A cut ending in a face of its target no longer leaves the hole closed by a skin (#2827)
A cut whose tool ends exactly on a face of the target (a hole cut from a pocket's floor up to the plate's top face) could come out of the general boolean with the target's face whole over the hole and the tool's end face under it: a skin of no thickness that keeps the hole closed. No volume shows it and the sampled membership checks see the hole either way, so the result was kept. The result check now refuses a body with a planar face lying back to back on another of its own planar faces with nothing behind part of it (`coplanar::has_skin`), and the retries take the cut. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
926a7353a3
commit
9e15995a74
4 files changed
+3012
-2
No files matched your search
@@ -997,3 +997,38 @@ fn prism_edge_in_a_round_cornered_slab_end_face_joins() {
|
||||
assert!((got - (prism + slab - shared)).abs() < 1e-3 * got, "r {r}: {got} vs {}", prism + slab - shared);
|
||||
}
|
||||
}
|
||||
|
||||
/// A cut from a face up to the plate's top face, its tool's end lying in that face: the boolean
|
||||
/// of the bodies as they lie left the hole closed by a skin of no thickness (the plate's top face
|
||||
/// whole over the hole, the tool's end face under it), which no volume shows and which was kept.
|
||||
/// The hole is open, and the cut takes the whole tool: the circle of radius 3.04 the two
|
||||
/// profiles make, from the barrel cut's floor at z 1.6 up to the plate's top at z 2.8.
|
||||
#[test]
|
||||
fn cut_up_to_the_plate_top_face_opens_the_hole() {
|
||||
let mut script: Value = serde_json::from_str(include_str!("../../../examples/regressions/cut_up_to_face_leaves_skin.json")).unwrap();
|
||||
let s = replay_value(&script);
|
||||
assert!(s.model.results.iter().all(|r| r.error.is_none()), "{:?}", s.model.results);
|
||||
let state = s.model.state();
|
||||
let body = &state.body("Body7").unwrap().body;
|
||||
assert!(body.validity().is_empty(), "{:?}", body.validity());
|
||||
let skin: Vec<f64> = body
|
||||
.faces(1e-4)
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.filter(|f| f.plane_normal.is_some_and(|n| n.z < -0.999) && (f.centroid.z - 2.8).abs() < 1e-6)
|
||||
.map(|f| f.area)
|
||||
.collect();
|
||||
assert!(skin.is_empty(), "faces at z 2.8 facing down, areas {skin:?} mm²");
|
||||
// The same design without the cut.
|
||||
script["commands"].as_array_mut().unwrap().pop();
|
||||
let before = replay_value(&script);
|
||||
let fine = |s: &Session| s.model.state().body("Body7").unwrap().body.tessellate(1e-5).unwrap().measure().volume;
|
||||
let (removed, want) = (fine(&before) - fine(&s), std::f64::consts::PI * 3.04 * 3.04 * 1.2);
|
||||
assert!((removed - want).abs() < 0.01, "removed {removed} mm³, want {want}");
|
||||
}
|
||||
|
||||
fn replay_value(script: &Value) -> Session {
|
||||
let mut s = Session::default();
|
||||
s.run_script(script).unwrap();
|
||||
s
|
||||
}
|
||||
@@ -999,6 +999,44 @@ pub(crate) fn faces_touch(a: &Body, b: &Body) -> bool {
|
||||
})
|
||||
}
|
||||
|
||||
/// Does `r` hold a skin of no thickness: a planar face lying on another of its planar faces that
|
||||
/// faces the other way, with no material behind part of it? A cut whose tool ends exactly on a
|
||||
/// face of the target can come out with the target's face whole over the hole and the tool's end
|
||||
/// face under it, closing the hole. No volume shows that, and points sampled off the surface see
|
||||
/// the hole either way. Faces back to back in one plane with material behind both (the top of a
|
||||
/// step beside the underside of an overhang) are not this. `mesh` is `r`'s mesh; what counts is
|
||||
/// an area of the faces with nothing behind it, so that the few triangles along an edge where the
|
||||
/// mesh of a curved neighbour cuts the corner don't.
|
||||
pub(crate) fn has_skin(r: &Body, mesh: &solidcraft_geom::Mesh) -> bool {
|
||||
let size = r.size();
|
||||
let tol = (size * 1e-7).max(1e-9) * 10.0;
|
||||
let p = planes(r);
|
||||
if p.len() > MAX_SKIN_FACES {
|
||||
return false;
|
||||
}
|
||||
let paired: HashMap<usize, Vec3> = p
|
||||
.iter()
|
||||
.filter(|(i, x)| p.iter().any(|(j, y)| i != j && x.n.dot(y.n) < -1.0 + 1e-9 && (x.d + y.d).abs() < tol))
|
||||
.map(|(i, x)| (*i, x.n))
|
||||
.collect();
|
||||
if paired.is_empty() {
|
||||
return false;
|
||||
}
|
||||
let inside = mesh.inside_index();
|
||||
let depth = (size * 1e-4).max(1e-6);
|
||||
let mut open = 0.0;
|
||||
for (t, face) in mesh.triangles.iter().zip(&mesh.tri_face).take(100_000) {
|
||||
let (Some(n), Some([a, b, c])) = (paired.get(&(*face as usize)), mesh.tri(t)) else { continue };
|
||||
if !inside.contains((a + b + c) / 3.0 - *n * depth) {
|
||||
open += (b - a).cross(c - a).len() * 0.5;
|
||||
}
|
||||
}
|
||||
open > (size * size * 1e-6).max(1e-9)
|
||||
}
|
||||
|
||||
/// The most planar faces [`has_skin`] pairs up (every pair is compared).
|
||||
const MAX_SKIN_FACES: usize = 2000;
|
||||
|
||||
/// The triangles of `tool`'s faces in the plane (`m`, `d`), `m` their outward normal, each with
|
||||
/// how far its face reaches past it sideways. A face bounded by straight edges is its
|
||||
/// triangles; they are drawn in by `skin`, so that faces of the other body lying against the
|
||||
|
||||
@@ -1295,7 +1295,8 @@ where
|
||||
// nothing to cut, so it returns both operands side by side (#396). Volume and point
|
||||
// sampling cannot see that; the shell grouping can. Only contact over an area counts
|
||||
// (bodies tangent along a line stay two lumps), and operands already like that, saved
|
||||
// before this was caught, stay joinable.
|
||||
// before this was caught, stay joinable. Nor can they see a skin of no thickness left over
|
||||
// a hole by a tool ending in a face of the target ([`crate::coplanar::has_skin`]).
|
||||
let unfused = |r: &Body| {
|
||||
op == BoolOp::Union
|
||||
&& r.shell_count() > 1
|
||||
@@ -1311,7 +1312,7 @@ where
|
||||
if !bounds {
|
||||
return (false, v);
|
||||
}
|
||||
if unfused(r) {
|
||||
if unfused(r) || crate::coplanar::has_skin(r, &mr) {
|
||||
return (false, v);
|
||||
}
|
||||
let consistent = match &meshes {
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user