From 69c60d372c18c20856f733efd337ac302b7de926 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 28 Apr 2020 04:40:23 +0200 Subject: Implement `std::ops::Add` for `Rectangle` --- core/src/rectangle.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'core/src') 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> for Rectangle { } } } + +impl std::ops::Add> for Rectangle +where + T: std::ops::Add, +{ + type Output = Rectangle; + + fn add(self, translation: Vector) -> Self { + Rectangle { + x: self.x + translation.x, + y: self.y + translation.y, + ..self + } + } +} -- cgit