Sheet metal convert: a bend split by cut-outs across it is one bend (#7530) (#7581)

A bend that cut-outs across it split into several cylinder faces came out slit, silently: only
the picked piece was bent, the rest of the bend was cut away with the cut-out, and the volume came
out short. Picking the other pieces too was refused ("two faces of the sheet that meet along more
than one edge"). A picked bend cylinder now takes every coaxial piece of the same radius between
the same two faces, on both skins; in the flat, a face that meets its bend neighbour along several
collinear runs gets one bend edge, and the notches between them and the bend zone's pieces there
become holes of the sheet.

Test: a_bend_split_by_slots_across_it_converts_as_one_bend (slots cut through a tray's unfolded
bends, one piece picked or every piece): the volume, flat size, outline area, bends and the three
cut-outs are the source's.

Fixes #7530.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
NOWN-DEV
2026-11-05 07:37:58 +00:00
committed by GitHub
parent 9fdb7fdefc
commit 9c93a6c340
2 changed files with 168 additions and 24 deletions
+52 -1
View File
@@ -1807,6 +1807,12 @@ fn a_wall_on_part_of_an_edge_meets_a_wall_at_a_relieved_corner_and_is_relieved_a
/// axes 45° round from the base. Returns the new design (with the rule), the picks and the
/// design the tray was made in.
fn tray_round_trip(shape: &str, two: bool) -> (Session, Vec<[f64; 3]>, Session) {
slotted_tray_round_trip(shape, two, &[])
}
/// [`tray_round_trip`] with `slots` (x0, y0, x1, y1) cut through the unfolded tray before it is
/// folded again and written out.
fn slotted_tray_round_trip(shape: &str, two: bool, slots: &[[f64; 4]]) -> (Session, Vec<[f64; 3]>, Session) {
let (t, r) = (1.0, 1.0);
let rule = json!({"name": "T", "thickness": "1 mm", "k_factor": "0.5", "bend_radius": "1 mm", "gap": "0.6 mm", "corner_relief_shape": shape, "corner_relief": "3 mm", "active": true});
let mut a = Session::default();
@@ -1824,7 +1830,18 @@ fn tray_round_trip(shape: &str, two: bool) -> (Session, Vec<[f64; 3]>, Session)
all.extend(short.as_array().cloned().unwrap_or_default());
run(&mut a, "sheet.flange", json!({"edges": all, "height": 30}));
}
let path = std::env::temp_dir().join(format!("solidcraft-tray-round-trip-{shape}-{two}-{}.step", std::process::id()));
if !slots.is_empty() {
run(&mut a, "sheet.unfold", json!({}));
for (i, [x0, y0, x1, y1]) in slots.iter().enumerate() {
let name = format!("Slot{i}");
run(&mut a, "sketch.create", json!({"plane": "XY", "name": name}));
run(&mut a, "sketch.rectangle.two_point", json!({"p0": [x0, y0], "p1": [x1, y1]}));
run(&mut a, "sketch.finish", json!({}));
run(&mut a, "solid.extrude", json!({"sketch": name, "through_all": true, "operation": "cut", "direction": "symmetric"}));
}
run(&mut a, "sheet.refold", json!({}));
}
let path = std::env::temp_dir().join(format!("solidcraft-tray-round-trip-{shape}-{two}-{}-{}.step", slots.len(), std::process::id()));
run(&mut a, "file.export", json!({"path": path.to_string_lossy()}));
let mut s = Session::default();
run(&mut s, "file.insert_step", json!({"path": path.to_string_lossy()}));
@@ -1876,3 +1893,37 @@ fn trays_of_its_own_sheet_metal_convert_back() {
}
}
}
/// A bend that slots cross is one bend, however many of its pieces are picked: the pieces of
/// its cylinder between the slots are all bent, and the slots come back as cut-outs across it.
#[test]
fn a_bend_split_by_slots_across_it_converts_as_one_bend() {
// Two slots across the long bend at y = 0, one across the short bend at x = 120, from the
// base into the walls of the unfolded tray.
let slots = [[30.0, -6.0, 40.0, 8.0], [70.0, -6.0, 80.0, 8.0], [112.0, 55.0, 126.0, 65.0]];
for shape in ["notch", "tear"] {
for every in [false, true] {
let what = format!("{shape}, {}", if every { "every piece picked" } else { "one piece picked" });
let (mut s, mut picks, mut source) = slotted_tray_round_trip(shape, false, &slots);
if every {
let (o, d) = (2.0, 2.0 * std::f64::consts::FRAC_1_SQRT_2);
picks.extend([[15.0, o - d, o - d], [100.0, o - d, o - d], [120.0 - o + d, 20.0, o - d], [120.0 - o + d, 75.0, o - d]]);
}
let body = s.model.state().bodies.first().map(|b| b.name.clone()).unwrap_or_default();
let out = s.execute("sheet.convert", &json!({"body": body, "face": [60, 45, 0], "bends": picks, "rule": "T"}));
assert!(out.is_ok(), "{what}: {}", out.err().map(|e| e.to_string()).unwrap_or_default());
let (v, size, (area, bends)) = (volume(&mut source), flat_size(&mut source), flat_area_and_bends(&mut source));
let cutouts = flat(&mut source)["cutouts"].as_array().map(Vec::len);
assert_eq!(cutouts, Some(3), "{what}");
assert!((volume(&mut s) - v).abs() < 1e-6 * v, "{what}: {} vs {v}", volume(&mut s));
assert!(same_size(flat_size(&mut s), size, 1e-6), "{what}: {:?} vs {size:?}", flat_size(&mut s));
let (got_area, got_bends) = flat_area_and_bends(&mut s);
assert!((got_area - area).abs() < 1e-6 * area, "{what}: {got_area} vs {area}");
assert!(
got_bends.len() == bends.len() && got_bends.iter().zip(&bends).all(|(x, y)| (x - y).abs() < 1e-6),
"{what}: {got_bends:?} vs {bends:?}"
);
assert_eq!(flat(&mut s)["cutouts"].as_array().map(Vec::len), cutouts, "{what}");
}
}
}