utils: Add Rectangle::contains_rect
This commit is contained in:
parent
3c7bbf65c4
commit
37adc1174c
|
@ -58,6 +58,7 @@
|
||||||
#### Utils
|
#### Utils
|
||||||
|
|
||||||
- `Rectangle` can now also be converted from f64 to i32 variants
|
- `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
|
### Bugfixes
|
||||||
|
|
||||||
|
|
|
@ -782,6 +782,13 @@ impl<N: Coordinate, Kind> Rectangle<N, Kind> {
|
||||||
&& (p.y < self.loc.y + self.size.h)
|
&& (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
|
/// Checks whether a given [`Rectangle`] overlaps with this one
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn overlaps(self, other: Rectangle<N, Kind>) -> bool {
|
pub fn overlaps(self, other: Rectangle<N, Kind>) -> bool {
|
||||||
|
|
Loading…
Reference in New Issue