Skip to main content

oxiphysics_geometry/implicit_geometry/
sdfcone_traits.rs

1//! # SdfCone - Trait Implementations
2//!
3//! This module contains trait implementations for `SdfCone`.
4//!
5//! ## Implemented Traits
6//!
7//! - `Sdf`
8//!
9//! 🤖 Generated with [SplitRS](https://github.com/cool-japan/splitrs)
10
11#[allow(unused_imports)]
12use super::functions::*;
13#[allow(unused_imports)]
14use super::functions::*;
15use super::types::SdfCone;
16
17impl Sdf for SdfCone {
18    fn dist(&self, p: [f64; 3]) -> f64 {
19        let c = [self.half_angle.cos(), self.half_angle.sin()];
20        let q = [len2([p[0], p[2]]), p[1]];
21        let d = len2([
22            q[0] - c[0] * clamp_f(dot2(q, c), 0.0, self.height),
23            q[1] - c[1] * clamp_f(dot2(q, c), 0.0, self.height),
24        ]);
25        let s = if q[0] * c[1] - q[1] * c[0] > 0.0 {
26            1.0
27        } else {
28            -1.0
29        };
30        let base_d = len2([
31            q[0] - clamp_f(q[0], 0.0, self.height * c[1] / c[0]),
32            q[1] - self.height,
33        ]);
34        let cone_d = s * d;
35        cone_d.min(base_d)
36    }
37}