Implement std::ops::Add<Vector> for Rectangle

This commit is contained in:
Héctor Ramón Jiménez 2020-04-28 04:40:23 +02:00
parent 5d5e60a5cc
commit 69c60d372c

View file

@ -1,4 +1,4 @@
use crate::{Point, Size};
use crate::{Point, Size, Vector};
/// A rectangle.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
@ -140,3 +140,18 @@ impl From<Rectangle<f32>> for Rectangle<u32> {
}
}
}
impl<T> std::ops::Add<Vector<T>> for Rectangle<T>
where
T: std::ops::Add<Output = T>,
{
type Output = Rectangle<T>;
fn add(self, translation: Vector<T>) -> Self {
Rectangle {
x: self.x + translation.x,
y: self.y + translation.y,
..self
}
}
}