noise_functions/modifiers/
max.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
26
27
28
29
30
31
32
33
34
35
36
37
#[cfg(feature = "nightly-simd")]
use core::simd::{LaneCount, Simd, SupportedLaneCount};

use crate::{math::max, Noise, Sample};

/// Computes the maximum of the two output values, ignoring NaN.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Max<A, B> {
    pub lhs: A,
    pub rhs: B,
}

impl<A, B> Noise for Max<A, B> {}

impl<const DIM: usize, A, B> Sample<DIM> for Max<A, B>
where
    A: Sample<DIM>,
    B: Sample<DIM>,
{
    #[inline]
    fn sample_with_seed(&self, point: [f32; DIM], seed: i32) -> f32 {
        max(self.lhs.sample_with_seed(point, seed), self.rhs.sample_with_seed(point, seed))
    }
}

#[cfg(feature = "nightly-simd")]
impl<const DIM: usize, const LANES: usize, A, B> Sample<DIM, Simd<f32, LANES>> for Max<A, B>
where
    A: Sample<DIM, Simd<f32, LANES>>,
    B: Sample<DIM, Simd<f32, LANES>>,
    LaneCount<LANES>: SupportedLaneCount,
{
    #[inline]
    fn sample_with_seed(&self, point: Simd<f32, LANES>, seed: i32) -> f32 {
        max(self.lhs.sample_with_seed(point, seed), self.rhs.sample_with_seed(point, seed))
    }
}