SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Tapped holes: read only the bodies along the drill line for the wall (#10227)
kaltenbrunnermarkusca4796921f2c
diff --git a/crates/doc/src/eval.rs b/crates/doc/src/eval.rsindex ca37066ded..b274092259 100644--- a/crates/doc/src/eval.rs+++ b/crates/doc/src/eval.rs@@ -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 };diff --git a/crates/doc/src/eval_cost_tests.rs b/crates/doc/src/eval_cost_tests.rsindex 027bfd7bc4..3396f5f7f4 100644--- a/crates/doc/src/eval_cost_tests.rs+++ b/crates/doc/src/eval_cost_tests.rs@@ -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);+}diff --git a/crates/doc/src/eval_more.rs b/crates/doc/src/eval_more.rsindex 8a81b4f2bd..29c9fbbb95 100644--- a/crates/doc/src/eval_more.rs+++ b/crates/doc/src/eval_more.rs@@ -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 };