Sdf

Trait Sdf 

Source
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§

Source

type State: SdfState<Scalar, DIM>

The state that is bound to this SDF. See SdfState for more information.

Required Methods§

Source

fn distance(&self, position: [Scalar; DIM]) -> Scalar

Evaluates the SDF at some point

Source

fn state(&self, position: [Scalar; DIM]) -> Self::State

Evaluates the state of the SDF at some point. See SdfState for more information.

Provided Methods§

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Implementors§

Source§

impl<I, Scalar: Float, State: SdfState<Scalar, DIM>, const DIM: usize> Sdf<Scalar, DIM> for IntersectionIterator<I, Scalar, State, DIM>
where I: Iterator + Clone, <I as Iterator>::Item: Sdf<Scalar, DIM, State = State>,

Source§

type State = State

Source§

impl<I, Scalar: Float, State: SdfState<Scalar, DIM>, const DIM: usize> Sdf<Scalar, DIM> for UnionIterator<I, Scalar, State, DIM>
where I: Iterator + Clone, <I as Iterator>::Item: Sdf<Scalar, DIM, State = State>,

Source§

type State = State

Source§

impl<Lhs, Rhs, Scalar: Display + Float, State: SdfState<Scalar, DIM>, const DIM: usize> Sdf<Scalar, DIM> for SUnionExponential<Lhs, Rhs, Scalar, State, DIM>
where Lhs: Sdf<Scalar, DIM, State = State>, Rhs: Sdf<Scalar, DIM, State = State>,

Source§

type State = State

Source§

impl<Lhs, Rhs, Scalar: Float, State: SdfState<Scalar, DIM>, const DIM: usize> Sdf<Scalar, DIM> for Difference<Lhs, Rhs, Scalar, State, DIM>
where Lhs: Sdf<Scalar, DIM, State = State>, Rhs: Sdf<Scalar, DIM, State = State>,

Source§

type State = State

Source§

impl<Lhs, Rhs, Scalar: Float, State: SdfState<Scalar, DIM>, const DIM: usize> Sdf<Scalar, DIM> for Intersection<Lhs, Rhs, Scalar, State, DIM>
where Lhs: Sdf<Scalar, DIM, State = State>, Rhs: Sdf<Scalar, DIM, State = State>,

Source§

type State = State

Source§

impl<Lhs, Rhs, Scalar: Float, State: SdfState<Scalar, DIM>, const DIM: usize> Sdf<Scalar, DIM> for SDifferenceExponential<Lhs, Rhs, Scalar, State, DIM>
where Lhs: Sdf<Scalar, DIM, State = State>, Rhs: Sdf<Scalar, DIM, State = State>,

Source§

type State = State

Source§

impl<Lhs, Rhs, Scalar: Float, State: SdfState<Scalar, DIM>, const DIM: usize> Sdf<Scalar, DIM> for SIntersectionExponential<Lhs, Rhs, Scalar, State, DIM>
where Lhs: Sdf<Scalar, DIM, State = State>, Rhs: Sdf<Scalar, DIM, State = State>,

Source§

type State = State

Source§

impl<Lhs, Rhs, Scalar: Float, State: SdfState<Scalar, DIM>, const DIM: usize> Sdf<Scalar, DIM> for Union<Lhs, Rhs, Scalar, State, DIM>
where Lhs: Sdf<Scalar, DIM, State = State>, Rhs: Sdf<Scalar, DIM, State = State>,

Source§

type State = State

Source§

impl<Scalar: Float + 'static> Sdf<Scalar, 3> for Cylinder<Scalar>

Source§

impl<Scalar: Float> Sdf<Scalar, 3> for Torus<Scalar>

Source§

impl<Scalar: Float, State: SdfState<Scalar, DIM>, Inner, const DIM: usize> Sdf<Scalar, DIM> for Approximated<Scalar, State, Inner, DIM>
where Inner: Sdf<Scalar, DIM, State = State>,

Source§

type State = State

Source§

impl<Scalar: Float, State: SdfState<Scalar, DIM>, Inner, const DIM: usize> Sdf<Scalar, DIM> for Inverted<Scalar, State, Inner, DIM>
where Inner: Sdf<Scalar, DIM, State = State>,

Source§

type State = State

Source§

impl<Scalar: Float, State: SdfState<Scalar, DIM>, Inner, const DIM: usize> Sdf<Scalar, DIM> for IsoSurface<Scalar, State, Inner, DIM>
where Inner: Sdf<Scalar, DIM, State = State>,

Source§

type State = State

Source§

impl<Scalar: Float, State: SdfState<Scalar, DIM>, Inner, const DIM: usize> Sdf<Scalar, DIM> for Scaled<Scalar, State, Inner, DIM>
where Inner: Sdf<Scalar, DIM, State = State>,

Source§

type State = State

Source§

impl<Scalar: Float, State: SdfState<Scalar, DIM>, Inner, const DIM: usize> Sdf<Scalar, DIM> for Thicken<Scalar, State, Inner, DIM>
where Inner: Sdf<Scalar, DIM, State = State>,

Source§

type State = State

Source§

impl<Scalar: Float, State: SdfState<Scalar, DIM>, Inner, const DIM: usize> Sdf<Scalar, DIM> for Translated<Scalar, State, Inner, DIM>
where Inner: Sdf<Scalar, DIM, State = State>,

Source§

type State = State

Source§

impl<Scalar: Float, const DIM: usize> Sdf<Scalar, DIM> for Cube

Source§

impl<Scalar: Float, const DIM: usize> Sdf<Scalar, DIM> for Cuboid<Scalar, DIM>

Source§

impl<Scalar: Float, const DIM: usize> Sdf<Scalar, DIM> for Empty

Source§

impl<Scalar: Float, const DIM: usize> Sdf<Scalar, DIM> for Plane

Source§

impl<Scalar: Float, const DIM: usize> Sdf<Scalar, DIM> for Sphere

Source§

impl<State: SdfState<f32, 3>, Inner> Sdf<f32, 3> for Rotated<State, Inner>
where Inner: Sdf<f32, 3, State = State>,

Source§

type State = State

Source§

impl<T, Scalar: Float, State: SdfState<Scalar, DIM>, const DIM: usize> Sdf<Scalar, DIM> for IntersectionContainer<T, Scalar, State, DIM>
where for<'a> &'a T: IntoIterator, for<'a> <&'a T as IntoIterator>::Item: Sdf<Scalar, DIM, State = State>,

Source§

type State = State

Source§

impl<T, Scalar: Float, State: SdfState<Scalar, DIM>, const DIM: usize> Sdf<Scalar, DIM> for UnionContainer<T, Scalar, State, DIM>
where for<'a> &'a T: IntoIterator, for<'a> <&'a T as IntoIterator>::Item: Sdf<Scalar, DIM, State = State>,

Source§

type State = State

Source§

impl<T, Scalar: Float, State: SdfState<Scalar, DIM>, const DIM: usize> Sdf<Scalar, DIM> for T
where T: Deref, T::Target: Sdf<Scalar, DIM, State = State>,

Source§

type State = State