pub struct Cube;Expand description
A N dimension cube of side length 1.
If we need a rectangle, see Cuboid.
This primitive is centered at the origin, and has side lengths of 1.
It implements Sdf<Scalar, DIM, State = ()>.
§Example
use lightwalk::prelude::*;
let sdf = Cube;
// This is required to hint the dimension and scalar type of the SDF. In practice,
// the compiler probably already has enough information to go off of.
let distance = sdf.distance([1.0, 2.0]);Trait Implementations§
Source§impl<Scalar: Float, const DIM: usize> Sdf<Scalar, DIM> for Cube
impl<Scalar: Float, const DIM: usize> Sdf<Scalar, DIM> for Cube
Source§fn distance(&self, position: [Scalar; DIM]) -> Scalar
fn distance(&self, position: [Scalar; DIM]) -> Scalar
Evaluates the SDF at some point
Source§fn state(&self, _: [Scalar; DIM])
fn state(&self, _: [Scalar; DIM])
Evaluates the state of the SDF at some point. See
SdfState for more information.Source§fn 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.Source§fn 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.Source§fn 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.Source§fn 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. Read more
Source§fn 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. Smooth
combinations and the empty SDF are good counter examples.
Source§fn normal_or_zero(
&self,
position: [Scalar; DIM],
epsilon: Scalar,
) -> [Scalar; DIM]
fn normal_or_zero( &self, position: [Scalar; DIM], epsilon: Scalar, ) -> [Scalar; DIM]
Calculates the gradient, then normalizes it. If the norm is 0, then [0; DIM] is returned.
The gradient typically is already normalized, but sometimes this isn’t the case, for example
with the empty SDF.
Source§fn gradient_approx(
&self,
position: [Scalar; DIM],
epsilon: Scalar,
) -> [Scalar; DIM]
fn gradient_approx( &self, position: [Scalar; DIM], epsilon: Scalar, ) -> [Scalar; DIM]
Calculates the gradient of the SDF at some point in space. It will approximate it using
epsilon.
Source§fn normal_approx(
&self,
position: [Scalar; DIM],
epsilon: Scalar,
) -> [Scalar; DIM]
fn normal_approx( &self, position: [Scalar; DIM], epsilon: Scalar, ) -> [Scalar; DIM]
Calculates the normal of the SDF at some point in space. It will approximate the
gradient using epsilon.
Source§fn normal_or_zero_approx(
&self,
position: [Scalar; DIM],
epsilon: Scalar,
) -> [Scalar; DIM]
fn normal_or_zero_approx( &self, position: [Scalar; DIM], epsilon: Scalar, ) -> [Scalar; DIM]
Calculates the normal of the SDF at some point in space, and if the norm is 0, it will
simply return [0; DIM]. It will approximate the gradient using epsilon.
impl Copy for Cube
impl Eq for Cube
impl StructuralPartialEq for Cube
Auto Trait Implementations§
impl Freeze for Cube
impl RefUnwindSafe for Cube
impl Send for Cube
impl Sync for Cube
impl Unpin for Cube
impl UnwindSafe for Cube
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more