From e7a22b7e300a0e9bf8142201b93270ac5e2e90ec Mon Sep 17 00:00:00 2001 From: Martin Robinson Date: Tue, 27 Oct 2015 16:20:38 -0700 Subject: [PATCH] Don't require the Zero trait for most Rect methods Only require it for Rect::union. This makes it easier to call these methods in Servo. --- src/rect.rs | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/src/rect.rs b/src/rect.rs index 1d3d5d2..8b9a15f 100644 --- a/src/rect.rs +++ b/src/rect.rs @@ -45,7 +45,7 @@ impl Rect { } } -impl + Sub + Zero> Rect { +impl + Sub> Rect { #[inline] pub fn intersects(&self, other: &Rect) -> bool { self.origin.x < other.origin.x + other.size.width && @@ -89,27 +89,6 @@ impl + Sub + Zero> lower_right.y - upper_left.y))) } - #[inline] - pub fn union(&self, other: &Rect) -> Rect { - if self.size == Zero::zero() { - return *other - } - if other.size == Zero::zero() { - return *self - } - - let upper_left = Point2D::new(min(self.min_x(), other.min_x()), - min(self.min_y(), other.min_y())); - - let lower_right = Point2D::new(max(self.max_x(), other.max_x()), - max(self.max_y(), other.max_y())); - - Rect { - origin: upper_left.clone(), - size: Size2D::new(lower_right.x - upper_left.x, lower_right.y - upper_left.y) - } - } - #[inline] pub fn translate(&self, other: &Point2D) -> Rect { Rect { @@ -154,6 +133,29 @@ impl + Sub + Zero> } } +impl + Sub + Zero> Rect { + #[inline] + pub fn union(&self, other: &Rect) -> Rect { + if self.size == Zero::zero() { + return *other + } + if other.size == Zero::zero() { + return *self + } + + let upper_left = Point2D::new(min(self.min_x(), other.min_x()), + min(self.min_y(), other.min_y())); + + let lower_right = Point2D::new(max(self.max_x(), other.max_x()), + max(self.max_y(), other.max_y())); + + Rect { + origin: upper_left.clone(), + size: Size2D::new(lower_right.x - upper_left.x, lower_right.y - upper_left.y) + } + } +} + impl Rect { #[inline] pub fn scale(&self, x: Scale, y: Scale) -> Rect