use crate::prelude::*;
pub struct VoronoiBasic {}
impl Noise for VoronoiBasic {
fn new() -> Self {
Self {
}
}
fn get_2d(&self, p: (FP, FP)) -> FP {
fn hash2d_2(mut p: FP2 ) -> FP2 {
p = FP2::new(glm::dot(&p, &FP2::new(127.1, 311.7)),
glm::dot(&p, &FP2::new(269.5,183.3)));
glm::fract(&glm::sin(&p).component_mul( &FP2::new(18.5453, 18.5453 )))
}
let x = FP2::new(p.0, p.1);
let n = glm::floor(&x);
let f = glm::fract(&x);
let mut m = FP3::new( 8.0, 8.0, 8.0 );
for j in -1..=1 {
for i in -1..=1 {
let g = FP2::new( i as FP, j as FP );
let o = hash2d_2( n + g );
let r = g - f + (FP2::new(0.5, 0.5) + 0.5 * glm::sin(&(6.2831*o)));
let d = glm::dot( &r, &r );
if d < m.x {
m = FP3::new( d, o.x, o.y );
}
}
}
return m.y + m.z; }
}