From d2bb84d6fb643936ed9ed8ffcbe8a0b2abc86a9f Mon Sep 17 00:00:00 2001 From: jyviko <2501648+jyviko@users.noreply.github.com> Date: Thu, 29 Oct 2026 00:19:42 -0400 Subject: [PATCH] Wave 333/509: Tests: the cap whose loops prism_measure compares is found by its plane, not as the last face (and 3 more) 4 commits, squashed; the originals stay reachable from tag archive/merge-main-develop. - 6a780de5f jyviko: Tests: the helical groove's removed volume from the cut's exact volume, not a 0.01 mm mesh's - 80b7ce28e jyviko: Tests: volume checks held to what their measures can tell, not tighter - a3e42e548 jyviko: Tests: the cap whose loops prism_measure compares is found by its plane, not as the last face - fad9c44da jyviko: kernel: measure integrates to SMLib's finest accuracy, 1e-8, not 1e-4 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01DtL5M41G8Nua7HvuFPZkmJ --- crates/kernel/src/measure.rs | 9 +++++---- crates/kernel/src/outline_tests.rs | 6 +++++- crates/kernel/src/prism_measure.rs | 12 +++++++++--- crates/kernel/src/tests.rs | 4 +++- crates/kernel/src/thread_tests.rs | 4 +++- 5 files changed, 25 insertions(+), 10 deletions(-) diff --git a/crates/kernel/src/measure.rs b/crates/kernel/src/measure.rs index beecbe483..0915b0337 100644 --- a/crates/kernel/src/measure.rs +++ b/crates/kernel/src/measure.rs @@ -43,10 +43,11 @@ pub struct MassMeasure { pub notes: Vec, } -/// The relative accuracy SMLib integrates at: the finest of SmApiBrepComputeMassProperties' -/// documented range ("clamped to [1e-4, 1e-1]", SmApiQueries.h). Its cost is "governed by -/// dRelativeAccuracy". -const ACCURACY: f64 = 1e-4; +/// The relative accuracy SMLib integrates at: the finest the C API takes +/// ([`solidcraft_smlib::MEASURE_ACCURACY`], 1e-8). `smlib_brep_mass_properties` calls the +/// kernel's integration directly because SmApiBrepComputeMassProperties clamps to [1e-4, 1e-1], +/// which leaves curved faces off by 1e-5 to 1e-3; asking 1e-4 here threw that away. +const ACCURACY: f64 = solidcraft_smlib::MEASURE_ACCURACY; /// Measure a body. A B-rep body's volume, area and centre are SMLib's, integrated on its exact /// surfaces over its material regions (a sheet's: its faces' area and their centre, volume 0), diff --git a/crates/kernel/src/outline_tests.rs b/crates/kernel/src/outline_tests.rs index 017dd54eb..c1579db16 100644 --- a/crates/kernel/src/outline_tests.rs +++ b/crates/kernel/src/outline_tests.rs @@ -30,8 +30,12 @@ fn a_lip_swept_on_a_round_rim_joins_it() { let r = boolean(a, b, BoolOp::Union).unwrap().unwrap(); assert_eq!(r.shell_count(), 1, "inset {inset}: one solid"); assert!(r.validity().is_empty(), "inset {inset}: {:?}", r.validity()); + // Each mesh lies within its chord (1e-5) of its faces: two meshes of the same solid, + // tessellated face by face as each body has its faces, differ by at most their area + // times twice that. let v = mesh_volume(&r); - assert!((v - want).abs() < 1e-3, "inset {inset}: volume {v} vs {want}"); + let bound = crate::measure(&r).unwrap().area * 2e-5; + assert!((v - want).abs() < bound, "inset {inset}: volume {v} vs {want} (within {bound})"); } } } diff --git a/crates/kernel/src/prism_measure.rs b/crates/kernel/src/prism_measure.rs index eee0405a2..346a6fb0f 100644 --- a/crates/kernel/src/prism_measure.rs +++ b/crates/kernel/src/prism_measure.rs @@ -927,9 +927,15 @@ mod tests { } } assert_eq!(equivalent(&original, source.size(), &same, source.size()), Some(true)); - let last = original.faces.len() - 1; - let outward = preflight(&original).unwrap()[last]; - let runs = loop_runs(&original, last, 0, outward).unwrap(); + // A cap: a face whose plane is square to z (the record's face order is SMLib's, its last + // face may be the hole's wall). + let cap = original + .faces + .iter() + .position(|f| plane_of(&f.surface).is_some_and(|(_, u, v)| u.cross(v).normalized().is_some_and(|n| n.z.abs() > 0.9))) + .unwrap(); + let outward = preflight(&original).unwrap()[cap]; + let runs = loop_runs(&original, cap, 0, outward).unwrap(); assert!( loops_same( &cap_loop(&runs, &Plane::XY, 3e-9, &mut 2_000_000).unwrap(), diff --git a/crates/kernel/src/tests.rs b/crates/kernel/src/tests.rs index ff4b877e4..850bd87c5 100644 --- a/crates/kernel/src/tests.rs +++ b/crates/kernel/src/tests.rs @@ -1603,7 +1603,9 @@ fn overlapping_holes_and_mirror_joins() { let both = boolean(&half, &other, BoolOp::Union).unwrap().unwrap(); let v = measure(&half).unwrap().volume; let mb = measure(&both).unwrap(); - assert!(rel(mb.volume, 2.0 * v) < 1e-9, "{} vs {}", mb.volume, 2.0 * v); + // Both volumes are SMLib's integrals, each good to its relative accuracy (1e-4, + // measure::ACCURACY); a lost round or wall would be off by percent. + assert!(rel(mb.volume, 2.0 * v) < 1e-4, "{} vs {}", mb.volume, 2.0 * v); // One body: the shared face is gone and the faces either side of it merged. assert_eq!(mb.merged.faces, 10, "{:?}", mb.merged); // Two equal cylinders on one axis, overlapping: one longer cylinder. diff --git a/crates/kernel/src/thread_tests.rs b/crates/kernel/src/thread_tests.rs index 659f502e1..4816ba298 100644 --- a/crates/kernel/src/thread_tests.rs +++ b/crates/kernel/src/thread_tests.rs @@ -18,7 +18,9 @@ fn faceted_cut_of_a_helical_groove() { let section = [Vec2::new(1.2, -0.06), Vec2::new(1.6, -0.06), Vec2::new(1.6, 0.06), Vec2::new(1.2, 0.06)]; let groove = sweep_helix_mesh(&plane, §ion, base, k, p, 5.0, 48).unwrap(); let cut = faceted_boolean(&shaft, &groove, BoolOp::Cut, 1e-3).unwrap().unwrap(); - let m = cut.mesh(&crate::MeshTolerance::chord(0.01)).unwrap().measure(); + // The cut's own volume (SMLib's, of its exact faces): a mesh's at 0.01 mm sags inside the + // shaft's round wall by 0.18 mm³, five times the 3 % the groove is held to. + let m = crate::measure(&cut).unwrap(); // In the shaft from z = 0: the section (r 1.2…1.5, 0.12 tall) for 4 turns, plus the part of // the first turn's section above z = 0 (its z range is ±0.06 about the turn's height). let per_turn = 2.0 * PI * 0.12 * (1.5f64.powi(2) - 1.2f64.powi(2)) / 2.0;