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
29
30
31
32
33
34
35
36
37
use crate::private_prelude::*;

/// Wraps a noise and modifies its frequency.
///
/// This multiplies the point by the provided `frequency` before sampling.
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Frequency<Noise> {
    pub noise: Noise,
    pub frequency: f32,
}

impl<const DIM: usize, Noise> Sample<DIM, [f32; DIM]> for Frequency<Noise>
where
    Noise: Sample<DIM, [f32; DIM]>,
{
    fn sample(&self, mut point: [f32; DIM]) -> f32 {
        let frequency = self.frequency;

        for x in &mut point {
            *x *= frequency;
        }

        self.noise.sample(point)
    }
}

#[cfg(feature = "nightly-simd")]
impl<const DIM: usize, const LANES: usize, Noise> Sample<DIM, Simd<f32, LANES>> for Frequency<Noise>
where
    Noise: Sample<DIM, Simd<f32, LANES>>,
    LaneCount<LANES>: SupportedLaneCount,
{
    fn sample(&self, mut point: Simd<f32, LANES>) -> f32 {
        point *= splat(self.frequency);
        self.noise.sample(point)
    }
}