From c64a611818a48817159bc7424ff6e0ca5986fbb2 Mon Sep 17 00:00:00 2001 From: rlartot <94693724+rlartot@users.noreply.github.com> Date: Tue, 20 Oct 2026 12:37:43 +0000 Subject: [PATCH] Boolean: fail an unverifiable intersection instead of keeping what it should trim (#3244) (#3344) * claim: #3244 Co-Authored-By: Claude Opus 5.5 * Fail an unverifiable intersection instead of keeping what it should trim (#3244) When every route of the general boolean fails, it falls back on the sampled answer (one body whole, or nothing) with a "not verified ... that part is ignored" warning, even when the bodies' facets cross well past their faceting error. For an intersection that keeps exactly the material it was asked to trim: teeth standing 0.27 mm out of a trimming cylinder came back untrimmed, and `solidcraft-cli run` exited 0 with a part 16.918 mm in radius. An intersection whose sampled answer is contradicted by facets crossing by more than twice the depth the warning reports (6 x the check mesh tolerance, three times the faceting error of two meshes) now fails, and the model is kept. Cuts and unions keep the fallback: shelling a body in two pieces relies on it (a cavity tool grazing the other piece), with the same depth and ignored volume as this case. Fixes #3244 Co-Authored-By: Claude Opus 5.5 * Leave an empty unverified intersection as it was (#3244) Only a doubted intersection that keeps one body whole is refused. An empty one ("the bodies are apart") stays a result reported unverified: the clearance and interference checks rely on it, and main's new a_pin_through_a_d_bore_of_its_size_still_overlaps_the_flat (#2714) expects it. Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Opus 5.5 --- crates/engine/src/boolean_regression_tests.rs | 28 +++++++++++++++++++ crates/kernel/src/ops.rs | 15 ++++++++++ 2 files changed, 43 insertions(+) diff --git a/crates/engine/src/boolean_regression_tests.rs b/crates/engine/src/boolean_regression_tests.rs index 1ecbe4773..8cf79c6f1 100644 --- a/crates/engine/src/boolean_regression_tests.rs +++ b/crates/engine/src/boolean_regression_tests.rs @@ -34,6 +34,34 @@ fn check_partial_face_contact_pattern() { println!("#674 volume {volume:.6} / {expected_volume:.6} mm³; area {area:.6} / {expected_area:.6} mm²; {shells} shells"); } +/// A cylinder intersected with a disc carrying a tooth whose corners stand 0.27 mm out of it +/// (radius 16.92 for 16.65): the general boolean can't intersect them, and the sampled answer +/// (the disc is inside the cylinder) used to be kept with a warning, corners and all. The +/// intersection must trim them or fail and leave the body as it was (#3244). +#[test] +fn intersection_never_keeps_material_outside_the_trimming_cylinder() { + let mut s = Session::default(); + let (a, b) = ([-0.1706475844770042, 7.63270030627277], [0.1706475844770042, 7.63270030627277]); + for (command, params) in [ + ("solid.cylinder", json!({"radius": 16.65, "height": 5, "body_name": "Base"})), + ("sketch.create", json!({"plane": {"origin": [0, 0, 0], "x_dir": [-1, 0, 0], "y_dir": [0, 0, 1]}})), + ("sketch.line", json!({"points": [a, [-3, 4.99], [3, 4.99], b]})), + ("sketch.arc.three_point", json!({"start": b, "through": [0, 7.7], "end": a})), + ("sketch.finish", json!({})), + ("solid.extrude", json!({"distance": 1.6875953835063608, "start_offset": 14.962404616493638, "operation": "join", "targets": ["Base"]})), + ] { + s.execute(command, ¶ms).unwrap(); + } + let before = volume(&s, "Base"); + let r = s.execute("solid.cylinder", &json!({"radius": 16.65, "height": 14.59, "operation": "intersect", "targets": ["Base"]})); + let state = s.model.state(); + let reach = state.body("Base").unwrap().body.tessellate(1e-3).unwrap().positions.iter().map(|p| p.x.hypot(p.y)).fold(0.0, f64::max); + match r { + Ok(_) => assert!(reach < 16.65 + 1e-2, "kept material out to radius {reach}"), + Err(e) => assert!((volume(&s, "Base") - before).abs() < 1e-9 && reach > 16.9, "{e}"), + } +} + fn replay(script: &str) -> Session { let mut s = Session::default(); let script: Value = serde_json::from_str(script).unwrap(); diff --git a/crates/kernel/src/ops.rs b/crates/kernel/src/ops.rs index 238ee378b..b591fe960 100644 --- a/crates/kernel/src/ops.rs +++ b/crates/kernel/src/ops.rs @@ -1799,6 +1799,21 @@ where if let Some(body) = fine(&mut last) { return Ok(Some(body)); } + // An intersection keeps what lies in both bodies: when the sampled answer keeps one of them + // whole and is contradicted by facets that cross well past their faceting error, keeping it + // would keep exactly what the intersection was asked to trim (#3244: teeth standing 0.27 mm + // out of a trimming cylinder came back untrimmed). It fails instead, and the model is kept. + // An empty answer stays reported as unverified: the clearance checks measure it another way. + let deep = 2.0 * 3.0 * tol_m; + if op == BoolOp::Intersect + && matches!(doubted, Some(Some(_))) + && let (Some(ma), Some(mb)) = &meshes + && ma.crosses(mb, deep) + { + return Err(KernelError::Failed(format!( + "boolean {op:?}: the bodies pass through each other by more than {deep:.3e} mm where they could not be intersected; {last}" + ))); + } match doubted { Some(r) => { let mut event = BooleanFallback::new(BooleanStrategy::UnverifiedShortcut);