noise_functions/modifiers/
translate_xy.rs1use core::ops::IndexMut;
2
3use crate::{Noise, Sample};
4
5pub struct TranslateXy<Noise, X, Y> {
7 pub noise: Noise,
8 pub x: X,
9 pub y: Y,
10}
11
12impl<N, X, Y> Noise for TranslateXy<N, X, Y> {}
13
14impl<const DIM: usize, Point, N, X, Y> Sample<DIM, Point> for TranslateXy<N, X, Y>
15where
16 Point: IndexMut<usize, Output = f32> + Copy,
17 N: Sample<DIM, Point>,
18 X: Sample<DIM, Point>,
19 Y: Sample<DIM, Point>,
20{
21 fn sample_with_seed(&self, point: Point, seed: i32) -> f32 {
22 let mut translated = point;
23
24 if DIM > 0 {
25 translated[0] += self.x.sample_with_seed(point, seed);
26 }
27
28 if DIM > 1 {
29 translated[1] += self.y.sample_with_seed(point, seed);
30 }
31
32 self.noise.sample_with_seed(translated, seed)
33 }
34}