Tapped holes: read only the bodies along the drill line for the wall (#10227)

A tapped hole looked for the cylindrical wall its marking lies on in
every face of every body of the design, measuring each face over all of
its body's triangles. A body is now passed over when the drill line,
widened by the hole's radius and a margin, misses its box (from the
mesh it keeps, which the wall's triangles are part of): no face there
can be the wall, so the marking stays the same.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
kaltenbrunnermarkus
2026-11-02 18:13:12 +00:00
committed by GitHub
parent 686056e4de
commit ca4796921f
3 changed files with 67 additions and 1 deletions
+10
View File
@@ -4792,6 +4792,16 @@ fn parallel_tapped_wall(st: &ModelState, entry: Vec3, inward: Vec3, radius: f64)
let tol = (radius * 1e-6).max(1e-6);
let mut best: Option<(f64, Vec3)> = None;
for body in &st.bodies {
// A wall found lies on the line through `entry` along `inward`, give or take its radius
// (and the slant its axis may have off `inward` over the body's distance), and its
// triangles are among the body's mesh: a body whose box that line misses by more holds
// none, and its faces are not read one by one (#10227).
let far = more::mesh_box(body).map_or(f64::INFINITY, |b| (b.min - entry).len().max((b.max - entry).len()) + b.diagonal());
if far.is_finite() && more::line_beyond_reach(body, entry, inward, radius * 1.01 + tol + 1e-3 + 2e-4 * far) {
continue;
}
#[cfg(test)]
cost_tests::count(|c| c.tapped_wall += 1);
let mesh = body.mesh();
for face in 0..body.body.face_count() {
let Some(c) = kernel::cylinder_face(&body.body, &mesh, face) else { continue };
+36 -1
View File
@@ -17,7 +17,8 @@ use crate::*;
/// Work counted on this thread: bodies moved, STEP texts digested, joint faces and bodies
/// measured, bodies searched for by name, features searched for by id, bodies a cut (or
/// intersect) ran its booleans on, and bodies searched for the cylinder a tap marking lies on.
/// intersect) ran its booleans on, bodies searched for the cylinder a tap marking lies on, and
/// bodies whose faces a tapped hole read for its wall.
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub(super) struct Counts {
pub moved: usize,
@@ -28,6 +29,7 @@ pub(super) struct Counts {
pub feature_searches: usize,
pub cut: usize,
pub cylinder_search: usize,
pub tapped_wall: usize,
}
thread_local! {
@@ -41,6 +43,7 @@ thread_local! {
feature_searches: 0,
cut: 0,
cylinder_search: 0,
tapped_wall: 0,
})
};
}
@@ -1297,6 +1300,7 @@ fn a_tap_marking_searches_only_the_bodies_near_it() {
};
let (work, threads) = marking_work(&mut doc, hole);
assert_eq!(work.cylinder_search, 1, "only the plate is searched");
assert_eq!(work.tapped_wall, 1, "only the plate's faces are read for the wall");
assert_eq!(threads.len(), 1);
assert_eq!(threads[0].body, "Plate");
assert!(threads[0].internal && (threads[0].radius - 2.5).abs() < 1e-6);
@@ -1375,3 +1379,34 @@ fn a_cut_leaves_sheets_it_cannot_reach_as_they_were() {
assert_eq!(work.kept, sheet_bodies(&work.model), "every sheet is left as it was");
assert!(volume(&work.model, "Plate") < 43_200.0 - 300.0, "and the plate is cut");
}
/// A tapped hole reads for its wall the faces of the bodies its drill line comes near: the plate
/// it is drilled in, a block far below on the same line, and one whose side lies a radius off the
/// line; not a block beside it. The marking stays in the plate's hole.
#[test]
fn a_tapped_hole_reads_the_bodies_along_its_drill_line() {
let mut doc = Document::new("line");
block(&mut doc, "Plate", Vec3::ZERO, [60.0, 60.0, 12.0]);
block(&mut doc, "Below", Vec3::new(20.0, 20.0, -150.0), [20.0, 20.0, 20.0]);
block(&mut doc, "Grazing", Vec3::new(32.5, 20.0, -60.0), [20.0, 20.0, 20.0]);
block(&mut doc, "Beside", Vec3::new(50.0, 20.0, -60.0), [20.0, 20.0, 20.0]);
let hole = FeatureKind::Hole {
position: FacePick(Vec3::new(30.0, 30.0, 12.0)),
at: None,
direction: Dir(-Vec3::Z),
diameter: "5".into(),
depth: Some("10".into()),
hole: HoleKind::default(),
points: None,
thread: Some("M6".into()),
thread_depth: None,
handedness: ThreadHandedness::Right,
to: None,
references: Vec::new(),
};
let (work, threads) = marking_work(&mut doc, hole);
assert_eq!(work.tapped_wall, 3, "Plate, Below and Grazing are read");
assert_eq!(threads.len(), 1);
assert_eq!(threads[0].body, "Plate");
assert!(threads[0].internal && (threads[0].radius - 2.5).abs() < 1e-6);
}
+21
View File
@@ -1601,6 +1601,27 @@ pub(super) fn beyond_cylinder_reach(mb: &ModelBody, p: Vec3) -> bool {
off.len() > reach
}
/// Whether the line through `at` along `dir` is known to pass farther than `reach` from the box
/// of `mb` ([`mesh_box`]) everywhere, and so from every point of the mesh the body keeps. Unknown
/// is never.
pub(super) fn line_beyond_reach(mb: &ModelBody, at: Vec3, dir: Vec3, reach: f64) -> bool {
let Some(b) = mesh_box(mb) else { return false };
let b = b.inflated(reach);
let (mut lo, mut hi) = (f64::NEG_INFINITY, f64::INFINITY);
for (a, d, min, max) in [(at.x, dir.x, b.min.x, b.max.x), (at.y, dir.y, b.min.y, b.max.y), (at.z, dir.z, b.min.z, b.max.z)] {
if d == 0.0 {
if a < min || a > max {
return true;
}
continue;
}
let (t0, t1) = ((min - a) / d, (max - a) / d);
lo = lo.max(t0.min(t1));
hi = hi.min(t0.max(t1));
}
lo > hi
}
/// Whether two boxes are known to be apart (an unknown box is never apart).
pub(super) fn boxes_apart(a: &Option<Aabb3>, b: &Option<Aabb3>) -> bool {
let (Some(a), Some(b)) = (a, b) else { return false };