1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
pub mod by_dist_sq {
    use derive_more::Constructor;

    #[derive(Constructor)]
    pub struct ComparedByDistSq<T> {
        pub val: T,
        pub dist_sq: f32,
    }
    impl<T> PartialEq for ComparedByDistSq<T> {
        fn eq(&self, other: &Self) -> bool {
            self.dist_sq == other.dist_sq
        }
    }
    impl<T> PartialOrd for ComparedByDistSq<T> {
        fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
            self.dist_sq.partial_cmp(&other.dist_sq)
        }
    }
    impl<T> Eq for ComparedByDistSq<T> {}
    impl<T> Ord for ComparedByDistSq<T> {
        fn cmp(&self, other: &Self) -> std::cmp::Ordering {
            self.partial_cmp(other).unwrap()
        }
    }
}