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
use rust_gpu_bridge::prelude::Vec2;
use type_fields::Field;

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

#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Field)]
pub struct Superellipse {
    pub n: f32,
}

impl Default for Superellipse {
    fn default() -> Self {
        Superellipse { n: 1.0 }
    }
}

impl SignedDistanceField<Vec2, Distance> for Superellipse {
    fn evaluate(&self, p: Vec2) -> Distance {
        let d = p.x.abs().powf(self.n) + p.y.abs().powf(self.n);
        let d = d - 1.0;
        Distance(d)
    }
}

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

    use crate::prelude::BoundChecker;

    use super::Superellipse;

    #[test]
    #[should_panic]
    fn test_lame_curve() {
        assert!(BoundChecker::<Vec2, Superellipse>::default().is_field())
    }
}