Skip to content

SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.

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)

bherbruckb2d0452656a7
diff --git a/crates/doc/src/sheet.rs b/crates/doc/src/sheet.rs
index 9c133351a1..cdbd6a912d 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 4663a3d10d..b3280b89ae 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}");
+ }
+ }
+}