noise_functions/modifiers/
translate_x.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use core::ops::IndexMut;

use crate::{Noise, Sample};

/// Translates the point before it is being sampled by the base noise.
pub struct TranslateX<Noise, X> {
    pub noise: Noise,
    pub x: X,
}

impl<N, X> Noise for TranslateX<N, X> {}

impl<const DIM: usize, Point, N, X> Sample<DIM, Point> for TranslateX<N, X>
where
    Point: IndexMut<usize, Output = f32> + Copy,
    N: Sample<DIM, Point>,
    X: Sample<DIM, Point>,
{
    fn sample_with_seed(&self, point: Point, seed: i32) -> f32 {
        let mut translated = point;

        if DIM > 0 {
            translated[0] += self.x.sample_with_seed(point, seed);
        }

        self.noise.sample_with_seed(translated, seed)
    }
}