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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DtL5M41G8Nua7HvuFPZkmJ
This commit is contained in:
jyviko
2026-10-26 05:04:57 -04:00
parent 2425f8b453
commit 7c481d281f
9 changed files with 103 additions and 7 deletions
+9 -2
View File
@@ -6785,7 +6785,12 @@ fn eval_feature(doc: &Document, vals: &BTreeMap<String, Value>, 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<String, Value>, 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])
+6 -2
View File
@@ -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<Vec<Vec3>> {
fn shell(s: &mut Session, p: &Value) -> Result<Value> {
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();
+19
View File
@@ -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}");
}
}
+22 -3
View File
@@ -205,9 +205,14 @@ pub(crate) fn plan(b: &brep::Brep, tol: f64, turn: Option<size::Turn>) -> 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<u32, [f64; 2]> = std::collections::HashMap::new();
for l in &face.loops {
let Loop::Edges { edges } = l else { continue };
let (mut pts, mut uvs): (Vec<Vec3>, 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();
+13
View File
@@ -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));
+7
View File
@@ -404,6 +404,13 @@ fn surfaces(flat: View, n_faces: usize) -> Res<Vec<(b::Surface, Option<b::Surfac
};
// A NURBS face's own block came first; a form follows the analytic face's canonical entry.
let form = if kind != SURFACE_NURBS && forms.get(f) == Some(&1) { Some(next_nurbs(&mut nurbs_at)?) } else { None };
// The record's torus is a ring torus. SMLib keeps horn and spindle tori too (a half disc
// revolved about a line through its rim's end, its tube touching the axis, the major
// radius a rounding below the minor): such a face is its NURBS form, unlabelled.
let (surface, form) = match (surface, form) {
(b::Surface::Torus { major_radius, minor_radius, .. }, Some(n)) if !(major_radius > minor_radius) => (n, None),
other => other,
};
out.push((surface, form));
}
Ok(out)
+18
View File
@@ -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)];
@@ -131,6 +131,14 @@
"command": "solid.extrude",
"params": {
"sketch": "Base",
"profiles": [
{
"point": [
4,
0
]
}
],
"distance": 2,
"operation": "new",
"body_name": "Base"
@@ -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,