noise/noise_fns/modifiers/
abs.rs

1use crate::noise_fns::NoiseFn;
2use core::marker::PhantomData;
3
4/// Noise function that outputs the absolute value of the output value from the
5/// source function.
6#[derive(Clone)]
7pub struct Abs<T, Source, const DIM: usize>
8where
9    Source: NoiseFn<T, DIM>,
10{
11    /// Outputs a value.
12    pub source: Source,
13
14    phantom: PhantomData<T>,
15}
16
17impl<T, Source, const DIM: usize> Abs<T, Source, DIM>
18where
19    Source: NoiseFn<T, DIM>,
20{
21    pub fn new(source: Source) -> Self {
22        Self {
23            source,
24            phantom: PhantomData,
25        }
26    }
27}
28
29impl<T, Source, const DIM: usize> NoiseFn<T, DIM> for Abs<T, Source, DIM>
30where
31    Source: NoiseFn<T, DIM>,
32{
33    fn get(&self, point: [T; DIM]) -> f64 {
34        (self.source.get(point)).abs()
35    }
36}