Files
solidcraft/crates/kernel/src/regularization_protection_tests.rs
T
jyvikoandClaude Opus 5.5 e1b762c4bd Booleans and Shell keep the lines faces were split along on purpose
Split Face records its lines on the body (split_lines): heal and the
certified-planar regularizer keep the faces apart along them, and they
make the body regularization-protected. On SMLib the boolean, the n-way
union and Shell carried the protection over but dropped the lines, so a
body with an authored split lost its record after a Union with partial
contact (issue #674/#782's case), and a shelled one after Shell. Each
result now keeps its operands' lines, each line once
(Body::inherit_split_lines), as the old kernel's coplanar join did.

regularization_protection_tests: SMLib's shell makes no section strips,
so the painted cup no longer has more faces than the ordinary one. The
ordinary cup is the box's five kept faces, their five linings and the
rim: 11. A paint over a whole face authors no boundary inside it, so the
painted cup has the same 11 faces; the split side's line stays an edge on
the wall and its lining: 13. The test now asserts those counts exactly
(it asserted more than 11 for both, the old strip route's witness) and
that the split lines survive.

Fixes kernel issue_674_tests::partial_contact_retains_an_authored_split_away_from_the_contact
and body::regularization_protection_tests::stamped_shell_keeps_authored_painted_and_split_boundaries.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-29 23:17:46 -04:00

64 lines
3.6 KiB
Rust

use super::*;
use solidcraft_geom::Plane;
fn stamped_stock() -> Body {
crate::box_solid(Vec3::new(-20., -15., 0.), Vec3::new(20., 15., 24.)).unwrap().with_box_certificate(7).unwrap()
}
fn cup(stock: &Body) -> Body {
crate::shell(stock, &[Vec3::new(0., 0., 24.)], 1.).unwrap().with_shell_certificate(9).unwrap()
}
#[test]
fn stamped_shell_keeps_authored_painted_and_split_boundaries() {
let stock = stamped_stock();
let ordinary = cup(&stock);
assert!(!ordinary.regularization_protected);
let painted = stock.clone().with_paint(Some(Paint { opacity: 1., faces: vec![FacePaint { face: 0, color: [1., 0., 0.], opacity: 1. }] }));
let side = (0..stock.face_count()).find(|i| stock.planar_face(*i).is_some_and(|p| p.normal().dot(Vec3::X) > 0.999 && p.origin.x == 20.)).unwrap();
let split = crate::split_faces(&stock, &[side], &crate::SplitTool::Plane(Plane { origin: Vec3::new(0., 0., 8.), ..Plane::XY })).unwrap();
assert!(split.split_lines().is_some());
// SMLib's shell makes no section strips: the ordinary cup is the stock's five kept faces,
// their five linings and the rim (11). A paint over a whole face authors no boundary inside
// it, so the painted cup has those same faces; the split side's line stays an edge on both
// walls (13).
for (protected, faces) in [(painted, ordinary.face_count()), (split, ordinary.face_count() + 2)] {
let result = cup(&protected);
assert!(result.regularization_protected);
assert_eq!(result.face_count(), faces, "authored boundaries must survive Shell");
assert_eq!(result.split_lines(), protected.split_lines());
assert!(result.validity().is_empty());
let expected = 40. * 30. * 24. - 38. * 28. * 23.;
let mesh = result.mesh(&crate::MeshTolerance::chord(1e-5)).unwrap();
assert!((mesh.measure().volume - expected).abs() < 1e-6);
assert!(mesh.contains(Vec3::new(19.5, 0., 12.)));
assert!(!mesh.contains(Vec3::new(0., 0., 12.)));
let count = result.face_count();
assert_eq!(result.clone().regularize_certified_planar_faces().unwrap().face_count(), count);
let placed = crate::transform(&result, Vec3::new(30., -40., 7.), Vec3::ZERO, Vec3::Z, 0.3).unwrap();
assert!(placed.regularization_protected);
for lump in placed.lumps().unwrap() {
assert!(lump.regularization_protected);
}
let cleared = result.clone().with_paint(None).with_split_lines(None);
assert!(cleared.regularization_protected, "cleared appearance must not erase inherited boundary protection");
assert_eq!(cleared.regularize_certified_planar_faces().unwrap().face_count(), count);
}
}
#[test]
fn protection_is_identity_and_survives_tool_operand_and_compounds() {
let a = stamped_stock();
let protected = a.clone().with_paint(Some(Paint { opacity: 1., faces: vec![FacePaint { face: 0, color: [0., 1., 0.], opacity: 1. }] }));
let cleared = protected.with_paint(None);
assert!(!a.same(&cleared));
let tool = crate::box_solid(Vec3::new(-5., -5., 23.), Vec3::new(5., 5., 30.)).unwrap().inherit_regularization_protection(&cleared);
let cut = crate::boolean(&a, &tool, crate::BoolOp::Cut).unwrap().unwrap();
assert!(cut.regularization_protected);
let remote = crate::box_solid(Vec3::new(100., 0., 0.), Vec3::new(110., 10., 10.)).unwrap();
let joined = crate::ops::join_pieces(vec![cleared, remote]).unwrap().unwrap();
assert!(joined.regularization_protected);
assert_eq!(joined.lumps().unwrap().len(), 2);
assert!(joined.lumps().unwrap().iter().all(|body| body.regularization_protected));
}