noise_functions/modifiers/
abs.rs

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