Sheet metal: a cut leaves sheets it cannot reach untouched without a check (#10301)
Before a cut ran, every sheet metal body of its component went through a boolean with the tool, to make sure the cut would not take material the flat pattern cannot keep. For a sheet the tool does not reach, that check only found nothing: in a design of 50 sheet parts it was about an eighth of a hole's time. Now a sheet whose box lies clear of every tool's box is left out of the check, with the same grown boxes the cut itself uses (#10225), so a tool that touches or grazes a sheet is still checked. Sheets shown in another frame and Intersect are checked as before. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
committed by
GitHub
parent
00f7e97578
commit
a0ec7dbdf0
@@ -3212,10 +3212,25 @@ fn apply_traced_with(
|
||||
return Ok(());
|
||||
}
|
||||
if matches!(op, Operation::Cut | Operation::Intersect) {
|
||||
// A cut that cannot reach a sheet leaves it as it is (#10226): a sheet whose box lies
|
||||
// clear of every tool's, in its own frame, needs no boolean to show it. An intersect
|
||||
// removes the sheets it misses, and checks each one as before.
|
||||
let mut reach: Option<Vec<Option<solidcraft_geom::Aabb3>>> = None;
|
||||
for &i in &target_idx {
|
||||
if let Some(mb) = state.bodies.get(i).filter(|b| state.sheets.iter().any(|s| s.body == b.name)) {
|
||||
let m = tool_frame(&mb.name);
|
||||
if op == Operation::Cut && m.is_none() && !mb.body.is_mesh() && !tools.iter().any(|t| t.body.is_mesh()) {
|
||||
let reach = reach.get_or_insert_with(|| tools.iter().map(|t| more::body_box(&t.body)).collect());
|
||||
if !reach.is_empty()
|
||||
&& let Some(target) = more::mesh_box(mb)
|
||||
&& reach.iter().all(|tool| more::boxes_apart(&Some(target), tool))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
let bodies: Vec<Body> = tools.iter().map(|t| tool_in(t, m).map(|t| t.body)).collect::<Result<_>>()?;
|
||||
#[cfg(test)]
|
||||
cost_tests::count(|c| c.cut += 1);
|
||||
sheet_boolean_unchanged(&mb.body, &bodies, op)?;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1344,3 +1344,34 @@ fn a_tap_marking_still_searches_the_bodies_within_its_reach() {
|
||||
assert_eq!(threads[0].internal, internal);
|
||||
}
|
||||
}
|
||||
|
||||
/// A flat sheet of the default rule (2.5 mm steel) on a `w` x `h` rectangle from `corner` on XY.
|
||||
fn flat_sheet(doc: &mut Document, corner: Vec2, w: f64, h: f64) {
|
||||
let mut sk = Sketch::new();
|
||||
let p = [corner, corner + Vec2::new(w, 0.0), corner + Vec2::new(w, h), corner + Vec2::new(0.0, h)].map(|q| sk.add_point(q, None).unwrap());
|
||||
for k in 0..4 {
|
||||
sk.add_line_pts(p[k], p[(k + 1) % 4], None).unwrap();
|
||||
}
|
||||
let sketch = doc.add_feature(FeatureKind::Sketch { plane: PlaneRef::Origin { name: "XY".into() }, sketch: sk }, None).unwrap();
|
||||
doc.add_feature(FeatureKind::SheetBase { sketch: SketchId(sketch), profiles: ProfileSel::All, rule: None, flip: false }, None).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()
|
||||
}
|
||||
|
||||
/// A cut leaves the sheets it cannot reach as they were, without checking that it would leave
|
||||
/// each one unchanged (#10226).
|
||||
#[test]
|
||||
fn a_cut_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, cutter(Vec3::new(30.0, -170.0, -1.0), 3.0, 20.0));
|
||||
assert_eq!(work.cut, 1, "only the plate goes through a boolean");
|
||||
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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user