Struct libnoise::NoiseBuffer

source ·
pub struct NoiseBuffer<const D: usize> {
    pub shape: [usize; D],
    pub offsets: [usize; D],
    pub buffer: Vec<f64>,
}
Expand description

A struct for generating an n-dimensional array and efficiently filling it with noise values.

This struct represents a simple n-dimensional array which is stored as a flat vector. When creating a new NoiseBuffer using the new() method, only the length along each dimension and a noise generator, that is, an object implementing Generator, must be provided. The n-dimensional array is then filled with noise values. The implementation ensures, that the noise is computed in a way such that the underlying flat vector is written sequentially for maximal cache performance.

As NoiseBuffer implements the Index and IndexMut traits, it is possible to index the n-dimensional array with an index array of the appropriate length.

§Creating a noise buffer

A noise buffer can be easily and efficiently created using the new() method. The resulting buffer will be filled with noise values according to the provided noise generator.

When filling the buffer, the specific value at a given buffer index is computed by sampling the generator with the index interpreted as coordinates in n-dimensional space. This means that the buffer samples the generator on points of a hypergrid:

// create a generator
let generator = Source::simplex(42);

// create a new noise buffer filled with noise values for each point
let buf = NoiseBuffer::<3>::new([30, 20, 25], &generator);

assert_eq!(buf[[17, 9, 21]], generator.sample([17.0, 9.0, 21.0]));

The scale or position of the grid can be modified by calling adapters such as scale(), translate(), or rotate() on the generator before using it to create a NoiseBuffer.

Fields§

§shape: [usize; D]

Stores the length of the n-dimensional array along each dimension.

§offsets: [usize; D]

Stores offsets which are used to convert n-dimensional coordinates to flat vector indices.

§buffer: Vec<f64>

The underlying flat vector storing the noise values.

Implementations§

source§

impl NoiseBuffer<1>

source

pub fn new<G: Generator<1>>(shape: [usize; 1], generator: &G) -> Self

Creates a new noise buffer with the given shape and filled with noise generated by the given generator. For further detail see the Creating a noise buffer section.

source§

impl NoiseBuffer<2>

source

pub fn new<G: Generator<2>>(shape: [usize; 2], generator: &G) -> Self

Creates a new noise buffer with the given shape and filled with noise generated by the given generator. For further detail see the Creating a noise buffer section.

source§

impl NoiseBuffer<3>

source

pub fn new<G: Generator<3>>(shape: [usize; 3], generator: &G) -> Self

Creates a new noise buffer with the given shape and filled with noise generated by the given generator. For further detail see the Creating a noise buffer section.

source§

impl NoiseBuffer<4>

source

pub fn new<G: Generator<4>>(shape: [usize; 4], generator: &G) -> Self

Creates a new noise buffer with the given shape and filled with noise generated by the given generator. For further detail see the Creating a noise buffer section.

Trait Implementations§

source§

impl<const D: usize> Clone for NoiseBuffer<D>

source§

fn clone(&self) -> NoiseBuffer<D>

Returns a copy 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<const D: usize> Debug for NoiseBuffer<D>

source§

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

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

impl<const D: usize> From<NoiseBuffer<D>> for Visualizer<D>

source§

fn from(noisebuf: NoiseBuffer<D>) -> Self

Converts to this type from the input type.
source§

impl Index<[usize; 1]> for NoiseBuffer<1>

§

type Output = f64

The returned type after indexing.
source§

fn index(&self, index: [usize; 1]) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
source§

impl Index<[usize; 2]> for NoiseBuffer<2>

§

type Output = f64

The returned type after indexing.
source§

fn index(&self, index: [usize; 2]) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
source§

impl Index<[usize; 3]> for NoiseBuffer<3>

§

type Output = f64

The returned type after indexing.
source§

fn index(&self, index: [usize; 3]) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
source§

impl Index<[usize; 4]> for NoiseBuffer<4>

§

type Output = f64

The returned type after indexing.
source§

fn index(&self, index: [usize; 4]) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
source§

impl IndexMut<[usize; 1]> for NoiseBuffer<1>

source§

fn index_mut(&mut self, index: [usize; 1]) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
source§

impl IndexMut<[usize; 2]> for NoiseBuffer<2>

source§

fn index_mut(&mut self, index: [usize; 2]) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
source§

impl IndexMut<[usize; 3]> for NoiseBuffer<3>

source§

fn index_mut(&mut self, index: [usize; 3]) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
source§

impl IndexMut<[usize; 4]> for NoiseBuffer<4>

source§

fn index_mut(&mut self, index: [usize; 4]) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more

Auto Trait Implementations§

§

impl<const D: usize> RefUnwindSafe for NoiseBuffer<D>

§

impl<const D: usize> Send for NoiseBuffer<D>

§

impl<const D: usize> Sync for NoiseBuffer<D>

§

impl<const D: usize> Unpin for NoiseBuffer<D>

§

impl<const D: usize> UnwindSafe for NoiseBuffer<D>

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

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

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

§

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>,

§

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>,

§

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V