noise_functions/modifiers/
div.rs

1#[cfg(feature = "nightly-simd")]
2use core::simd::{LaneCount, Simd, SupportedLaneCount};
3
4use crate::{Noise, Sample};
5
6/// Divides one output value by the other.
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
8pub struct Div<A, B> {
9    pub lhs: A,
10    pub rhs: B,
11}
12
13impl<A, B> Noise for Div<A, B> {}
14
15impl<const DIM: usize, A, B> Sample<DIM> for Div<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        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 Div<A, B>
28where
29    A: Sample<DIM, Simd<f32, LANES>>,
30    B: Sample<DIM, Simd<f32, LANES>>,
31    LaneCount<LANES>: SupportedLaneCount,
32{
33    #[inline]
34    fn sample_with_seed(&self, point: Simd<f32, LANES>, seed: i32) -> f32 {
35        self.lhs.sample_with_seed(point, seed) / self.rhs.sample_with_seed(point, seed)
36    }
37}