From 315d8cfeb7fb516b3ceb3a6678d6d79c25d4535d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=27tite=20T=C3=AAte?= Date: Wed, 4 Nov 2026 21:27:05 +0000 Subject: [PATCH] fix: sketch.intersect keeps a small round between short walls (#9962) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - section() kept the loose fit whenever it had fewer curves, even when it had merged 2 mm walls and an R2 round into one R2.85 arc that misses the walls, leaving the outline open - The tight fit is now also kept when the loose one strays from the exact crossings (on planes and rulings) and the tight one does not; capped work, other curves count as near - Test: a box with R2 corner rounds and four tapered grooves stopping 2 mm short, cut at Y=20 Co-authored-by: P'tite TĂȘte --- crates/doc/src/project.rs | 31 +++++++++++++- crates/engine/src/cmd/sketch_project_tests.rs | 41 +++++++++++++++++++ 2 files changed, 71 insertions(+), 1 deletion(-) diff --git a/crates/doc/src/project.rs b/crates/doc/src/project.rs index 05ba7b015..6e6a5f165 100644 --- a/crates/doc/src/project.rs +++ b/crates/doc/src/project.rs @@ -1619,7 +1619,36 @@ pub(crate) fn section(plane: &Plane, m: &Mesh, face: Option) -> Vec Option { + match *g { + LinkGeom::Line(a, b) => { + let d = b - a; + let t = if d.len2() > 0.0 { ((p - a).dot(d) / d.len2()).clamp(0.0, 1.0) } else { 0.0 }; + Some(p.dist(a.lerp(b, t))) + } + LinkGeom::Circle(c, r) => Some((p.dist(c) - r).abs()), + LinkGeom::Arc { c, a, b } => { + let (s0, sw) = ((a - c).angle(), ((b - c).angle() - (a - c).angle()).rem_euclid(std::f64::consts::TAU)); + if ((p - c).angle() - s0).rem_euclid(std::f64::consts::TAU) <= sw + 1e-9 { + Some((p.dist(c) - c.dist(a)).abs()) + } else { + Some(p.dist(a).min(p.dist(b))) + } + } + _ => None, + } } /// The segments where the plane crosses the mesh's triangles (in plane coordinates, each with diff --git a/crates/engine/src/cmd/sketch_project_tests.rs b/crates/engine/src/cmd/sketch_project_tests.rs index d2e5f8cec..7d2bf069f 100644 --- a/crates/engine/src/cmd/sketch_project_tests.rs +++ b/crates/engine/src/cmd/sketch_project_tests.rs @@ -1395,6 +1395,47 @@ fn whole_body_intersect_of_a_filleted_plate_keeps_exact_lines_and_arcs() { assert!(arcs.iter().all(|r| (r - 2.).abs() < 5e-3), "{arcs:?}"); } #[test] +fn whole_body_intersect_keeps_a_small_round_between_short_walls() { + use solidcraft_sketch::CurveKind; + // A tapered groove on each side stops 2 mm short of the R2 corner rounds: walls of 2 mm, a + // round, walls of 2 mm, which a loose fit takes for one larger arc that misses the walls. + let mut s = Session::default(); + run(&mut s, "solid.box", json!({"length": 150, "width": 55, "height": 150, "corner": [-75, 0, -75], "body_name": "Part"})); + run(&mut s, "solid.fillet", json!({"edges": [[75, 27.5, 75], [-75, 27.5, 75], [75, 27.5, -75], [-75, 27.5, -75]], "radius": 2})); + for (plane, offset, direction, rect) in [ + ("YZ", 75, "negative", [[7, -71], [48, 71]]), + ("YZ", -75, "positive", [[7, -71], [48, 71]]), + ("XY", 75, "negative", [[-71, 7], [71, 48]]), + ("XY", -75, "positive", [[-71, 7], [71, 48]]), + ] { + run(&mut s, "sketch.create", json!({"plane": plane, "offset": offset})); + run(&mut s, "sketch.rectangle.two_point", json!({"p0": rect[0], "p1": rect[1]})); + run(&mut s, "sketch.finish", json!({})); + run(&mut s, "solid.extrude", json!({"distance": 6, "direction": direction, "taper": "-56.31 deg", "operation": "cut", "targets": ["Part"]})); + } + let sketch = run(&mut s, "sketch.create", json!({"plane": "XZ", "offset": 20, "project_edges": false}))["sketch"].as_u64().unwrap(); + run(&mut s, "sketch.intersect", json!({"refs": [{"body": "Part"}]})); + let inspect = run(&mut s, "sketch.inspect", json!({})); + let state = s.model.state(); + let sk = &state.sketch(sketch).unwrap().sketch; + let pos = |i: usize| sk.points[i].pos; + let arcs: Vec = sk + .curves + .iter() + .filter_map(|c| match c.kind { + CurveKind::Arc { c, a, .. } => Some(pos(c).dist(pos(a))), + _ => None, + }) + .collect(); + assert_eq!(arcs.len(), 4, "{arcs:?}"); + assert!(arcs.iter().all(|r| (r - 2.).abs() < 5e-3), "{arcs:?}"); + // Square less the corners' (4 - pi) r^2 and four trapezoid grooves (142 + 124) / 2 * 6. + assert_eq!(inspect["profiles"].as_array().map(Vec::len), Some(1), "one closed outline"); + let area = inspect["profiles"][0]["area_mm2"].as_f64().unwrap(); + let expected = 150. * 150. - (4. - std::f64::consts::PI) * 4. - 4. * 798.; + assert!((area - expected).abs() < 0.5, "{area} vs {expected}"); +} +#[test] fn a_rebuilt_projection_keeps_user_constraints_without_a_warning() { for dimensioned in [false, true] { let mut s = Session::default();