Skip to main content

oxiphysics_geometry/csg/
sdfsphere_traits.rs

1//! # SdfSphere - Trait Implementations
2//!
3//! This module contains trait implementations for `SdfSphere`.
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::functions::{length, normalize, sub};
15use super::types::SdfSphere;
16
17impl ImplicitSurface for SdfSphere {
18    fn sdf(&self, p: [f64; 3]) -> f64 {
19        length(sub(p, self.center)) - self.radius
20    }
21    fn gradient(&self, p: [f64; 3]) -> [f64; 3] {
22        normalize(sub(p, self.center))
23    }
24}