SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Pin analytic robustness and edge-contact scale regressions (#1950)
cronosbd4eb42c2d5b
diff --git a/crates/engine/src/fuzz.rs b/crates/engine/src/fuzz.rsindex db78c2d808..c1f51c5f33 100644--- a/crates/engine/src/fuzz.rs+++ b/crates/engine/src/fuzz.rs@@ -440,3 +440,83 @@ pub fn minimise(run: &Run) -> Run {}Run { seed: run.seed, steps, outcome, unsupported: Vec::new(), rejected: 0, boolean_fallbacks, boolean_reports_truncated }}++#[cfg(test)]+mod tests {+ use std::collections::BTreeMap;++ use super::*;++ #[allow(clippy::expect_used)]+ fn body_measures(s: &Session) -> Vec<solidcraft_kernel::BodyMeasure> {+ s.model.state().bodies.iter().map(|b| solidcraft_kernel::measure(&b.body).expect("measure a valid body")).collect()+ }++ fn seed_measures(seed: u64) -> Vec<solidcraft_kernel::BodyMeasure> {+ let (run, s) = run_session(seed, 8, &mut |_| {});+ assert_eq!(run.outcome.kind, "ok", "seed {seed}: {:?}", run.outcome);+ body_measures(&s)+ }++ /// Seed 34: a quarter cylinder R15 x 12.5, a spherical bite R2.5 centred+ /// at (10, 12.5, 0), and an independent R2 x 5 blind drill with a 118° tip.+ /// The circular-lens surface/volume integrals give these references+ /// independently of the B-rep and its measurement tessellation (docs/robustness.md).+ #[test]+ fn a_spherical_bite_and_blind_drill_match_the_analytic_solid() {+ let measured = seed_measures(34);+ assert_eq!(measured.len(), 1);+ let m = &measured[0];+ for (name, got, want) in [("volume", m.volume, 2_134.404_133), ("area", m.area, 1_086.316_691)] {+ // measure uses a chordal mesh with a 5e-5 relative chord tolerance.+ assert!((got - want).abs() <= 5e-5 * want, "{name}: {got} versus analytic {want}");+ }+ assert_eq!(m.merged.face_types, BTreeMap::from([("cone".into(), 1), ("cylinder".into(), 2), ("plane".into(), 4), ("sphere".into(), 1)]));+ }++ /// The recorded seed-67 design: a notched extrusion with bores and a boss,+ /// and a chamfered block with a patterned bore. Freeze the commands because+ /// retaining disconnected shells in one body (#2247) changes later generator picks.+ /// Redundant raw subdivisions must preserve the original analytic surface inventory.+ #[test]+ fn a_patterned_bore_preserves_the_analytic_surfaces() {+ let commands = [+ ("sketch.create", json!({"plane":"XY"})),+ ("sketch.line", json!({"points":[[0,0],[30.0,0],[30.0,32.5],[17.5,32.5],[17.5,17.5],[10.0,17.5],[10.0,32.5],[0,32.5]]})),+ ("sketch.arc.three_point", json!({"end":[0,0],"start":[0,32.5],"through":[-15.0,16.25]})),+ ("sketch.finish", json!({})),+ ("solid.extrude", json!({"distance":20.0})),+ ("solid.cylinder", json!({"axis":[0.0,0.0,-1.0],"base":[-0.0,0.0,20.00000000000001],"height":2.5,"operation":"cut","radius":6.25})),+ ("solid.hole", json!({"diameter":6.0,"position":[13.749999999999998,17.5,10.00000000000001]})),+ ("solid.cylinder", json!({"axis":[0.0,0.0,1.0],"base":[-5.0,12.5,2.5],"height":30.0,"operation":"join","radius":3.75})),+ (+ "solid.box",+ json!({"corner":[-14.999881984669182,22.5,32.500000000000014],"height":20.0,"length":12.5,"operation":"join","width":12.5}),+ ),+ ("solid.hole", json!({"depth":12.5,"diameter":4.0,"position":[-8.749881984669182,28.75,32.500000000000014]})),+ (+ "solid.chamfer",+ json!({"distance":0.5,"edges":[[-2.499881984669182,28.75,32.500000000000014],[-9.900529629797113,27.11414854074047,32.500000000000014],[-8.749881984669182,35.0,32.500000000000014]]}),+ ),+ ("solid.pattern.rectangular", json!({"count1":2,"dir1":[1.0,0.0,0.0],"features":["Hole2"],"spacing1":7.5})),+ ];+ let mut s = Session::default();+ for (command, params) in commands {+ let result = s.execute(command, ¶ms);+ assert!(result.is_ok(), "{command}: {result:?}");+ for body in &s.model.state().bodies {+ assert!(body.body.validity().is_empty(), "{command}: {:?}", body.body.validity());+ }+ }+ let measured = body_measures(&s);+ assert_eq!(measured.len(), 1);+ assert_eq!(measured.iter().map(|m| m.shells).sum::<usize>(), 2);+ let mut kinds = BTreeMap::new();+ for m in &measured {+ for (kind, count) in &m.merged.face_types {+ *kinds.entry(kind.clone()).or_insert(0) += count;+ }+ }+ assert_eq!(kinds, BTreeMap::from([("cone".into(), 1), ("cylinder".into(), 6), ("plane".into(), 22)]));+ }+}diff --git a/crates/kernel/tests/boolean_props.rs b/crates/kernel/tests/boolean_props.rsindex 064d210a4c..7fb11c31ae 100644--- a/crates/kernel/tests/boolean_props.rs+++ b/crates/kernel/tests/boolean_props.rs@@ -118,6 +118,25 @@ fn identity(a: &Prim, b: &Prim) -> Result<(), TestCaseError> {Ok(())}+fn scale(a: &Prim, b: &Prim, k: f64) -> Result<(), TestCaseError> {+ let sc = |p: &Prim| match p.clone() {+ Prim::Box { at, size } => Prim::Box { at: at.map(|x| x * k), size: size.map(|x| x * k) },+ Prim::Cyl { at, axis, r, h } => Prim::Cyl { at: at.map(|x| x * k), axis, r: r * k, h: h * k },+ Prim::Sph { at, r } => Prim::Sph { at: at.map(|x| x * k), r: r * k },+ };+ let (ba, bb, ka, kb) = (a.body(), b.body(), sc(a).body(), sc(b).body());+ let s = vol(&ba) + vol(&bb);+ for op in [BoolOp::Union, BoolOp::Intersect, BoolOp::Cut] {+ let (one, big) = (run(&ba, &bb, op), run(&ka, &kb, op));+ if edge_contact_refusal(a, b, op, &one) && edge_contact_refusal(a, b, op, &big) {+ continue;+ }+ let (one, big) = (one?, big? / (k * k * k));+ prop_assert!(close(one, big, s), "{op:?} at scale 1 gives {one:.4}, at scale {k} gives {big:.4} (normalised)");+ }+ Ok(())+}+fn cfg(default: u32) -> ProptestConfig {// The env var overrides the default; proptest reads PROPTEST_CASES itself only when the// config does not set `cases`, so read it here.@@ -186,21 +205,7 @@ proptest! {/// (40x) expose tolerances that do not scale.#[test]fn scale_invariant(a in grid_prim(), b in grid_prim(), k in prop::sample::select(vec![0.05, 1.0, 40.0])) {- let sc = |p: &Prim| match p.clone() {- Prim::Box { at, size } => Prim::Box { at: at.map(|x| x * k), size: size.map(|x| x * k) },- Prim::Cyl { at, axis, r, h } => Prim::Cyl { at: at.map(|x| x * k), axis, r: r * k, h: h * k },- Prim::Sph { at, r } => Prim::Sph { at: at.map(|x| x * k), r: r * k },- };- let (ba, bb, ka, kb) = (a.body(), b.body(), sc(&a).body(), sc(&b).body());- let s = vol(&ba) + vol(&bb);- for op in [BoolOp::Union, BoolOp::Intersect, BoolOp::Cut] {- let (one, big) = (run(&ba, &bb, op), run(&ka, &kb, op));- if edge_contact_refusal(&a, &b, op, &one) && edge_contact_refusal(&a, &b, op, &big) {- continue;- }- let (one, big) = (one?, big? / (k * k * k));- prop_assert!(close(one, big, s), "{op:?} at scale 1 gives {one:.4}, at scale {k} gives {big:.4} (normalised)");- }+ scale(&a, &b, k)?;}/// A∪A = A, A∩A = A, A−A = nothing.@@ -279,6 +284,19 @@ fn edge_only_box_join_is_refused_in_both_orders() {}}+/// The saved scale-invariance failure: these boxes meet at y=30, z=20 along an+/// edge, so a join is refused at every scale. Intersection and cut still scale.+#[test]+fn edge_only_box_contact_is_scale_invariant() {+ let a = Prim::Box { at: [0.0, 15.0, 7.5], size: [7.5, 15.0, 12.5] };+ let b = Prim::Box { at: [0.0, 30.0, 20.0], size: [5.0, 5.0, 5.0] };+ assert!(edge_only_boxes(&a, &b));+ for k in [0.05, 1.0, 40.0] {+ check(scale(&a, &b, k));+ check(scale(&b, &a, k));+ }+}+fn check(r: Result<(), TestCaseError>) {if let Err(e) = r {panic!("{e}");diff --git a/docs/robustness.md b/docs/robustness.mdindex 4aec674eb5..168601ceaa 100644--- a/docs/robustness.md+++ b/docs/robustness.md@@ -63,6 +63,33 @@ ROBUSTNESS_GOLDENS_BLESS="why it changed" cargo test --profile ci -p solidcraft-The changed seeds and the reason are added to the file's `notes`; say why in the pull request too.+The generator feeds the current geometry's bounds and face/edge picks back into later+commands. The same RNG seed can therefore generate different command coordinates or picks+on different math libraries. The original inputs are retained, including near-contact cases.+Platform snapshots track repeatability; they do not certify cross-platform geometric+equivalence or resolve the numerical differences tracked in #924.++### Independent measurement checks++The seeded snapshots also have checks against geometric references. Seed 34 starts with a+quarter cylinder of radius 15 and height 12.5 (`x,y >= 0`, `-12.5 <= z <= 0`), cuts it with a+radius-2.5 sphere centred at (10, 12.5, 0), then drills an independent radius-2, depth-5 blind+hole from (0, 7.5, -6.25) along +X, with a 118-degree tip.+Subtracting the sphere/cylinder intersection and the drill gives **2134.404133 mm³** and+**1086.316691 mm²**. The drill has tip height `2 / tan(59 degrees)`; the spherical bite is+integrated over the intersection of the radius-15 disk and the sphere's projected radius-2.5+disk. Integrating the lower spherical hemisphere and the removed cylinder-wall patch gives+the surface reference. The test compares the chordal measurement with these independent+references at 5e-5 relative error.++A fixed command replay recorded from seed 67 checks two disconnected shells kept in one+body after a cut (#2247), with a combined analytic surface inventory of 22 planar, six+cylindrical and one conical face after merging redundant subdivisions. The commands are+fixed because the generator chooses later operations from the current body and edge layout;+changes to body grouping can therefore change the generated design. This preserves the+original geometric reference independently of those choices. These checks supplement the+snapshots' stricter repeatability comparisons of raw topology and tessellated measurements.+## Successful Boolean retriesWhen an accepted Boolean result needs a retry that can make it differ from the