Implement std::ops::Add<Vector> for Rectangle
This commit is contained in:
parent
5d5e60a5cc
commit
69c60d372c
1 changed files with 16 additions and 1 deletions
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue