diff options
author | 2020-04-28 04:40:23 +0200 | |
---|---|---|
committer | 2020-04-28 04:40:23 +0200 | |
commit | 69c60d372c18c20856f733efd337ac302b7de926 (patch) | |
tree | c23c23891feaaa8a329c8afddaa10dd3afb7bb8e /core | |
parent | 5d5e60a5cc647b3227f78e1f3a3b31b2c27a3cc7 (diff) | |
download | iced-69c60d372c18c20856f733efd337ac302b7de926.tar.gz iced-69c60d372c18c20856f733efd337ac302b7de926.tar.bz2 iced-69c60d372c18c20856f733efd337ac302b7de926.zip |
Implement `std::ops::Add<Vector>` for `Rectangle`
Diffstat (limited to 'core')
-rw-r--r-- | core/src/rectangle.rs | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/core/src/rectangle.rs b/core/src/rectangle.rs index b9d0d5d2..87046df4 100644 --- a/core/src/rectangle.rs +++ b/core/src/rectangle.rs @@ -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 + } + } +} |