diff options
author | 2023-04-05 04:10:00 +0200 | |
---|---|---|
committer | 2023-04-05 05:40:44 +0200 | |
commit | f8cd1faa286daaf34cc532bf6d34b932b32eb35a (patch) | |
tree | 9db23ee837803df6954abc65eb5291b6af521083 /core/src/rectangle.rs | |
parent | 6270c33ed9823c67f6b6e6dac8fd32521e4ac5a9 (diff) | |
download | iced-f8cd1faa286daaf34cc532bf6d34b932b32eb35a.tar.gz iced-f8cd1faa286daaf34cc532bf6d34b932b32eb35a.tar.bz2 iced-f8cd1faa286daaf34cc532bf6d34b932b32eb35a.zip |
Group damage regions by area increase
Diffstat (limited to 'core/src/rectangle.rs')
-rw-r--r-- | core/src/rectangle.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/core/src/rectangle.rs b/core/src/rectangle.rs index 5cdcbe78..7ff324cb 100644 --- a/core/src/rectangle.rs +++ b/core/src/rectangle.rs @@ -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, |