diff --git a/src/geometry.rs b/src/geometry.rs index cde9154..e0d1033 100644 --- a/src/geometry.rs +++ b/src/geometry.rs @@ -129,6 +129,36 @@ impl Rectangle { height, } } + + fn top_left(&self) -> Point { + self.top_left + } + + fn top_right(&self) -> Point { + Point::new(self.top_left.x() + self.width, self.top_left.y()) + } + + fn bottom_right(&self) -> Point { + Point::new( + self.top_left.x() + self.width, + self.top_left.y() + self.height, + ) + } + + fn bottom_left(&self) -> Point { + Point::new(self.top_left.x(), self.top_left.y() + self.height) + } + + fn area(&self) -> u32 { + self.width * self.height + } + + fn intersects(&self, other: &Rectangle) -> bool { + !(self.top_left().right_of(&other.top_right()) + || self.top_left().below(&other.bottom_left()) + || self.top_right().left_of(&other.top_left()) + || self.bottom_left().above(&other.top_left())) + } } #[cfg(test)]