use crate::compiled::real::Real;
#[inline(always)]
pub fn sdf_pipe(a: f32, b: f32, r: f32) -> f32 {
sdf_pipe_r::<f32>(a, b, r)
}
#[inline(always)]
pub fn sdf_pipe_r<R: Real>(a: R, b: R, r: f32) -> R {
(a * a + b * b).sqrt() - R::splat(r)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_pipe_on_surface() {
let d = sdf_pipe(0.5, 0.0, 0.5);
assert!(d.abs() < 1e-6, "Should be on surface, got {}", d);
}
#[test]
fn test_pipe_inside() {
let d = sdf_pipe(0.1, 0.1, 0.5);
assert!(d < 0.0, "Should be inside, got {}", d);
}
#[test]
fn test_pipe_outside() {
let d = sdf_pipe(1.0, 1.0, 0.5);
assert!(d > 0.0, "Should be outside, got {}", d);
}
#[test]
fn test_pipe_symmetry() {
let d1 = sdf_pipe(0.3, 0.5, 0.2);
let d2 = sdf_pipe(0.5, 0.3, 0.2);
assert!((d1 - d2).abs() < 1e-6, "Should be symmetric");
}
}