From 37adc1174c81ac69fa4b8a745b4d6182f60932eb Mon Sep 17 00:00:00 2001 From: Victor Brekenfeld Date: Sat, 27 Nov 2021 20:53:26 +0100 Subject: [PATCH] utils: Add Rectangle::contains_rect --- CHANGELOG.md | 1 + src/utils/geometry.rs | 7 +++++++ 2 files changed, 8 insertions(+) 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 {