Finish implementing Rectangle
This commit is contained in:
parent
08def2bb42
commit
f5db656a0f
|
@ -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)]
|
||||
|
|
Loading…
Reference in New Issue