From b2d0452656a72a906959d839fa8264bc8076428d Mon Sep 17 00:00:00 2001 From: bherbruck Date: Thu, 8 Oct 2026 12:53:25 +0000 Subject: [PATCH] Fold: with no fixed side the larger side stays, whichever side of the line it is on (the side areas were measured from the wrong point for one side; QA s22) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AS5Tn3xieewUSg3uxrMVdL --- crates/doc/src/sheet.rs | 3 ++- crates/engine/src/cmd/sheet_tests.rs | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/crates/doc/src/sheet.rs b/crates/doc/src/sheet.rs index 9c133351..cdbd6a91 100644 --- a/crates/doc/src/sheet.rs +++ b/crates/doc/src/sheet.rs @@ -953,7 +953,8 @@ impl SheetBody { let mut n = Vec2::new(-d.y, d.x); let l0 = a2.dot(n); // Which side moves. A flange keeps the side its own bend is on. - let side_area = |n: Vec2| signed_area(&clip(&pts, n * l0, n)).abs(); + let on_line = n * l0; + let side_area = |m: Vec2| signed_area(&clip(&pts, on_line, m)).abs(); let moves_n = match (panel, fixed) { (Some(j), _) => { let f = self.flanges.get(j).ok_or_else(|| DocError::Invalid("flange".into()))?; diff --git a/crates/engine/src/cmd/sheet_tests.rs b/crates/engine/src/cmd/sheet_tests.rs index 4663a3d1..b3280b89 100644 --- a/crates/engine/src/cmd/sheet_tests.rs +++ b/crates/engine/src/cmd/sheet_tests.rs @@ -327,3 +327,20 @@ fn flange_edges_are_named_and_follow_the_base_sketch() { let h = s.doc.find_feature("H").cloned().unwrap(); assert!(h.edge_names[0].starts_with(&format!("F{id}.0:far")), "{:?}", h.edge_names); } + +/// With no fixed side, the larger side stays whichever side of the line it is on (QA s22). +#[test] +fn fold_keeps_the_larger_side_either_way() { + for (w, line, moving_right) in [(60.0, 40.0, true), (100.0, 40.0, false)] { + let mut s = Session::default(); + base(&mut s, w, 40.0); + run(&mut s, "SheetMetalFoldCmd", json!({"points": [[line, 0, 2.5], [line, 40, 2.5]]})); + let b = bbox(&mut s); + let (x0, x1) = (b["min"][0].as_f64().unwrap_or(0.0), b["max"][0].as_f64().unwrap_or(0.0)); + if moving_right { + assert!(x0.abs() < 1e-6 && x1 < line + 5.0, "the left (larger) part stays: {b}"); + } else { + assert!((x1 - w).abs() < 1e-6 && x0 > line - 5.0, "the right (larger) part stays: {b}"); + } + } +}