From 7c481d281fc9753e88aeb11f26b430db43af8152 Mon Sep 17 00:00:00 2001 From: jyviko <2501648+jyviko@users.noreply.github.com> Date: Mon, 26 Oct 2026 05:04:57 -0400 Subject: [PATCH] Wave 239/509: engine: a shell that opens no face makes a closed hollow body (and 3 more) 4 commits, squashed; the originals stay reachable from tag archive/merge-main-develop. - 48abbbcc1 jyviko: kernel: a vertex a face's loops pass twice is one point of its (u, v) - 1df330c79 jyviko: engine: a shell that opens no face makes a closed hollow body - 5aeff43f8 jyviko: smlib: a horn or spindle torus face comes out as its NURBS form - bd4e1926a jyviko: kernel-cases: 2928's base extrudes the ring it describes Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01DtL5M41G8Nua7HvuFPZkmJ --- crates/doc/src/eval.rs | 11 ++++++-- crates/engine/src/cmd/features.rs | 8 ++++-- crates/engine/tests/shell_regressions.rs | 19 ++++++++++++++ crates/kernel/src/tess/mod.rs | 25 ++++++++++++++++--- crates/kernel/src/tess/tests.rs | 13 ++++++++++ crates/smlib/src/export.rs | 7 ++++++ crates/smlib/src/sweeps_tests.rs | 18 +++++++++++++ .../recipe.json | 8 ++++++ .../expected.json | 1 + 9 files changed, 103 insertions(+), 7 deletions(-) diff --git a/crates/doc/src/eval.rs b/crates/doc/src/eval.rs index b602b55c0..479a32b3a 100644 --- a/crates/doc/src/eval.rs +++ b/crates/doc/src/eval.rs @@ -6785,7 +6785,12 @@ fn eval_feature(doc: &Document, vals: &BTreeMap, f: &Feature, st: } FeatureKind::Shell { faces, thickness, body, direction, tangent_chain } => { let t = val(vals, thickness, Kind::Length)?; - let i = body_at(st, body, &crate::plain(faces))?; + // No face opened (a closed hollow body) picks no body: the one there is, or the named one. + let i = match (faces.is_empty(), body, st.bodies.len()) { + (true, None, 1) => 0, + (true, None, _) => return Err(DocError::Invalid("a shell that opens no face needs the body named".into())), + _ => body_at(st, body, &crate::plain(faces))?, + }; let Some(mb) = st.bodies.get(i).cloned() else { return Err(DocError::Invalid("body".into())) }; let picks = crate::plain(faces); let open = if *tangent_chain { @@ -6823,7 +6828,9 @@ fn eval_feature(doc: &Document, vals: &BTreeMap, f: &Feature, st: // The cavity's faces are the shell's inner walls, named after the faces they offset. let inner = mb.before_as(crate::lineage::Operand::Inner(mb.name.clone())); let cavity = if inn > 0.0 { Traced::step(kernel::offset_faces(&mb.body, &walls, -inn)?, &[&inner]) } else { inner }; - let cavity = Traced::step(kernel::offset_faces(&cavity.body, &open, 2.0 * t + 1.0)?, &[&cavity]); + // The open faces pushed out of the way (none: the cavity stays sealed inside). + let cavity = + if open.is_empty() { cavity } else { Traced::step(kernel::offset_faces(&cavity.body, &open, 2.0 * t + 1.0)?, &[&cavity]) }; let cut = kernel::boolean(&outer.body, &cavity.body, BoolOp::Cut)? .ok_or_else(|| DocError::Invalid("the shell removed everything".into()))?; (cut, vec![outer, cavity]) diff --git a/crates/engine/src/cmd/features.rs b/crates/engine/src/cmd/features.rs index f4a3b1e8c..587599bc5 100644 --- a/crates/engine/src/cmd/features.rs +++ b/crates/engine/src/cmd/features.rs @@ -97,7 +97,7 @@ pub static COMMANDS: &[CommandSpec] = &[ CommandSpec::new("solid.shell", "Shell", shell) .at("SOLID", "MODIFY") .icon("shell") - .params("faces: [[x,y,z] points on the faces to remove, or face names from model.faces]; thickness: expr; direction?: inside|outside|both; tangent_chain?: bool (also open faces joined smoothly to the picked ones); body?"), + .params("faces: [[x,y,z] points on the faces to remove, or face names from model.faces; none: a closed hollow body]; thickness: expr; direction?: inside|outside|both; tangent_chain?: bool (also open faces joined smoothly to the picked ones); body? (needed with no faces when there are several bodies)"), CommandSpec::new("solid.draft", "Draft", draft) .at("SOLID", "MODIFY") .icon("draft") @@ -2649,7 +2649,11 @@ fn face_points(s: &Session, p: &Value, cmd: &str) -> Result> { fn shell(s: &mut Session, p: &Value) -> Result { let cmd = "solid.shell"; - let faces = face_points(s, p, cmd)?; + // No face opened: a closed hollow body, its void sealed inside. + let faces = match p.get("faces").and_then(Value::as_array) { + Some(a) if a.is_empty() => Vec::new(), + _ => face_points(s, p, cmd)?, + }; let thickness = req_expr(cmd, p, "thickness")?; check_expr(s, &thickness, Kind::Length, cmd, "thickness")?; let direction = str_(p, "direction").map(str::to_ascii_lowercase).unwrap_or_default(); diff --git a/crates/engine/tests/shell_regressions.rs b/crates/engine/tests/shell_regressions.rs index 5243877ff..b1f3f1e4b 100644 --- a/crates/engine/tests/shell_regressions.rs +++ b/crates/engine/tests/shell_regressions.rs @@ -86,3 +86,22 @@ fn sound(s: &Session) { assert!(b.body.validity().is_empty(), "{:?}", b.body.validity()); } } + +/// A shell that opens no face (rig shell/4009): a closed hollow body, the void sealed inside. A +/// 40 × 30 × 12.5 box with a 2.5 wall inside leaves a 35 × 25 × 7.5 void; grown 2.5 outside, the +/// walls are a 45 × 35 × 17.5 box less the original. +#[test] +fn a_shell_that_opens_no_face_seals_its_void() { + for (direction, want, shells) in [("inside", 15000.0 - 35.0 * 25.0 * 7.5, 2), ("outside", 45.0 * 35.0 * 17.5 - 15000.0, 2)] { + let mut s = Session::default(); + run(&mut s, "solid.box", json!({"length": 40.0, "width": 30.0, "height": 12.5})); + run(&mut s, "solid.shell", json!({"faces": [], "thickness": 2.5, "direction": direction})); + let errors: Vec<_> = s.model.results.iter().filter_map(|r| r.error.clone()).collect(); + assert!(errors.is_empty(), "{direction}: {errors:?}"); + let st = s.model.state(); + assert_eq!(st.bodies.len(), 1, "{direction}: one body"); + assert_eq!(st.bodies[0].body.shell_count(), shells, "{direction}: an outer and an inner shell"); + let got = volume(&s); + assert!((got - want).abs() < 1e-6 * want, "{direction}: volume {got}, want {want}"); + } +} diff --git a/crates/kernel/src/tess/mod.rs b/crates/kernel/src/tess/mod.rs index db16a5922..07933b789 100644 --- a/crates/kernel/src/tess/mod.rs +++ b/crates/kernel/src/tess/mod.rs @@ -205,9 +205,14 @@ pub(crate) fn plan(b: &brep::Brep, tol: f64, turn: Option) -> Result /// its loop would wind round the surface). Each loop then starts at a node off every pole whose /// predecessor is off them too, so the step from its last node to its first, which /// [`seam::drift`] takes as the nearest copy, never crosses a pole. A vertex loop (a pole) -/// bounds no area and has no nodes of its own. A pcurve that does not cover its edge's interval, or puts a -/// node farther off the edge than the tolerances allow, is an error naming the face and edge: -/// the record is wrong there. +/// bounds no area and has no nodes of its own. Where the face's loops pass a vertex more than once +/// (two holes touching at a point, a loop through another's corner), the pcurves of the edges from +/// it give its parameters apart by their rounding, and two nodes 1e-14 apart put crossing +/// constraints into the triangulation: a pass whose parameters agree with the first pass's to +/// that rounding (1e-9 relative) takes the first's. Farther apart they are two places of the +/// surface (a seam's two sides, a closed spline's ends). A pcurve that does not cover its edge's +/// interval, or puts a node farther off the edge than the tolerances allow, is an error naming +/// the face and edge: the record is wrong there. fn boundary( b: &brep::Brep, fi: usize, @@ -220,6 +225,8 @@ fn boundary( let dom = uv::domain(s); let fail = |e: u32, why: String| unsupported(format!("face {fi} ({}): edge {e}: {why}", kind(&face.surface))); let mut out = Boundary { loops: Vec::with_capacity(face.loops.len()), segments: Vec::with_capacity(face.loops.len()) }; + // Each vertex's parameters, from the first edge use of the face to start there. + let mut at_vertex: std::collections::HashMap = std::collections::HashMap::new(); for l in &face.loops { let Loop::Edges { edges } = l else { continue }; let (mut pts, mut uvs): (Vec, Vec<[f64; 2]>) = (Vec::new(), Vec::new()); @@ -265,6 +272,18 @@ fn boundary( q[0] += shift[0]; q[1] += shift[1]; } + if let (Some(&v), Some(q)) = (edge.vertices.get(usize::from(!oe.forward)), eq.first_mut()) { + match at_vertex.get(&v) { + Some(first) => { + if (0..2).all(|d| (first[d] - q[d]).abs() <= 1e-9 * first[d].abs().max(q[d].abs()).max(1.0)) { + *q = *first; + } + } + None => { + at_vertex.insert(v, *q); + } + } + } end = eq.last().copied(); ep.pop(); eq.pop(); diff --git a/crates/kernel/src/tess/tests.rs b/crates/kernel/src/tess/tests.rs index 00af3b78d..64d48602d 100644 --- a/crates/kernel/src/tess/tests.rs +++ b/crates/kernel/src/tess/tests.rs @@ -128,6 +128,19 @@ fn holes_and_trimmed_faces_are_watertight() { assert!((a - b).abs() < 0.01 * b, "cross hole volume {a} vs {b}"); } +/// Through holes in pairs whose circles touch at one point (rig booleans/307): the plate's faces +/// have one loop round each pair, through their common vertex twice. Both passes are one point of +/// the face's (u, v), not two nodes the pcurves put 1e-14 apart, whose constraints crossed +/// ("boundary crosses itself"). +#[test] +fn holes_touching_at_a_point_are_watertight() { + let mut body = ok(crate::box_solid(Vec3::new(-50.0, -50.0, 0.0), Vec3::new(50.0, 50.0, 5.0))); + for (x, y) in [(25.0, 0.0), (-25.0, 0.0), (0.0, 25.0), (0.0, -25.0), (15.0, 0.0), (-15.0, 0.0), (0.0, 15.0), (0.0, -15.0)] { + body = cut(&body, &ok(crate::cylinder(Vec3::new(x, y, -1.0), Vec3::Z, 5.0, 7.0))); + } + check("holes touching at a point", &body, 0.01, 10000.0 * 5.0 - 8.0 * PI * 25.0 * 5.0); +} + #[test] fn faces_and_edges_keep_the_body_order() { let body = ok(crate::cylinder(Vec3::ZERO, Vec3::Z, 2.0, 5.0)); diff --git a/crates/smlib/src/export.rs b/crates/smlib/src/export.rs index 8f02a6806..62fa38fb5 100644 --- a/crates/smlib/src/export.rs +++ b/crates/smlib/src/export.rs @@ -404,6 +404,13 @@ fn surfaces(flat: View, n_faces: usize) -> Res minor_radius) => (n, None), + other => other, + }; out.push((surface, form)); } Ok(out) diff --git a/crates/smlib/src/sweeps_tests.rs b/crates/smlib/src/sweeps_tests.rs index abf1fda68..5508d8088 100644 --- a/crates/smlib/src/sweeps_tests.rs +++ b/crates/smlib/src/sweeps_tests.rs @@ -49,6 +49,24 @@ fn revolutions_whole_and_partial() { assert_close(solid_volume(&b, "quarter ring"), PI / 2.0 * 7.0 * 4.0, 1e-6, "quarter ring"); } +/// A half disc of radius 14 centred 14 off the axis, its rim outward, three quarters of a turn +/// (rig sweeps/4007): a horn torus, which SMLib gives a major radius a rounding below its minor. +/// The record's torus is a ring torus, so the face comes out as its NURBS form, unlabelled, and +/// the record validates. Pappus: 3/4 turn · 2π (14 + 4·14 / 3π) · π 14² / 2. +#[test] +fn a_horn_torus_comes_out_as_its_nurbs() { + let half = vec![ + Curve::Arc { center: [14.0, 0.0, 0.0], axis: [0.0, -1.0, 0.0], reference: [1.0, 0.0, 0.0], radius: 14.0, start: -PI / 2.0, end: PI / 2.0 }, + Curve::Line { start: [14.0, 0.0, 14.0], end: [14.0, 0.0, -14.0] }, + ]; + let b = Brep::revolve(&half, [0.0; 3], [0.0, 0.0, 1.0], 1.5 * PI, true).unwrap(); + let want = 1.5 * PI * (14.0 + 56.0 / (3.0 * PI)) * PI * 98.0; + assert_close(solid_volume(&b, "horn torus"), want, 1e-6, "horn torus"); + let record = b.to_native().unwrap(); + record.validate().unwrap(); + assert!(record.faces.iter().all(|f| !matches!(f.surface, solidcraft_geom::brep::Surface::Torus { .. })), "a torus label on a horn torus"); +} + #[test] fn sweeps_lofts_and_screws() { let disc = [circle([5.0, 0.0, 0.0], 2.0)]; diff --git a/tests/kernel-cases/booleans/2928-join-cap-touching-lips-with-offset-walls/recipe.json b/tests/kernel-cases/booleans/2928-join-cap-touching-lips-with-offset-walls/recipe.json index dff6c0d75..defab27cd 100644 --- a/tests/kernel-cases/booleans/2928-join-cap-touching-lips-with-offset-walls/recipe.json +++ b/tests/kernel-cases/booleans/2928-join-cap-touching-lips-with-offset-walls/recipe.json @@ -131,6 +131,14 @@ "command": "solid.extrude", "params": { "sketch": "Base", + "profiles": [ + { + "point": [ + 4, + 0 + ] + } + ], "distance": 2, "operation": "new", "body_name": "Base" diff --git a/tests/kernel-cases/shell/4009-closed-shell-internal-void/expected.json b/tests/kernel-cases/shell/4009-closed-shell-internal-void/expected.json index 33c5e659f..7c5ac82d3 100644 --- a/tests/kernel-cases/shell/4009-closed-shell-internal-void/expected.json +++ b/tests/kernel-cases/shell/4009-closed-shell-internal-void/expected.json @@ -6,6 +6,7 @@ "source": "analytic", "method": "outer box 40x30x12.5, void = inward offset box 35x25x7.5 (2.5 wall every side). V=15000-6562.5=8437.5; area=outer 2(1200+500+375)=4150 + void 2(875+187.5+262.5)... computed in python; faces 6+6=12; one body with an outer and an inner shell; centroid (20,15,6.25) by symmetry", "body_count": 1, + "shells": 2, "volume_mm3": 8437.5, "area_mm2": 6800.0, "faces": 12,