diff options
Diffstat (limited to 'core/src/point.rs')
-rw-r--r-- | core/src/point.rs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/core/src/point.rs b/core/src/point.rs index b9a8149c..43ee2143 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; + + a.hypot(b) + } } impl From<[f32; 2]> for Point { @@ -46,3 +56,14 @@ impl std::ops::Add<Vector> for Point { } } } + +impl std::ops::Sub<Vector> for Point { + type Output = Self; + + fn sub(self, vector: Vector) -> Self { + Self { + x: self.x - vector.x, + y: self.y - vector.y, + } + } +} |