Convert to Sheet Metal keeps a plate where it is (#3316)

* claim: Convert to Sheet Metal keeps a plate where it is

* Convert to Sheet Metal keeps a plate where it is

Converted without bend edges, a plate moved by one thickness: a 100 x 60 x 2
plate on XY came out at z -2..0 picked on its top face, 2..4 picked on its
bottom. The sheet's frame (its base panel's bottom face, thickness along its
normal) was put on the plate's far face facing away from the picked face, so
the material grew out into empty space.

The frame now lies on the picked face with z into the material, as Convert
with bend edges does. The sheet is the old one moved back by the thickness:
same orientation, flat pattern, flange directions and pocket layers.

A test converts the plate from either face and checks its bounding box; the
engraved-plate test now checks the plate's position, not only its thickness.
This commit is contained in:
raykholo authored and GitHub committed 2026-10-20 11:43:07 +00:00
1 parent 9506336829
commit 9666c0be56
2 files changed
+24 -4

No files matched your search

+4 -2
View File
@@ -741,8 +741,10 @@ pub(super) fn sheet_eval(
let t = hi - lo;
// The face outline: boundary edges of the triangles on that face's plane, where it runs
// along a round wall an arc of the wall's circle (not chords: the plate check below
// compares its area with the exact volume).
let plane = Plane::from_normal(face.0 + n * lo, n * -1.0).ok_or_else(|| DocError::Invalid("face".into()))?;
// compares its area with the exact volume). The sheet's frame lies on the picked face
// (its outer level, `hi`) with z into the material, as with bend edges, so the sheet
// takes the plate's place: its thickness runs from `hi` back to `lo`.
let plane = Plane::from_normal(face.0 + n * hi, n * -1.0).ok_or_else(|| DocError::Invalid("face".into()))?;
// Recesses in one face (an engraved label) become pockets; the outline is the other face's.
let recesses = plate_recesses(&mb.body, &mesh, &plane, face.0, n, (lo, hi), tol)?;
let mut walls = std::collections::HashMap::new();
+20 -2
View File
@@ -985,6 +985,24 @@ fn convert_box(l: f64, w: f64, t: f64, holes: &[([f64; 2], f64)]) -> Session {
s
}
/// A converted plate stays where the plate was, whichever of its faces is picked: the sheet
/// takes the plate's two faces, not the space one thickness beyond the face picked (a 100 x 60 x 2
/// plate on XY used to come out at z −2…0 picked on top, and 2…4 picked underneath).
#[test]
fn a_converted_plate_stays_where_the_plate_was() {
for pick in [[40.0, 15.0, 2.0], [40.0, 15.0, 0.0]] {
let mut s = Session::default();
run(&mut s, "solid.box", json!({"length": 100, "width": 60, "height": 2, "body_name": "Plate"}));
let before = bbox(&mut s);
run(&mut s, "sheet.convert", json!({"body": "Plate", "face": pick}));
assert!(!s.model.state().sheets.is_empty(), "{pick:?}");
let after = bbox(&mut s);
let moved = before.0.iter().chain(&before.1).zip(after.0.iter().chain(&after.1)).any(|(a, b)| (a - b).abs() > 1e-9);
assert!(!moved, "{pick:?}: {before:?} became {after:?}");
assert!((volume(&mut s) - 12_000.0).abs() < 1e-6, "{pick:?}: {}", volume(&mut s));
}
}
/// A long thin strip converts. 1200 x 100 x 1 was refused with "no outline on that face": the
/// outline's tolerance was a thousandth of the body's size (1.2), more than the thickness, so the
/// far side's triangles counted as the picked face's and no boundary was left.
@@ -1087,9 +1105,9 @@ fn a_plate_with_an_engraving_converts_with_the_engraving_as_a_pocket() {
let m = run(&mut s, "inspect.measure", json!({}));
assert!((m["total"]["volume_mm3"].as_f64().unwrap_or(f64::NAN) - 2380.0).abs() < 1e-6, "{pick:?}: {m}");
assert!((m["total"]["area_mm2"].as_f64().unwrap_or(f64::NAN) - 5006.0).abs() < 1e-6, "{pick:?}: {m}");
// It stays in the face it was cut into (the converted plate is as thick, wherever it lies).
// It stays in the face it was cut into, and the plate where it was (z 0…1).
let (lo, hi) = bbox(&mut s);
assert!((hi[2] - lo[2] - 1.0).abs() < 1e-9, "{pick:?}: {lo:?} {hi:?}");
assert!(lo[2].abs() < 1e-9 && (hi[2] - 1.0).abs() < 1e-9, "{pick:?}: {lo:?} {hi:?}");
assert!(!contains(&s, [20.0, 15.0, hi[2] - 0.05]) && contains(&s, [20.0, 15.0, hi[2] - 0.15]), "{pick:?}");
assert!(contains(&s, [45.0, 30.0, hi[2] - 0.05]), "{pick:?}");
// The flat pattern: the whole plate, no cut-out, and the engraving as a pocket 0.1 deep.