1
2
3
4
5
6
7
8
9
10
11
12
13
use super::*;

impl<T> ManhattanDistance<T, Point<T>> for Point<T>
where
    T: PartialOrd + Clone + Sub<Output = T> + Add<Output = T>,
{
    fn manhattan_distance(&self, rhs: &Point<T>) -> T {
        // avoid call abs() method, make it suitable for usize
        let dx = if self.x > rhs.x { self.x.clone() - rhs.x.clone() } else { rhs.x.clone() - self.x.clone() };
        let dy = if self.y > rhs.y { self.y.clone() - rhs.y.clone() } else { rhs.y.clone() - self.y.clone() };
        dx + dy
    }
}