SpatialRng

Trait SpatialRng 

Source
pub trait SpatialRng:
    Sized
    + Send
    + Sync {
    // Required methods
    fn new(seed: u32) -> Self;
    fn compute(&self, x: u32, y: u32) -> f32;

    // Provided methods
    fn dither_2d<T>(
        &self,
        value: T,
        min: T,
        one: T,
        dither_amplitude: T,
        x: u32,
        y: u32,
    ) -> T
       where T: DitherFloat,
             Self: Sized { ... }
    fn simple_dither_2d<T>(&self, value: T, one: T, x: u32, y: u32) -> T
       where T: DitherFloat + Number + CastableFrom<f32>,
             Self: Sized { ... }
    fn dither_slice_2d<T>(
        &self,
        values: &mut [T],
        width: usize,
        min: T,
        one: T,
        dither_amplitude: T,
    )
       where T: DitherFloat + Send + Sync,
             Self: Sized { ... }
    fn simple_dither_slice_2d<T>(&self, values: &mut [T], width: usize, one: T)
       where T: DitherFloat + Number + CastableFrom<f32> + Send + Sync,
             Self: Sized { ... }
    fn dither_float_2d<Src, Dest>(&self, value: Src, x: u32, y: u32) -> Dest
       where Src: DitherFloatConversion<Dest> + DitherFloat + CastableFrom<f64>,
             Self: Sized { ... }
    fn dither_float_slice_2d<Src, Dest>(
        &self,
        values: &[Src],
        width: usize,
    ) -> Vec<Dest>
       where Src: DitherFloatConversion<Dest> + DitherFloat + CastableFrom<f64> + Copy + Send + Sync,
             Dest: Send,
             Self: Sized { ... }
}
Expand description

Trait for spatial random number generators.

These generators produce deterministic random values based on 2D coordinates, making them ideal for parallel processing and applications like dithering.

§When to Use SpatialRng

Use SpatialRng implementations when:

  • Processing 2D data (images, textures).
  • You need spatially-aware noise patterns.
  • Parallel processing is important (each pixel independent).
  • Visual quality matters more than speed.

§Available Implementations

  • InterleavedGradientNoise – Fast IGN algorithm from Jorge Jimenez. Real-time graphics quality.
  • SpatialHash – Spatial hash function. Blue noise-like properties with good performance.
  • BlueNoiseApprox – Combines IGN and SpatialHash. Approximates blue noise characteristics.
  • [BlueNoise] (requires blue_noise feature) – True blue noise from precomputed tables. Highest quality.

Required Methods§

Source

fn new(seed: u32) -> Self

Create a new spatial RNG with the given seed.

Source

fn compute(&self, x: u32, y: u32) -> f32

Compute a deterministic value for given 2D coordinates. Returns a value in range [-1, 1].

Provided Methods§

Source

fn dither_2d<T>( &self, value: T, min: T, one: T, dither_amplitude: T, x: u32, y: u32, ) -> T
where T: DitherFloat, Self: Sized,

Dither a single value using 2D coordinates.

Source

fn simple_dither_2d<T>(&self, value: T, one: T, x: u32, y: u32) -> T
where T: DitherFloat + Number + CastableFrom<f32>, Self: Sized,

Simple dither for a single value using 2D coordinates.

Source

fn dither_slice_2d<T>( &self, values: &mut [T], width: usize, min: T, one: T, dither_amplitude: T, )
where T: DitherFloat + Send + Sync, Self: Sized,

Dither a 2D image stored as a flat slice (parallel version).

Source

fn simple_dither_slice_2d<T>(&self, values: &mut [T], width: usize, one: T)
where T: DitherFloat + Number + CastableFrom<f32> + Send + Sync, Self: Sized,

Simple dither for a 2D image stored as a flat slice (parallel version).

Source

fn dither_float_2d<Src, Dest>(&self, value: Src, x: u32, y: u32) -> Dest

Dither a float value when converting to lower precision using 2D coordinates.

Source

fn dither_float_slice_2d<Src, Dest>( &self, values: &[Src], width: usize, ) -> Vec<Dest>
where Src: DitherFloatConversion<Dest> + DitherFloat + CastableFrom<f64> + Copy + Send + Sync, Dest: Send, Self: Sized,

Dither float values in a 2D image slice when converting to lower precision (parallel version).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§