1use f32 as dp; pub use crate::cprelude::*;
3
4use auto_ops::*;
5pub struct Point {
6 pub x: dp,
7 pub y: dp
8}
9fn square_dp(n: dp) -> dp {
10 n.powf(2.0)
11}
12impl Point {
13 pub fn distance_to(&self, other: &Self) -> dp {
14 let delta_x = other.x-self.x;
15 let delta_y = other.y-self.y;
16
17 (square_dp(delta_x)+square_dp(delta_y))
18 .sqrt()
19 }
20}
21impl CloseEnough for Point {
22 fn is_close_enough_to(&self, other: &Self, tolerance: dp) -> bool {
23 self.distance_to(other) <= tolerance
24 }
25}
26impl_op_ex!(+ |a: &Point, b: &Point| -> Point {
27 Point {x: a.x+b.x, y: a.y+b.y}
28});
29impl_op_ex!(- |a: &Point, b: &Point| -> Point {
30 a + Point {x: -b.x, y: -b.y}
31});