summaryrefslogtreecommitdiffstats
path: root/core/src/rectangle.rs
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/rectangle.rs')
-rw-r--r--core/src/rectangle.rs14
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,