use crate::noise_fns::NoiseFn;
use core::marker::PhantomData;
#[derive(Clone)]
pub struct ScaleBias<T, Source, const DIM: usize> {
pub source: Source,
pub scale: f64,
pub bias: f64,
phantom: PhantomData<T>,
}
impl<T, Source, const DIM: usize> ScaleBias<T, Source, DIM>
where
Source: NoiseFn<T, DIM>,
{
pub fn new(source: Source) -> Self {
Self {
source,
scale: 1.0,
bias: 0.0,
phantom: PhantomData,
}
}
pub fn set_scale(self, scale: f64) -> Self {
Self { scale, ..self }
}
pub fn set_bias(self, bias: f64) -> Self {
Self { bias, ..self }
}
}
impl<T, Source, const DIM: usize> NoiseFn<T, DIM> for ScaleBias<T, Source, DIM>
where
Source: NoiseFn<T, DIM>,
{
#[cfg(not(target_os = "emscripten"))]
fn get(&self, point: [T; DIM]) -> f64 {
(self.source.get(point)).mul_add(self.scale, self.bias)
}
#[cfg(target_os = "emscripten")]
fn get(&self, point: [T; DIM]) -> f64 {
(self.source.get(point) * self.scale) + self.bias
}
}