noise_functions/
value_or_noise.rs

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
use crate::{Constant, Noise};

/// Either a `f32` or a noise.
///
/// Used for [`Noise`] modifier methods.
pub trait ValueOrNoise {
    type Noise;
    fn into_noise(self) -> Self::Noise;
}

impl ValueOrNoise for f32 {
    type Noise = Constant;

    fn into_noise(self) -> Self::Noise {
        Constant(self)
    }
}

impl<N: Noise> ValueOrNoise for N {
    type Noise = Self;

    fn into_noise(self) -> Self::Noise {
        self
    }
}