libnoise/core/adapters/
power.rs

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