baiser/
distance.rs

1use num_traits::Float;
2
3pub trait Distance<F: Float> {
4    fn distance(&self, other: &Self) -> F;
5}
6
7impl<F: Float> Distance<F> for f32 {
8    fn distance(&self, other: &Self) -> F {
9        F::from((self - other).abs()).unwrap_or(F::infinity())
10    }
11}
12
13impl<F: Float> Distance<F> for f64 {
14    fn distance(&self, other: &Self) -> F {
15        F::from((self - other).abs()).unwrap_or(F::infinity())
16    }
17}