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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DtL5M41G8Nua7HvuFPZkmJ
This commit is contained in:
jyviko
2026-11-02 20:35:15 -05:00
parent ae45cc6623
commit 955232fbea
+12
View File
@@ -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());