utils: Add Rectangle::contains_rect

This commit is contained in:
Victor Brekenfeld 2021-11-27 20:53:26 +01:00
parent 3c7bbf65c4
commit 37adc1174c
2 changed files with 8 additions and 0 deletions

View File

@ -58,6 +58,7 @@
#### Utils
- `Rectangle` can now also be converted from f64 to i32 variants
- `Rectangle::contains_rect` can be used to check if a rectangle is contained within another
### Bugfixes

View File

@ -782,6 +782,13 @@ impl<N: Coordinate, Kind> Rectangle<N, Kind> {
&& (p.y < self.loc.y + self.size.h)
}
/// Checks whether given [`Rectangle`] is inside the rectangle
#[inline]
pub fn contains_rect<R: Into<Rectangle<N, Kind>>>(self, rect: R) -> bool {
let r: Rectangle<N, Kind> = rect.into();
self.contains(r.loc) && self.contains(r.loc + r.size)
}
/// Checks whether a given [`Rectangle`] overlaps with this one
#[inline]
pub fn overlaps(self, other: Rectangle<N, Kind>) -> bool {