Cube

Struct Cube 

Source
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 Clone for Cube

Source§

fn clone(&self) -> Cube

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Cube

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Cube

Source§

fn default() -> Cube

Returns the “default value” for a type. Read more
Source§

impl Hash for Cube

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Cube

Source§

fn eq(&self, other: &Cube) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

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

Source§

type State = ()

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

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

Evaluates the SDF at some point
Source§

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

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. Read more
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. Smooth combinations and the empty SDF are good counter examples.
Source§

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]

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]

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]

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

impl Copy for Cube

Source§

impl Eq for Cube

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, Scalar, const DIM: usize> SdfBindTrait<Scalar, DIM> for T
where Scalar: Float, T: Sdf<Scalar, DIM>,

Source§

fn bind<State: SdfState<Scalar, DIM>>( self, state: State, ) -> Bound<Self, Scalar, State, DIM>

Source§

impl<T, Scalar, State, const DIM: usize> SdfCombinationOperations<Scalar, State, DIM> for T
where Scalar: Float + 'static, State: SdfState<Scalar, DIM>, T: Sdf<Scalar, DIM, State = State>,

Source§

fn add<Rhs>(self, rhs: Rhs) -> Union<Self, Rhs, Scalar, State, DIM>
where Rhs: Sdf<Scalar, DIM, State = State>,

Source§

fn mul<Rhs>(self, rhs: Rhs) -> Intersection<Self, Rhs, Scalar, State, DIM>
where Rhs: Sdf<Scalar, DIM, State = State>,

Source§

fn sub<Rhs>(self, rhs: Rhs) -> Difference<Self, Rhs, Scalar, State, DIM>
where Rhs: Sdf<Scalar, DIM, State = State>,

Source§

fn add_smooth_sigmoid<Rhs>( self, rhs: Rhs, factor: Scalar, ) -> SUnionSigmoid<Self, Rhs, Scalar, State, DIM>
where Rhs: Sdf<Scalar, DIM, State = State>,

Source§

fn add_smooth_exp<Rhs>( self, rhs: Rhs, factor: Scalar, ) -> SUnionExponential<Self, Rhs, Scalar, State, DIM>
where Rhs: Sdf<Scalar, DIM, State = State>,

Source§

fn mul_smooth_exp<Rhs>( self, rhs: Rhs, factor: Scalar, ) -> SIntersectionExponential<Self, Rhs, Scalar, State, DIM>
where Rhs: Sdf<Scalar, DIM, State = State>,

Source§

fn sub_smooth_exp<Rhs>( self, rhs: Rhs, factor: Scalar, ) -> SDifferenceExponential<Self, Rhs, Scalar, State, DIM>
where Rhs: Sdf<Scalar, DIM, State = State>,

Source§

impl<State, S> SdfRotationOperations<State> for S
where State: SdfState<f32, 3>, S: Sdf<f32, 3, State = State>,

Source§

fn rotate(self, rotation: Quat) -> Rotated<State, Self>

Source§

impl<Scalar, State, const DIM: usize, S> SdfTransformOperations<Scalar, State, DIM> for S
where Scalar: Float + 'static, State: SdfState<Scalar, DIM>, S: Sdf<Scalar, DIM, State = State>,

Source§

fn translate( self, translation: impl Into<[Scalar; DIM]>, ) -> Translated<Scalar, State, Self, DIM>

Source§

fn scale(self, scale: Scalar) -> Scaled<Scalar, State, Self, DIM>

Source§

fn invert(self) -> Inverted<Scalar, State, Self, DIM>

Source§

fn iso(self, iso: Scalar) -> IsoSurface<Scalar, State, Self, DIM>

Source§

fn thicken(self, thickness: Scalar) -> Thicken<Scalar, State, Self, DIM>

Source§

fn approx(self, radius: Scalar) -> Approximated<Scalar, State, Self, DIM>

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.