use crate::{
core::super_simplex::*,
noise_fns::{NoiseFn, Seedable},
permutationtable::PermutationTable,
};
#[derive(Clone, Copy, Debug)]
pub struct SuperSimplex {
seed: u32,
perm_table: PermutationTable,
}
impl SuperSimplex {
pub const DEFAULT_SEED: u32 = 0;
pub fn new(seed: u32) -> Self {
Self {
seed,
perm_table: PermutationTable::new(seed),
}
}
}
impl Default for SuperSimplex {
fn default() -> Self {
Self::new(Self::DEFAULT_SEED)
}
}
impl Seedable for SuperSimplex {
fn set_seed(self, seed: u32) -> Self {
if self.seed == seed {
return self;
}
Self {
seed,
perm_table: PermutationTable::new(seed),
}
}
fn seed(&self) -> u32 {
self.seed
}
}
impl NoiseFn<f64, 2> for SuperSimplex {
fn get(&self, point: [f64; 2]) -> f64 {
super_simplex_2d(point.into(), &self.perm_table)
}
}
impl NoiseFn<f64, 3> for SuperSimplex {
fn get(&self, point: [f64; 3]) -> f64 {
super_simplex_3d(point.into(), &self.perm_table)
}
}