noise_functions/
noise_fn.rs

1use crate::{Noise, Sample};
2
3/// Wraps a function to make it implement [`Sample`].
4///
5/// The function is expected to take one parameter for the point and optionally a seed parameter.
6pub struct NoiseFn<F, const WITH_SEED: bool>(pub F);
7
8impl<F, const WITH_SEED: bool> Noise for NoiseFn<F, WITH_SEED> {}
9
10impl<const DIM: usize, Point, F> Sample<DIM, Point> for NoiseFn<F, false>
11where
12    F: Fn(Point) -> f32,
13{
14    fn sample_with_seed(&self, point: Point, _seed: i32) -> f32 {
15        self.0(point)
16    }
17}
18
19impl<const DIM: usize, Point, F> Sample<DIM, Point> for NoiseFn<F, true>
20where
21    F: Fn(Point, i32) -> f32,
22{
23    fn sample_with_seed(&self, point: Point, seed: i32) -> f32 {
24        self.0(point, seed)
25    }
26}