From f08cb4ad565799689d07bacc190fbe0436a63648 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 14 Mar 2020 08:10:50 +0100 Subject: Implement mouse-based pane resizing for `PaneGrid` --- core/src/point.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'core/src/point.rs') 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 { -- cgit From 18f016cba70bf59095ae65ce0e289d80a548ae58 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 20 Mar 2020 04:08:18 +0100 Subject: Use `f32::hypot` in `Point::distance` --- core/src/point.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core/src/point.rs') diff --git a/core/src/point.rs b/core/src/point.rs index b855cd91..43ee2143 100644 --- a/core/src/point.rs +++ b/core/src/point.rs @@ -30,7 +30,7 @@ impl Point { let a = self.x - to.x; let b = self.y - to.y; - f32::sqrt(a * a + b * b) + a.hypot(b) } } -- cgit