shape_core/elements/points/point_2d/manhattan.rs
1use super::*;
2
3impl<T> ManhattanDistance<T, Point<T>> for Point<T>
4where
5 T: PartialOrd + Clone + Sub<Output = T> + Add<Output = T>,
6{
7 fn manhattan_distance(&self, rhs: &Point<T>) -> T {
8 // avoid call abs() method, make it suitable for usize
9 let dx = if self.x > rhs.x { self.x.clone() - rhs.x.clone() } else { rhs.x.clone() - self.x.clone() };
10 let dy = if self.y > rhs.y { self.y.clone() - rhs.y.clone() } else { rhs.y.clone() - self.y.clone() };
11 dx + dy
12 }
13}