noise/noise_fns/combiners/
add.rs

1use crate::noise_fns::NoiseFn;
2use core::marker::PhantomData;
3
4/// Noise function that outputs the sum of the two output values from two source
5/// functions.
6#[derive(Clone)]
7pub struct Add<T, Source1, Source2, const DIM: usize>
8where
9    Source1: NoiseFn<T, DIM>,
10    Source2: NoiseFn<T, DIM>,
11{
12    /// Outputs a value.
13    pub source1: Source1,
14
15    /// Outputs a value.
16    pub source2: Source2,
17
18    phantom: PhantomData<T>,
19}
20
21impl<T, Source1, Source2, const DIM: usize> Add<T, Source1, Source2, DIM>
22where
23    Source1: NoiseFn<T, DIM>,
24    Source2: NoiseFn<T, DIM>,
25{
26    pub fn new(source1: Source1, source2: Source2) -> Self {
27        Self {
28            source1,
29            source2,
30            phantom: PhantomData,
31        }
32    }
33}
34
35impl<T, Source1, Source2, const DIM: usize> NoiseFn<T, DIM> for Add<T, Source1, Source2, DIM>
36where
37    T: Copy,
38    Source1: NoiseFn<T, DIM>,
39    Source2: NoiseFn<T, DIM>,
40{
41    fn get(&self, point: [T; DIM]) -> f64 {
42        self.source1.get(point) + self.source2.get(point)
43    }
44}