diff --git a/src/rect.rs b/src/rect.rs index 25c1a99..372b842 100644 --- a/src/rect.rs +++ b/src/rect.rs @@ -42,7 +42,7 @@ pub fn Rect(origin: Point2D, size: Size2D) -> Rect { } } -impl + Sub> Rect { +impl + Sub + Zero> Rect { #[inline] pub fn intersects(&self, other: &Rect) -> bool { self.origin.x < other.origin.x + other.size.width && @@ -89,6 +89,13 @@ impl + Sub> 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(min(self.min_x(), other.min_x()), min(self.min_y(), other.min_y())); diff --git a/src/size.rs b/src/size.rs index 591c66d..f61f4ac 100644 --- a/src/size.rs +++ b/src/size.rs @@ -52,6 +52,15 @@ impl Size2D { } } +impl Zero for Size2D { + fn zero() -> Size2D { + Size2D { + width: Zero::zero(), + height: Zero::zero(), + } + } +} + impl, T1: Clone> Mul for Size2D { type Output = Size2D; #[inline]