use crate::compiled::real::Real;
#[inline(always)]
pub fn sdf_groove(a: f32, b: f32, ra: f32, rb: f32) -> f32 {
sdf_groove_r::<f32>(a, b, ra, rb)
}
#[inline(always)]
pub fn sdf_groove_r<R: Real>(a: R, b: R, ra: f32, rb: f32) -> R {
a.max((a + R::splat(ra)).min(R::splat(rb) - b.abs()))
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_groove_far_outside() {
let d = sdf_groove(5.0, 0.5, 0.1, 0.05);
assert!(
(d - 5.0).abs() < 0.01,
"Far outside should be ~a, got {}",
d
);
}
#[test]
fn test_groove_preserves_interior() {
let d = sdf_groove(-5.0, 0.0, 0.1, 0.05);
assert!(d.is_finite());
}
#[test]
fn test_groove_finite() {
let d = sdf_groove(0.0, 0.0, 0.2, 0.1);
assert!(d.is_finite());
}
}