Skip to main content

oxiphysics_geometry/implicit_geometry/
sdfroundedcylinder_traits.rs

1//! # SdfRoundedCylinder - Trait Implementations
2//!
3//! This module contains trait implementations for `SdfRoundedCylinder`.
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::SdfRoundedCylinder;
13
14impl Sdf for SdfRoundedCylinder {
15    fn dist(&self, p: [f64; 3]) -> f64 {
16        let r = self.radius - self.rounding;
17        let h = self.half_height - self.rounding;
18        let d0 = len2([p[0], p[2]]) - r;
19        let d1 = p[1].abs() - h;
20        let d_in = d0.max(d1).min(0.0);
21        let d_out = len2([d0.max(0.0), d1.max(0.0)]);
22        d_in + d_out - self.rounding
23    }
24}