use super::gdf_vectors::{gdf_eval, GDF_DODECAHEDRON};
use glam::Vec3;
#[inline(always)]
pub fn sdf_dodecahedron(p: Vec3, radius: f32) -> f32 {
gdf_eval(p, &GDF_DODECAHEDRON, radius)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_dodecahedron_origin() {
let d = sdf_dodecahedron(Vec3::ZERO, 1.0);
assert!(d < 0.0, "Origin should be inside, got {}", d);
}
#[test]
fn test_dodecahedron_outside() {
let d = sdf_dodecahedron(Vec3::new(3.0, 0.0, 0.0), 1.0);
assert!(d > 0.0, "Far point should be outside, got {}", d);
}
#[test]
fn test_dodecahedron_surface() {
let n = Vec3::new(0.0, 0.850_650_8, 0.525_731_1);
let d = sdf_dodecahedron(n * 1.0, 1.0);
assert!(
d.abs() < 0.01,
"Face center should be on surface, got {}",
d
);
}
#[test]
fn test_dodecahedron_symmetry() {
let r = 1.0;
let d1 = sdf_dodecahedron(Vec3::new(0.5, 0.5, 0.5), r);
let d2 = sdf_dodecahedron(Vec3::new(-0.5, 0.5, 0.5), r);
assert!((d1 - d2).abs() < 1e-6);
}
}