Group damage regions by area increase

This commit is contained in:
Héctor Ramón Jiménez 2023-04-05 04:10:00 +02:00
parent 6270c33ed9
commit f8cd1faa28
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
4 changed files with 199 additions and 108 deletions

View file

@ -66,6 +66,11 @@ impl Rectangle<f32> {
Size::new(self.width, self.height)
}
/// Returns the area of the [`Rectangle`].
pub fn area(&self) -> f32 {
self.width * self.height
}
/// Returns true if the given [`Point`] is contained in the [`Rectangle`].
pub fn contains(&self, point: Point) -> bool {
self.x <= point.x
@ -74,6 +79,15 @@ impl Rectangle<f32> {
&& point.y <= self.y + self.height
}
/// Returns true if the current [`Rectangle`] is completely within the given
/// `container`.
pub fn is_within(&self, container: &Rectangle) -> bool {
container.contains(self.position())
&& container.contains(
self.position() + Vector::new(self.width, self.height),
)
}
/// Computes the intersection with the given [`Rectangle`].
pub fn intersection(
&self,