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;
12use super::functions::{length, normalize, sub};
13use super::types::SdfSphere;
14
15impl ImplicitSurface for SdfSphere {
16 fn sdf(&self, p: [f64; 3]) -> f64 {
17 length(sub(p, self.center)) - self.radius
18 }
19 fn gradient(&self, p: [f64; 3]) -> [f64; 3] {
20 normalize(sub(p, self.center))
21 }
22}