Skip to main content

noise_functions/modifiers/
min.rs

1#[cfg(feature = "nightly-simd")]
2use core::simd::Simd;
3
4use crate::{math::min, Noise, Sample};
5
6/// Computes the minimum of the two output values, ignoring NaN.
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
8pub struct Min<A, B> {
9    pub lhs: A,
10    pub rhs: B,
11}
12
13impl<A, B> Noise for Min<A, B> {}
14
15impl<const DIM: usize, A, B> Sample<DIM> for Min<A, B>
16where
17    A: Sample<DIM>,
18    B: Sample<DIM>,
19{
20    #[inline]
21    fn sample_with_seed(&self, point: [f32; DIM], seed: i32) -> f32 {
22        min(self.lhs.sample_with_seed(point, seed), self.rhs.sample_with_seed(point, seed))
23    }
24}
25
26#[cfg(feature = "nightly-simd")]
27impl<const DIM: usize, const LANES: usize, A, B> Sample<DIM, Simd<f32, LANES>> for Min<A, B>
28where
29    A: Sample<DIM, Simd<f32, LANES>>,
30    B: Sample<DIM, Simd<f32, LANES>>,
31{
32    #[inline]
33    fn sample_with_seed(&self, point: Simd<f32, LANES>, seed: i32) -> f32 {
34        min(self.lhs.sample_with_seed(point, seed), self.rhs.sample_with_seed(point, seed))
35    }
36}