pub trait Sdf<Scalar: Float, const DIM: usize> {
type State: SdfState<Scalar, DIM>;
// Required methods
fn distance(&self, position: [Scalar; DIM]) -> Scalar;
fn state(&self, position: [Scalar; DIM]) -> Self::State;
// Provided methods
fn state_sample(
&self,
position: [Scalar; DIM],
) -> <Self::State as SdfState<Scalar, DIM>>::Sample { ... }
fn distance_and_state(
&self,
position: [Scalar; DIM],
) -> (Scalar, Self::State) { ... }
fn distance_and_state_sample(
&self,
position: [Scalar; DIM],
) -> (Scalar, <Self::State as SdfState<Scalar, DIM>>::Sample) { ... }
fn gradient(
&self,
position: [Scalar; DIM],
epsilon: Scalar,
) -> [Scalar; DIM] { ... }
fn normal(&self, position: [Scalar; DIM], epsilon: Scalar) -> [Scalar; DIM] { ... }
}Expand description
Base trait for objects that represent a signed distance function.
To have an idea as to how you can use, and even create your own SDF, look at the implementation of some of the SDFs defined in this crate (and the Architecture/Usage sections of the doc too)
Required Associated Types§
Required Methods§
Sourcefn distance(&self, position: [Scalar; DIM]) -> Scalar
fn distance(&self, position: [Scalar; DIM]) -> Scalar
Evaluates the SDF at some point
Sourcefn state(&self, position: [Scalar; DIM]) -> Self::State
fn state(&self, position: [Scalar; DIM]) -> Self::State
Evaluates the state of the SDF at some point. See SdfState for more information.
Provided Methods§
Sourcefn state_sample(
&self,
position: [Scalar; DIM],
) -> <Self::State as SdfState<Scalar, DIM>>::Sample
fn state_sample( &self, position: [Scalar; DIM], ) -> <Self::State as SdfState<Scalar, DIM>>::Sample
Evaluates, then samples the state of the SDF at some point. See SdfState
for more information.
Sourcefn distance_and_state(&self, position: [Scalar; DIM]) -> (Scalar, Self::State)
fn distance_and_state(&self, position: [Scalar; DIM]) -> (Scalar, Self::State)
Evaluates both the distance and the state of the SDF, hopefully a little bit
faster than if you called both Sdf::distance and Sdf::state separately.
Sourcefn distance_and_state_sample(
&self,
position: [Scalar; DIM],
) -> (Scalar, <Self::State as SdfState<Scalar, DIM>>::Sample)
fn distance_and_state_sample( &self, position: [Scalar; DIM], ) -> (Scalar, <Self::State as SdfState<Scalar, DIM>>::Sample)
Evaluates both the distance and the sample of the state of the SDF, hopefully a little
bit faster than if you called both Sdf::distance and Sdf::state_sample separately.
Sourcefn gradient(&self, position: [Scalar; DIM], epsilon: Scalar) -> [Scalar; DIM]
fn gradient(&self, position: [Scalar; DIM], epsilon: Scalar) -> [Scalar; DIM]
Calculates the gradient of the SDF at some point in space. Some SDF have analytical expressions of the gradient, some don’t. If a SDF doesn’t have an implementation, it will instead approximate it using epsilon.
§Note
if a SDF approximates the gradient, all it’s children (if it’s a transformer or a combinator) will see their SDF be computed approximately EVEN if they themselves have some analytical expression of the gradient.
Sourcefn normal(&self, position: [Scalar; DIM], epsilon: Scalar) -> [Scalar; DIM]
fn normal(&self, position: [Scalar; DIM], epsilon: Scalar) -> [Scalar; DIM]
Calculates the gradient, then normalizes it. The gradient typically is already normalized if the SDF is well formed and if we aren’t on some edge case, but we never know.