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 andSpatialHash. Approximates blue noise characteristics.- [
BlueNoise] (requiresblue_noisefeature) – True blue noise from precomputed tables. Highest quality.
Required Methods§
Provided Methods§
Sourcefn dither_2d<T>(
&self,
value: T,
min: T,
one: T,
dither_amplitude: T,
x: u32,
y: u32,
) -> Twhere
T: DitherFloat,
Self: Sized,
fn dither_2d<T>(
&self,
value: T,
min: T,
one: T,
dither_amplitude: T,
x: u32,
y: u32,
) -> Twhere
T: DitherFloat,
Self: Sized,
Dither a single value using 2D coordinates.
Sourcefn simple_dither_2d<T>(&self, value: T, one: T, x: u32, y: u32) -> T
fn simple_dither_2d<T>(&self, value: T, one: T, x: u32, y: u32) -> T
Simple dither for a single value using 2D coordinates.
Sourcefn dither_slice_2d<T>(
&self,
values: &mut [T],
width: usize,
min: T,
one: T,
dither_amplitude: T,
)
fn dither_slice_2d<T>( &self, values: &mut [T], width: usize, min: T, one: T, dither_amplitude: T, )
Dither a 2D image stored as a flat slice (parallel version).
Sourcefn simple_dither_slice_2d<T>(&self, values: &mut [T], width: usize, one: T)
fn simple_dither_slice_2d<T>(&self, values: &mut [T], width: usize, one: T)
Simple dither for a 2D image stored as a flat slice (parallel version).
Sourcefn dither_float_2d<Src, Dest>(&self, value: Src, x: u32, y: u32) -> Dest
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.
Sourcefn 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,
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.