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>
impl NoiseBuffer<1>
source§impl NoiseBuffer<2>
impl NoiseBuffer<2>
source§impl NoiseBuffer<3>
impl NoiseBuffer<3>
source§impl NoiseBuffer<4>
impl NoiseBuffer<4>
Trait Implementations§
source§impl<const D: usize> Clone for NoiseBuffer<D>
impl<const D: usize> Clone for NoiseBuffer<D>
source§fn clone(&self) -> NoiseBuffer<D>
fn clone(&self) -> NoiseBuffer<D>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more