summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/src/mouse/click.rs2
-rw-r--r--core/src/rectangle.rs14
2 files changed, 15 insertions, 1 deletions
diff --git a/core/src/mouse/click.rs b/core/src/mouse/click.rs
index 0a373878..dd1c84cd 100644
--- a/core/src/mouse/click.rs
+++ b/core/src/mouse/click.rs
@@ -13,7 +13,7 @@ pub struct Click {
}
/// The kind of mouse click.
-#[derive(Debug, Clone, Copy)]
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Kind {
/// A single click
Single,
diff --git a/core/src/rectangle.rs b/core/src/rectangle.rs
index cff33991..14d2a2e8 100644
--- a/core/src/rectangle.rs
+++ b/core/src/rectangle.rs
@@ -143,6 +143,20 @@ impl Rectangle<f32> {
&& point.y < self.y + self.height
}
+ /// Returns the minimum distance from the given [`Point`] to any of the edges
+ /// of the [`Rectangle`].
+ pub fn distance(&self, point: Point) -> f32 {
+ let center = self.center();
+
+ let distance_x =
+ ((point.x - center.x).abs() - self.width / 2.0).max(0.0);
+
+ let distance_y =
+ ((point.y - center.y).abs() - self.height / 2.0).max(0.0);
+
+ distance_x.hypot(distance_y)
+ }
+
/// Returns true if the current [`Rectangle`] is completely within the given
/// `container`.
pub fn is_within(&self, container: &Rectangle) -> bool {