noise_functions/modifiers/
translate_x.rs

1use core::ops::IndexMut;
2
3use crate::{Noise, Sample};
4
5/// Translates the point before it is being sampled by the base noise.
6pub struct TranslateX<Noise, X> {
7    pub noise: Noise,
8    pub x: X,
9}
10
11impl<N, X> Noise for TranslateX<N, X> {}
12
13impl<const DIM: usize, Point, N, X> Sample<DIM, Point> for TranslateX<N, X>
14where
15    Point: IndexMut<usize, Output = f32> + Copy,
16    N: Sample<DIM, Point>,
17    X: Sample<DIM, Point>,
18{
19    fn sample_with_seed(&self, point: Point, seed: i32) -> f32 {
20        let mut translated = point;
21
22        if DIM > 0 {
23            translated[0] += self.x.sample_with_seed(point, seed);
24        }
25
26        self.noise.sample_with_seed(translated, seed)
27    }
28}