noise_functions/modifiers/
map.rs1#[cfg(feature = "nightly-simd")]
2use core::simd::{LaneCount, Simd, SupportedLaneCount};
3
4use crate::{Noise, Sample};
5
6pub struct Map<N, F> {
8 pub noise: N,
9 pub f: F,
10}
11
12impl<N, F> Noise for Map<N, F> {}
13
14impl<N, F, const DIM: usize> Sample<DIM> for Map<N, F>
15where
16 N: Sample<DIM>,
17 F: Fn(f32) -> f32,
18{
19 #[inline]
20 fn sample_with_seed(&self, point: [f32; DIM], seed: i32) -> f32 {
21 (self.f)(self.noise.sample_with_seed(point, seed))
22 }
23}
24
25#[cfg(feature = "nightly-simd")]
26impl<N, F, const DIM: usize, const LANES: usize> Sample<DIM, Simd<f32, LANES>> for Map<N, F>
27where
28 N: Sample<DIM, Simd<f32, LANES>>,
29 F: Fn(f32) -> f32,
30 LaneCount<LANES>: SupportedLaneCount,
31{
32 #[inline]
33 fn sample_with_seed(&self, point: Simd<f32, LANES>, seed: i32) -> f32 {
34 (self.f)(self.noise.sample_with_seed(point, seed))
35 }
36}