1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
use crate::noise_fns::NoiseFn;

/// Noise function that outputs the absolute value of the output value from the
/// source function.
pub struct Abs<'a, T> {
    /// Outputs a value.
    pub source: &'a dyn NoiseFn<T>,
}

impl<'a, T> Abs<'a, T> {
    pub fn new(source: &'a dyn NoiseFn<T>) -> Self {
        Self { source }
    }
}

impl<'a, T> NoiseFn<T> for Abs<'a, T> {
    fn get(&self, point: T) -> f64 {
        (self.source.get(point)).abs()
    }
}