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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//! Chebyshev distance metric.

use rust_gpu_bridge::prelude::{Vec2, Vec3};

use crate::signed_distance_field::{Distance, SignedDistanceField};

/// Chebyshev distance metric.
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct ChebyshevMetric;

impl SignedDistanceField<f32, Distance> for ChebyshevMetric {
    fn evaluate(&self, p: f32) -> Distance {
        p.abs().into()
    }
}

impl SignedDistanceField<Vec2, Distance> for ChebyshevMetric {
    fn evaluate(&self, p: Vec2) -> Distance {
        p.x.abs().max(p.y.abs()).into()
    }
}

impl SignedDistanceField<Vec3, Distance> for ChebyshevMetric {
    fn evaluate(&self, p: Vec3) -> Distance {
        p.x.abs().max(p.y.abs()).max(p.z.abs()).into()
    }
}

#[cfg(test)]
pub mod test {
    use rust_gpu_bridge::prelude::{Vec2, Vec3};

    use crate::{
        prelude::BoundChecker, signed_distance_field::metrics::chebyshev::ChebyshevMetric,
    };

    #[test]
    #[should_panic]
    pub fn test_chebyshev_metric_2d() {
        assert!(BoundChecker::<Vec2, ChebyshevMetric>::default().is_field());
    }

    #[test]
    #[should_panic]
    pub fn test_chebyshev_metric_3d() {
        assert!(BoundChecker::<Vec3, ChebyshevMetric>::default().is_field());
    }
}