diff --git a/CHANGELOG.md b/CHANGELOG.md index 21982a9..3fab971 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/utils/geometry.rs b/src/utils/geometry.rs index 3bb5823..8f3e97f 100644 --- a/src/utils/geometry.rs +++ b/src/utils/geometry.rs @@ -782,6 +782,13 @@ impl Rectangle { && (p.y < self.loc.y + self.size.h) } + /// Checks whether given [`Rectangle`] is inside the rectangle + #[inline] + pub fn contains_rect>>(self, rect: R) -> bool { + let r: Rectangle = 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) -> bool {