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;
12use super::types::CsgDifference;
13
14impl ImplicitSurface for CsgDifference {
15    fn sdf(&self, p: [f64; 3]) -> f64 {
16        self.a.sdf(p).max(-self.b.sdf(p))
17    }
18    fn gradient(&self, p: [f64; 3]) -> [f64; 3] {
19        if self.a.sdf(p) > -self.b.sdf(p) {
20            self.a.gradient(p)
21        } else {
22            let g = self.b.gradient(p);
23            [-g[0], -g[1], -g[2]]
24        }
25    }
26}