fix: unfold sheets shrunk by a parameter change (#349)
A sheet-metal tray built at 2000 x 2500 mm with an edge flange on all four edges (72° or 90°) and unfolded failed to rebuild when W and H went to 400 x 300, 600 x 450, or W alone to 400: "planar region arrangement failed or exceeded its bounded processing budget". The same tray drawn at 400 x 300 unfolded, and growing it worked. The sketch solved again after the change leaves its corners ~1e-13 mm off, so the flanges inherit a hair of tilt and their panels and bend zones meet the trimmed base within 1e-13 mm instead of exactly. The flat pattern is a balanced union of those pieces, and the arrangement chains its output loops within 10 tol. In a later round, ray parity classified a bend zone's edge midpoint that lay level with a corner whose two lines did not quite meet: the ray slipped through the gap without a crossing, the zone's edges counted as inside the other operand and were dropped, and the outline no longer closed. A rectangle turned by 1e-14 rad failed the same way. inside_loop now closes the gap where one line ends and the next begins with a straight connector while it counts crossings; exactly closed joints are unaffected. Joints with an arc keep the arc's own endpoint rule, which treats ends within its angular tolerance as on the ray (a connector there double counted at a circle split into two arcs). Co-authored-by: NOWN-DEV <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
This commit is contained in:
3 files changed
+115
-1
No files matched your search
@@ -702,6 +702,45 @@ fn fold_keeps_the_larger_side_either_way() {
|
||||
}
|
||||
}
|
||||
|
||||
/// A tray shrunk by a parameter change unfolds like the same tray built at that size. The
|
||||
/// sketch solved again leaves its corners ~1e-13 mm off, and the flat pattern's planar
|
||||
/// arrangement used to drop a bend zone through a gap that small: "planar region arrangement
|
||||
/// failed", for W alone or both sizes, at 72° or 90°, while growing the tray worked.
|
||||
#[test]
|
||||
fn tray_shrunk_by_a_parameter_unfolds_like_one_built_at_that_size() {
|
||||
for angle in [72.0, 90.0] {
|
||||
let tray = |s: &mut Session, w: f64, h: f64| {
|
||||
run(s, "parameters.add", json!({"name": "W", "expression": format!("{w} mm")}));
|
||||
run(s, "parameters.add", json!({"name": "H", "expression": format!("{h} mm")}));
|
||||
run(s, "sheet.manage_rules", json!({"name": "AL2", "thickness": "2 mm", "k_factor": "0.5", "bend_radius": "1 mm", "active": true}));
|
||||
run(s, "sketch.create", json!({"plane": "XY", "name": "Tray"}));
|
||||
run(s, "sketch.rectangle.two_point", json!({"p0": [0, 0], "p1": [w, h]}));
|
||||
run(s, "sketch.constraint.fix", json!({"entities": ["p1"]}));
|
||||
run(s, "sketch.dimension", json!({"entities": ["l1"], "value": "W"}));
|
||||
run(s, "sketch.dimension", json!({"entities": ["l2"], "value": "H"}));
|
||||
run(s, "sketch.finish", json!({}));
|
||||
run(s, "sheet.flange", json!({"type": "base", "sketch": "Tray"}));
|
||||
let edges = json!([[w / 2.0, 0, 2], [w, h / 2.0, 2], [w / 2.0, h, 2], [0, h / 2.0, 2]]);
|
||||
run(s, "sheet.flange", json!({"type": "edge", "edges": edges, "height": 38.6, "angle": angle}));
|
||||
run(s, "sheet.unfold", json!({}));
|
||||
};
|
||||
let mut direct = Session::default();
|
||||
tray(&mut direct, 400.0, 300.0);
|
||||
let want = flat(&mut direct)["flat_size_mm"].clone();
|
||||
let mut shrunk = Session::default();
|
||||
tray(&mut shrunk, 2000.0, 2500.0);
|
||||
for (name, expr) in [("W", "400 mm"), ("H", "300 mm")] {
|
||||
let r = run(&mut shrunk, "parameters.change", json!({"name": name, "expression": expr}));
|
||||
assert_eq!(r["errors"], json!([]), "{angle}° {name} = {expr}: {r}");
|
||||
}
|
||||
let got = flat(&mut shrunk)["flat_size_mm"].clone();
|
||||
for k in 0..3 {
|
||||
assert!((got[k].as_f64().unwrap() - want[k].as_f64().unwrap()).abs() < 1e-9, "{angle}°: {got} {want}");
|
||||
}
|
||||
assert!(rel(volume(&mut shrunk), volume(&mut direct)) < 1e-9, "{angle}°");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bend_table_exports_shop_dimensions_and_tracks_parameter_changes() {
|
||||
let mut s = Session::default();
|
||||
|
||||
Reference in new issue
Block a user