Wave 470/509: Modify history tests: shell, offset and thicken are one test each through the public API, with the volumes, refusals and history the SMLib copies checked (and 3 more)

4 commits, squashed; the originals stay reachable from tag archive/merge-main-develop.

- 16bef1097 jyviko: Shell regression: the saddle-corner shell opened on the top box's side has its exact volume
- 699ddb6b3 jyviko: SMLib history test: every operand's order is the identity on its record's faces and edges
- ec421252d jyviko: Boolean history tests: the SMLib module's box-minus-sphere, box-minus-cylinder and box-union-box copies go; the top-level ones check more
- f87f22874 jyviko: Modify history tests: shell, offset and thicken are one test each through the public API, with the volumes, refusals and history the SMLib copies checked

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DtL5M41G8Nua7HvuFPZkmJ
This commit is contained in:
jyvikoandClaude Opus 5.5 committed 2026-10-31 08:57:45 -04:00
1 parent b9105a394e
commit c8ea4168b1
3 files changed
+49 -116

No files matched your search

+7
View File
@@ -46,6 +46,13 @@ fn shell_box_on_box_overhanging_saddle_corner() {
let mut s = box_on_box(2.5);
run(&mut s, "solid.shell", json!({"faces": [[7.5, 17.5, 38.75]], "thickness": 1.5}));
sound(&s);
// The bottom closed and the top box's left face x = 7.5 open, so the cavity in the top box
// runs out to it: [1.5, 23.5] × [1.5, 16] × [1.5, 33.5] in the lower box,
// [7.5, 21] × [1.5, 16] × [33.5, 41] over it and [7.5, 21] × [16, 18.5] × [36.5, 41] in the
// overhang, out of the solid's 25 × 17.5 × 35 + 15 × 20 × 7.5.
let want = 25.0 * 17.5 * 35.0 + 15.0 * 20.0 * 7.5 - 22.0 * 14.5 * 32.0 - 13.5 * 14.5 * 7.5 - 13.5 * 2.5 * 4.5;
let got = volume(&s);
assert!((got - want).abs() < 1e-6 * want, "shell volume {got}, want {want}");
}
/// The same saddle corner with the bottom open: every face round the corner moves, and the
+8 -35
View File
@@ -446,46 +446,19 @@ mod smlib {
crate::sphere(Vec3::new(10.0, 10.0, 10.0), 4.0).unwrap(),
crate::torus(Vec3::new(0.0, 0.0, 0.0), 10.0, 2.0).unwrap(),
];
// SMLib imports a record's faces and edges in the record's order, and the record is
// already canonical: SMLib's face and edge i are the record's i (the order is the
// identity, or empty, which says the same), with no edge split into pieces.
for (i, b) in bodies.iter().enumerate() {
let (_, order) = crate::native::smlib_body_ordered(b).unwrap();
assert!(order.is_some(), "body {i}");
let order = order.unwrap_or_else(|| panic!("body {i}: no order"));
let identity = |to: &[usize], n: usize| to.is_empty() || to.iter().copied().eq(0..n);
assert!(identity(&order.faces, b.face_count()), "body {i}: faces {:?}", order.faces);
assert!(identity(&order.edges, b.edge_count()), "body {i}: edges {:?}", order.edges);
assert!(order.pieces.is_empty(), "body {i}: {:?}", order.pieces);
}
}
#[test]
fn box_minus_sphere() {
let a = boxed(0.0, 0.0, 0.0, 10.0, 10.0, 10.0);
let b = crate::sphere(Vec3::new(10.0, 10.0, 10.0), 4.0).unwrap();
let r = through_smlib(&a, &b, BoolOp::Cut);
let h = verified(&r, &[&a, &b], 0.02);
// The three notched box faces, the three untouched, and the sphere's patches inside.
assert_eq!(changes(h)[..2].iter().sum::<usize>() + changes(h)[2], h.faces.len(), "{}", show(h));
assert!(
meets(h).iter().all(|(x, y)| matches!((x, y), (FaceOrigin::Face { operand: 0, .. }, FaceOrigin::Face { operand: 1, .. }))),
"{}",
show(h)
);
}
#[test]
fn box_minus_cylinder() {
let a = boxed(0.0, 0.0, 0.0, 10.0, 10.0, 10.0);
let b = crate::cylinder(Vec3::new(5.0, 5.0, -1.0), Vec3::Z, 2.0, 12.0).unwrap();
let r = through_smlib(&a, &b, BoolOp::Cut);
let h = verified(&r, &[&a, &b], 0.01);
assert!(from(h, face(0, 0)).len() + from(h, face(0, 1)).len() >= 1, "{}", show(h));
}
#[test]
fn box_union_box() {
let a = boxed(0.0, 0.0, 0.0, 10.0, 10.0, 10.0);
let b = boxed(5.0, 2.0, 2.0, 15.0, 8.0, 8.0);
let r = through_smlib(&a, &b, BoolOp::Union);
let h = verified(&r, &[&a, &b], 0.02);
assert_eq!(h.faces.len(), 11, "{}", show(h));
assert_eq!(meets(h).len(), 4, "{}", show(h));
}
/// Cubes sharing an edge, and cubes sharing a vertex: SMLib's union touches itself there;
/// it comes back as two closed shells, the shared edge and vertices split into one copy per
/// cube, each copy with its edge's history (verified against the geometry). The copies say
+34 -81
View File
@@ -55,6 +55,10 @@ fn face_at(b: &Body, p: Vec3) -> usize {
(0..b.face_count()).min_by(|x, y| to_face(&m, *x, p).total_cmp(&to_face(&m, *y, p))).unwrap()
}
fn volume(b: &Body) -> f64 {
crate::measure(b).unwrap().volume
}
fn cube() -> Body {
box_solid(Vec3::ZERO, Vec3::new(40.0, 30.0, 20.0)).unwrap()
}
@@ -227,6 +231,8 @@ fn shell_lines_the_walls_with_offsets() {
let b = cube();
let top = Vec3::new(20.0, 15.0, 20.0);
let r = crate::shell(&b, &[top], 2.0).unwrap();
// The cavity is 36 x 26 x 18 (the floor 2 thick, the top open).
assert!((volume(&r) - (24000.0 - 36.0 * 26.0 * 18.0)).abs() < 1e-3, "{}", volume(&r));
let h = verified(&r, &b, reach(2.0));
// Five inner walls, each an offset of the face it lines; the top is left as a rim.
let top = face_at(&b, top);
@@ -236,7 +242,7 @@ fn shell_lines_the_walls_with_offsets() {
assert_eq!(h.faces[walls[0]].change, Change::Generated);
}
assert!(with(h, &[FaceOrigin::Offset { operand: 0, face: top }]).is_empty());
assert_eq!(changes(h), [0, 6, 0, 0, 5]);
assert_eq!(changes(h), [0, 6, 0, 0, 5], "{h:?}");
}
#[test]
@@ -306,10 +312,17 @@ fn offset_moves_a_face() {
let b = ell();
let top = Vec3::new(5.0, 5.0, 20.0);
let r = crate::offset_faces(&b, &[top], 3.0).unwrap();
// The L's plan is 40 x 15 + 15 x 15 = 825; 23 high.
assert!((volume(&r) - 825.0 * 23.0).abs() < 1e-3, "{}", volume(&r));
let h = verified(&r, &b, Reach { made: 0.0, moved: 3.0 * 1.1 });
assert_eq!(h.faces.len(), b.face_count());
assert_eq!(with(h, &[face(face_at(&b, top))]).len(), 1);
let moved = with(h, &[face(face_at(&b, top))]);
assert_eq!(moved.len(), 1);
assert_eq!(h.faces[moved[0]].change, Change::Modified);
assert!(h.edges.iter().all(|e| matches!(e.origins.as_slice(), [EdgeOrigin::Edge { .. }])));
// Into the body by its whole height: nothing is left behind the face.
let e = crate::offset_faces(&b, &[top], -20.0).unwrap_err();
assert!(e.to_string().contains("no room"), "{e}");
}
#[test]
@@ -403,10 +416,24 @@ fn surfaces_keep_their_faces() {
fn thicken_offsets_the_surface() {
let s = crate::patch_region(&Plane::XY, &Region2 { outer: square(0.0, 0.0, 10.0, 10.0), holes: vec![] }).unwrap();
let t = crate::thicken(&s, 2.0, false).unwrap();
assert!((volume(&t) - 200.0).abs() < 1e-6, "{}", volume(&t));
// Along the sheet's normal (+Z).
let m = t.mesh(&crate::MeshTolerance::chord(TOL)).unwrap();
let (lo, hi) = m.positions.iter().fold((f64::MAX, f64::MIN), |(lo, hi), p| (lo.min(p.z), hi.max(p.z)));
assert!(lo.abs() < 1e-9 && (hi - 2.0).abs() < 1e-9, "z {lo}..{hi}");
let h = verified(&t, &s, reach(2.0));
assert_eq!(with(h, &[face(0)]).len(), 1);
assert_eq!(with(h, &[FaceOrigin::Offset { operand: 0, face: 0 }]).len(), 1);
assert_eq!(blends(h).len(), 4);
assert_eq!(with(h, &[face(0)]).len(), 1, "{h:?}");
assert_eq!(with(h, &[FaceOrigin::Offset { operand: 0, face: 0 }]).len(), 1, "{h:?}");
assert_eq!(blends(h).len(), 4, "{h:?}");
let both = crate::thicken(&s, 2.0, true).unwrap();
let m = both.mesh(&crate::MeshTolerance::chord(TOL)).unwrap();
let (lo, hi) = m.positions.iter().fold((f64::MAX, f64::MIN), |(lo, hi), p| (lo.min(p.z), hi.max(p.z)));
assert!((lo + 1.0).abs() < 1e-9 && (hi - 1.0).abs() < 1e-9, "z {lo}..{hi}");
let h = verified(&both, &s, reach(1.0));
assert_eq!(with(h, &[FaceOrigin::Offset { operand: 0, face: 0 }]).len(), 2, "{h:?}");
assert_eq!(blends(h).len(), 4, "{h:?}");
let against = crate::thicken(&s, -2.0, false).unwrap();
assert!((volume(&against) - 200.0).abs() < 1e-6);
}
#[test]
@@ -494,44 +521,13 @@ fn chamfer_after_box_cuts() {
}
}
/// Shell, offset faces and thicken through SMLib (`crate::offset_backend`), their histories
/// checked against the geometry as truck's are, and their numbers against the analytic ones.
/// Shell, offset faces and draft straight through `crate::offset_backend`: refusals, and their
/// histories checked against the geometry and their numbers against the analytic ones.
#[cfg(feature = "smlib")]
mod smlib {
use super::*;
use crate::offset_backend;
fn volume(b: &Body) -> f64 {
crate::measure(b).unwrap().volume
}
#[test]
fn shell_lines_the_walls_with_offsets() {
let b = cube();
let top = Vec3::new(20.0, 15.0, 20.0);
let r = offset_backend::shell(&b, &[top], 2.0).unwrap();
// The cavity is 36 x 26 x 18 (the floor 2 thick, the top open).
assert!((volume(&r) - (24000.0 - 36.0 * 26.0 * 18.0)).abs() < 1e-3, "{}", volume(&r));
let h = verified(&r, &b, reach(2.0));
let top = face_at(&b, top);
for f in (0..6).filter(|f| *f != top) {
let walls = with(h, &[FaceOrigin::Offset { operand: 0, face: f }]);
assert_eq!(walls.len(), 1, "{h:?}");
assert_eq!(h.faces[walls[0]].change, Change::Generated);
}
assert!(with(h, &[FaceOrigin::Offset { operand: 0, face: top }]).is_empty());
assert_eq!(changes(h), [0, 6, 0, 0, 5], "{h:?}");
}
#[test]
fn shell_of_a_body_that_is_not_convex() {
let b = ell();
let r = offset_backend::shell(&b, &[Vec3::new(5.0, 5.0, 20.0)], 2.0).unwrap();
let h = verified(&r, &b, reach(2.0 * 1.5));
let offsets = h.faces.iter().filter(|f| matches!(f.origins.as_slice(), [FaceOrigin::Offset { .. }])).count();
assert_eq!(offsets, 7, "{h:?}");
}
/// tangency-labs/solidcore#380: a closed shell whose wall leaves no room inside the body is
/// refused before SMLib's offset sees it, by the body's own inradius (the L's legs are 15
/// wide, the largest ball fits at the inner corner: 15 * sqrt(2) / (1 + sqrt(2)) = 8.79),
@@ -573,25 +569,6 @@ mod smlib {
assert!(e.contains("the 1.5 mm walls would meet along a line"), "{e}");
}
#[test]
fn offset_moves_a_face() {
let b = ell();
let top = Vec3::new(5.0, 5.0, 20.0);
let healed = crate::boolean_record::healed(&b).unwrap();
let chosen = [face_at(&healed, top)];
let r = offset_backend::offset_faces(&healed, &chosen, 3.0).unwrap();
// The L's plan is 40 x 15 + 15 x 15 = 825; 23 high.
assert!((volume(&r) - 825.0 * 23.0).abs() < 1e-3, "{}", volume(&r));
let h = verified(&r, &healed, Reach { made: 0.0, moved: 3.0 * 1.1 });
assert_eq!(h.faces.len(), healed.face_count());
let moved = with(h, &[face(chosen[0])]);
assert_eq!(moved.len(), 1);
assert_eq!(h.faces[moved[0]].change, Change::Modified);
// Into the body by its whole height: nothing is left behind the face.
let e = offset_backend::offset_faces(&healed, &chosen, -20.0).unwrap_err();
assert!(e.to_string().contains("no room"), "{e}");
}
#[test]
fn draft_tilts_a_side_and_keeps_its_name() {
let b = cube();
@@ -616,28 +593,4 @@ mod smlib {
let e = offset_backend::draft(&b, &[Vec3::new(20.0, 15.0, 20.0)], &Plane::XY, Vec3::Z, 5.0 * deg).unwrap_err();
assert!(e.to_string().contains("not supported yet"), "{e}");
}
#[test]
fn thicken_offsets_the_surface() {
let s = crate::patch_region(&Plane::XY, &Region2 { outer: square(0.0, 0.0, 10.0, 10.0), holes: vec![] }).unwrap();
let t = offset_backend::thicken(&s, 2.0, false).unwrap();
assert!((volume(&t) - 200.0).abs() < 1e-6, "{}", volume(&t));
// Along the sheet's normal (+Z).
let m = t.mesh(&crate::MeshTolerance::chord(TOL)).unwrap();
let (lo, hi) = m.positions.iter().fold((f64::MAX, f64::MIN), |(lo, hi), p| (lo.min(p.z), hi.max(p.z)));
assert!(lo.abs() < 1e-9 && (hi - 2.0).abs() < 1e-9, "z {lo}..{hi}");
let h = verified(&t, &s, reach(2.0));
assert_eq!(with(h, &[face(0)]).len(), 1, "{h:?}");
assert_eq!(with(h, &[FaceOrigin::Offset { operand: 0, face: 0 }]).len(), 1, "{h:?}");
assert_eq!(blends(h).len(), 4, "{h:?}");
let both = offset_backend::thicken(&s, 2.0, true).unwrap();
let m = both.mesh(&crate::MeshTolerance::chord(TOL)).unwrap();
let (lo, hi) = m.positions.iter().fold((f64::MAX, f64::MIN), |(lo, hi), p| (lo.min(p.z), hi.max(p.z)));
assert!((lo + 1.0).abs() < 1e-9 && (hi - 1.0).abs() < 1e-9, "z {lo}..{hi}");
let h = verified(&both, &s, reach(1.0));
assert_eq!(with(h, &[FaceOrigin::Offset { operand: 0, face: 0 }]).len(), 2, "{h:?}");
assert_eq!(blends(h).len(), 4, "{h:?}");
let against = offset_backend::thicken(&s, -2.0, false).unwrap();
assert!((volume(&against) - 200.0).abs() < 1e-6);
}
}