noise_functions/modifiers/
round.rs

1#[cfg(feature = "nightly-simd")]
2use core::simd::{LaneCount, Simd, SupportedLaneCount};
3
4use crate::{math::round, Noise, Sample};
5
6/// Computes the nearest integer to the output value.
7/// If a value is half-way between two integers, round away from 0.0.
8pub struct Round<A> {
9    pub noise: A,
10}
11
12impl<N> Noise for Round<N> {}
13
14impl<const DIM: usize, N> Sample<DIM> for Round<N>
15where
16    N: Sample<DIM>,
17{
18    #[inline]
19    fn sample_with_seed(&self, point: [f32; DIM], seed: i32) -> f32 {
20        round(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 Round<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        round(self.noise.sample_with_seed(point, seed))
33    }
34}