Skip to main content

oxiphysics_geometry/csg/
csgdifference_traits.rs

1//! # CsgDifference - Trait Implementations
2//!
3//! This module contains trait implementations for `CsgDifference`.
4//!
5//! ## Implemented Traits
6//!
7//! - `ImplicitSurface`
8//!
9//! 🤖 Generated with [SplitRS](https://github.com/cool-japan/splitrs)
10
11use super::functions::ImplicitSurface;
12#[allow(unused_imports)]
13use super::functions::*;
14use super::types::CsgDifference;
15
16impl ImplicitSurface for CsgDifference {
17    fn sdf(&self, p: [f64; 3]) -> f64 {
18        self.a.sdf(p).max(-self.b.sdf(p))
19    }
20    fn gradient(&self, p: [f64; 3]) -> [f64; 3] {
21        if self.a.sdf(p) > -self.b.sdf(p) {
22            self.a.gradient(p)
23        } else {
24            let g = self.b.gradient(p);
25            [-g[0], -g[1], -g[2]]
26        }
27    }
28}