use crate::{math::scale_shift, noise_fns::NoiseFn};
use core::marker::PhantomData;
#[derive(Clone)]
pub struct Exponent<T, Source, const DIM: usize>
where
Source: NoiseFn<T, DIM>,
{
pub source: Source,
pub exponent: f64,
phantom: PhantomData<T>,
}
impl<T, Source, const DIM: usize> Exponent<T, Source, DIM>
where
Source: NoiseFn<T, DIM>,
{
pub fn new(source: Source) -> Self {
Self {
source,
exponent: 1.0,
phantom: PhantomData,
}
}
pub fn set_exponent(self, exponent: f64) -> Self {
Self { exponent, ..self }
}
}
impl<T, Source, const DIM: usize> NoiseFn<T, DIM> for Exponent<T, Source, DIM>
where
Source: NoiseFn<T, DIM>,
{
fn get(&self, point: [T; DIM]) -> f64 {
let mut value = self.source.get(point);
value = (value + 1.0) / 2.0;
value = value.abs();
value = value.powf(self.exponent);
scale_shift(value, 2.0)
}
}