libnoise/core/adapters/
add.rs

1use crate::core::generator::{Generator, Generator1D, Generator2D, Generator3D, Generator4D};
2
3/// A generator adding `offset` to results of the underlying generator.
4///
5/// For details, see the documentation of [`add()`]. Typically, this struct is not meant
6/// to be used directly. Instead, [`add()`] implemented by [`Generator`], should be used
7/// to create [`Add`].
8///
9/// [`add()`]: Generator::add
10#[derive(Clone, Copy, Debug)]
11pub struct Add<const D: usize, G> {
12    generator: G,
13    offset: f64,
14}
15
16impl<G: Generator<1>> Generator1D for Add<1, G> {}
17impl<G: Generator<2>> Generator2D for Add<2, G> {}
18impl<G: Generator<3>> Generator3D for Add<3, G> {}
19impl<G: Generator<4>> Generator4D for Add<4, G> {}
20
21impl<const D: usize, G> Add<D, G>
22where
23    G: Generator<D>,
24{
25    #[inline]
26    pub fn new(generator: G, offset: f64) -> Self {
27        Self { generator, offset }
28    }
29}
30
31impl<const D: usize, G> Generator<D> for Add<D, G>
32where
33    G: Generator<D>,
34{
35    #[inline]
36    fn sample(&self, point: [f64; D]) -> f64 {
37        self.generator.sample(point) + self.offset
38    }
39}