summaryrefslogtreecommitdiffstats
path: root/core/src/point.rs
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/point.rs')
-rw-r--r--core/src/point.rs10
1 files changed, 10 insertions, 0 deletions
diff --git a/core/src/point.rs b/core/src/point.rs
index b55f5099..b855cd91 100644
--- a/core/src/point.rs
+++ b/core/src/point.rs
@@ -22,6 +22,16 @@ impl Point {
pub const fn new(x: f32, y: f32) -> Self {
Self { x, y }
}
+
+ /// Computes the distance to another [`Point`].
+ ///
+ /// [`Point`]: struct.Point.html
+ pub fn distance(&self, to: Point) -> f32 {
+ let a = self.x - to.x;
+ let b = self.y - to.y;
+
+ f32::sqrt(a * a + b * b)
+ }
}
impl From<[f32; 2]> for Point {