Sheet metal: a hole leaves sheet parts it cannot reach untouched (#10226)

A hole in a design with sheet metal first tried to bore every sheet of its
component, building each panel and running a boolean on it, and then
checked every sheet again to see whether the drill met it at all. For a
sheet far from the hole both only found nothing: with 50 sheet parts that
was most of a hole's time. Now a sheet whose box lies clear of the
drill's box is left out of both, with the same grown boxes the other
sheet cuts use, so a drill into a sheet's rim still bores it. A drill a
sheet would refuse whatever it meets (an invalid one, or one more bore
than a sheet may hold) is still put to every sheet as before.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
kaltenbrunnermarkus
2026-11-02 19:14:28 +00:00
committed by GitHub
parent 1721cb0a4c
commit 0d8eebbea6
4 changed files with 85 additions and 4 deletions
+9 -3
View File
@@ -4895,11 +4895,17 @@ fn sheet_hole_cut(
_ => done,
};
if done.is_empty() {
// A sheet whose box lies clear of the tool's cannot meet it (#10226).
let reach = more::body_box(tool);
let mut meets = false;
for sheet in &st.sheets {
if let Some(mb) = st.body(&sheet.body)
&& kernel::boolean(&mb.body, tool, BoolOp::Intersect)?.is_some()
{
let Some(mb) = st.body(&sheet.body) else { continue };
if more::boxes_apart(&more::mesh_box(mb), &reach) {
continue;
}
#[cfg(test)]
cost_tests::count(|c| c.cut += 1);
if kernel::boolean(&mb.body, tool, BoolOp::Intersect)?.is_some() {
meets = true;
break;
}
+49
View File
@@ -1360,6 +1360,15 @@ fn flat_sheet(doc: &mut Document, corner: Vec2, w: f64, h: f64) {
doc.add_feature(FeatureKind::SheetBase { sketch: SketchId(sketch), profiles: ProfileSel::All, rule: None, flip: false }, None).unwrap();
}
/// A hole of `diameter` at `position`, drilling along `direction` through all.
fn hole(position: Vec3, direction: Vec3, diameter: f64) -> FeatureKind {
serde_json::from_value(serde_json::json!({
"type": "hole", "position": [position.x, position.y, position.z], "direction": [direction.x, direction.y, direction.z],
"diameter": diameter.to_string(),
}))
.unwrap()
}
/// The sheet metal bodies of a model.
fn sheet_bodies(model: &Model) -> Vec<String> {
model.state().sheets.iter().map(|s| s.body.clone()).collect()
@@ -1410,3 +1419,43 @@ fn a_tapped_hole_reads_the_bodies_along_its_drill_line() {
assert_eq!(threads[0].body, "Plate");
assert!(threads[0].internal && (threads[0].radius - 2.5).abs() < 1e-6);
}
/// A hole leaves the sheets it cannot reach as they were, without drilling, checking or cutting
/// each one: in a design of many sheet parts that was most of a hole's time (#10226).
#[test]
fn a_hole_leaves_sheets_it_cannot_reach_as_they_were() {
let mut doc = Document::new("far sheets");
for i in 0..5 {
flat_sheet(&mut doc, Vec2::new(200.0 * i as f64, 0.0), 150.0, 100.0);
}
block(&mut doc, "Plate", Vec3::new(0.0, -200.0, 0.0), [60.0, 60.0, 12.0]);
let work = cut_work(&mut doc, hole(Vec3::new(30.0, -170.0, 12.0), Vec3::new(0.0, 0.0, -1.0), 6.0));
let sheets = sheet_bodies(&work.model);
assert_eq!(sheets.len(), 5);
assert_eq!(work.cut, 1, "only the plate goes through a boolean");
assert_eq!(work.kept, sheets, "every sheet is left as it was");
assert!(volume(&work.model, "Plate") < 43_200.0 - 300.0, "and the plate is drilled");
}
/// A hole drilled into a sheet's rim still bores that sheet, beside sheets it cannot reach.
#[test]
fn a_hole_into_a_rim_still_bores_its_sheet_beside_far_ones() {
let mut doc = Document::new("rim");
for i in 0..4 {
flat_sheet(&mut doc, Vec2::new(200.0 * i as f64, 0.0), 60.0, 40.0);
}
let mut model = Model::new();
model.evaluate(&doc);
let near = sheet_bodies(&model)[0].clone();
let whole = volume(&model, &near);
let d = 1.5;
let work = cut_work(&mut doc, hole(Vec3::new(60.0, 20.0, 1.25), Vec3::new(-1.0, 0.0, 0.0), d));
assert_eq!(work.cut, 1, "only the sheet the drill meets is bored");
assert_eq!(work.kept, sheet_bodies(&work.model)[1..]);
let state = work.model.state();
let sheet = state.sheets.iter().find(|s| s.body == near).unwrap();
assert_eq!(sheet.bores.len(), 1, "kept as a bore of the sheet");
let removed = whole - volume(&work.model, &near);
let bore = std::f64::consts::PI * (d / 2.0).powi(2) * 60.0;
assert!((removed - bore).abs() < 0.02 * bore, "removed {removed} of {bore}");
}
+21
View File
@@ -1265,12 +1265,23 @@ pub(super) fn sheet_primitive_cut(
/// panel at an angle).
pub(super) fn sheet_bore_cut(f: &Feature, st: &mut ModelState, prism: PrimitivePrism) -> Result<Option<Vec<String>>> {
let PrimitivePrism::Cylinder { base, axis, radius, height } = prism else { return Ok(None) };
// Drilling a sheet builds each of its panels and runs a boolean on it, only to find that a
// drill far off meets none (#10226): a sheet whose box lies clear of the drill's is left out.
// Both boxes are grown past how far the exact faces curve out from their meshes, as for
// the other sheet cuts. A drill a sheet refuses whatever it meets (not a cylinder, or the
// sheet holds all the bores it may) is still put to every sheet.
let reach = drill_box(base, axis, radius, height);
let mut plans = Vec::new();
for original in &st.sheets {
if !sheet_eligible(f, st, &[], original) {
continue;
}
if !original.bores_full() && st.body(&original.body).is_some_and(|mb| boxes_apart(&mesh_box(mb), &reach)) {
continue;
}
let mut sh = original.clone();
#[cfg(test)]
super::cost_tests::count(|c| c.cut += 1);
match sh.add_bore(base, axis, radius, height) {
Ok(true) => {}
Ok(false) => continue,
@@ -1297,6 +1308,16 @@ pub(super) fn sheet_bore_cut(f: &Feature, st: &mut ModelState, prism: PrimitiveP
Ok(Some(handled))
}
/// [`body_box`] of a hole's drill as [`crate::sheet::SheetBody::add_bore`] makes it; None
/// (never apart) for a drill it refuses.
fn drill_box(base: Vec3, axis: Vec3, radius: f64, height: f64) -> Option<Aabb3> {
let axis = axis.normalized()?;
if ![base.x, base.y, base.z, radius, height].iter().all(|v| v.is_finite()) || !(radius > 0.0) || height == 0.0 {
return None;
}
body_box(&kernel::cylinder(base, axis, radius, height).ok()?)
}
/// The most hole tools machined in one pass by [`sheet_drill_cuts`].
const MAX_DRILLS_AT_ONCE: usize = 1000;
+6 -1
View File
@@ -1942,6 +1942,11 @@ impl SheetBody {
Ok(body)
}
/// Whether the sheet holds all the bores it may: [`Self::add_bore`] refuses any more.
pub(crate) fn bores_full(&self) -> bool {
self.bores.len() >= MAX_BORES
}
/// Record a round bore drilled along the sheet (a hole into a rim): the world cylinder from
/// `base` along `axis`, one record per panel whose material it meets. Ok(false) when it
/// meets no material; an error when it meets a bend, or crosses a panel other than along
@@ -1951,7 +1956,7 @@ impl SheetBody {
if ![base.x, base.y, base.z, radius, height].iter().all(|v| v.is_finite()) || !(radius > 0.0) || height == 0.0 {
return Err(DocError::Invalid("invalid sheet bore".into()));
}
if self.bores.len() >= MAX_BORES {
if self.bores_full() {
return Err(flat_budget_error());
}
let mut work = FlatWork::new();