From 955232fbeaf73cb64c2975c6b18a89ffc38afe98 Mon Sep 17 00:00:00 2001 From: jyviko <2501648+jyviko@users.noreply.github.com> Date: Mon, 2 Nov 2026 20:35:15 -0500 Subject: [PATCH] Test: a volume's accuracy out of range is clamped as mass_properties clamps it core::volume passed its accuracy to solidcore as given: 0 fails (None), where mass_properties takes 1e-8. A sphere's volume at 0, -1 and 1e-15 must be its volume at 1e-8. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01DtL5M41G8Nua7HvuFPZkmJ --- crates/smlib/src/core.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/crates/smlib/src/core.rs b/crates/smlib/src/core.rs index ed0988fed..a00403943 100644 --- a/crates/smlib/src/core.rs +++ b/crates/smlib/src/core.rs @@ -573,6 +573,18 @@ mod tests { assert!((v - 6000.0).abs() < 6000.0 * 1e-9, "{v}"); } + /// An accuracy finer than 1e-8 or not positive is 1e-8, as `mass_properties` takes it: a + /// sphere's volume at 0, -1 and 1e-15 is its volume at 1e-8, on its closed form. + #[test] + fn a_volume_accuracy_out_of_range_is_clamped() { + let ball = make_sphere([1.0, 2.0, 3.0], 5.0).unwrap(); + let at = volume(&ball, 1e-8).unwrap(); + assert!((at - 4.0 / 3.0 * std::f64::consts::PI * 125.0).abs() < 1e-6, "{at}"); + for acc in [0.0, -1.0, 1e-15] { + assert_eq!(volume(&ball, acc).ok(), Some(at), "accuracy {acc}"); + } + } + #[test] fn hostile_numbers_are_refused() { assert!(make_box([f64::NAN, 0.0, 0.0], [1.0; 3]).is_err());