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
11use super::functions::*;
12use super::types::SdfCone;
13
14impl Sdf for SdfCone {
15    fn dist(&self, p: [f64; 3]) -> f64 {
16        let c = [self.half_angle.cos(), self.half_angle.sin()];
17        let q = [len2([p[0], p[2]]), p[1]];
18        let d = len2([
19            q[0] - c[0] * clamp_f(dot2(q, c), 0.0, self.height),
20            q[1] - c[1] * clamp_f(dot2(q, c), 0.0, self.height),
21        ]);
22        let s = if q[0] * c[1] - q[1] * c[0] > 0.0 {
23            1.0
24        } else {
25            -1.0
26        };
27        let base_d = len2([
28            q[0] - clamp_f(q[0], 0.0, self.height * c[1] / c[0]),
29            q[1] - self.height,
30        ]);
31        let cone_d = s * d;
32        cone_d.min(base_d)
33    }
34}