SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Preserve expression-positioned sketch fillet corners (#4097) (#4106)
raykholoec56df3ffd68
diff --git a/crates/engine/src/cmd/sketch_modify.rs b/crates/engine/src/cmd/sketch_modify.rsindex a70f51e8cf..cead75217c 100644--- a/crates/engine/src/cmd/sketch_modify.rs+++ b/crates/engine/src/cmd/sketch_modify.rs@@ -866,11 +866,11 @@ struct CornerKept {}/// Keep corner point `c` of curves `ca`, `cb` (whose corner ends were just moved to `na`, `nb`)-/// when anything measures to it: a constraint or dimension on the point, the length of either-/// line, or it is the origin or still ends another curve. It stays as a virtual sharp corner,-/// held on both curves' extensions (their intersection), and the line lengths become distances-/// from the far end to it, so the part keeps its size. Otherwise None: the-/// caller removes the point.+/// when anything measures to it or places it: a constraint or dimension on the point, the length+/// of either line, a fixed or expression-driven position, or it is the origin or still ends another+/// curve. It stays as a virtual sharp corner, held on both curves' extensions (their+/// intersection), and the line lengths become distances from the far end to it, so the part+/// keeps its size. Otherwise None: the caller removes the point.fn keep_corner(sk: &mut Sketch, c: usize, [(ca, na), (cb, nb)]: [(usize, usize); 2]) -> Result<Option<CornerKept>> {let used = sk.curves.iter().any(|x| uses(x, c));let mut moved: Vec<String> = sk.constraints.iter().filter(|k| k.kind.refers_to_point(c)).map(|k| k.id.clone()).collect();@@ -888,7 +888,8 @@ fn keep_corner(sk: &mut Sketch, c: usize, [(ca, na), (cb, nb)]: [(usize, usize);k.kind = if *a == new_end { ConstraintKind::Distance { p: c, q: *b, value } } else { ConstraintKind::Distance { p: *a, q: c, value } };moved.push(k.id.clone());}- if moved.is_empty() && !used && c != 0 {+ let positioned = sk.points.get(c).is_some_and(|pt| pt.fixed || pt.exprs.is_some());+ if moved.is_empty() && !used && c != 0 && !positioned {return Ok(None);}for cu in [ca, cb] {diff --git a/crates/engine/src/cmd/sketch_modify_tests.rs b/crates/engine/src/cmd/sketch_modify_tests.rsindex d5b5f57c4e..b18974a9c8 100644--- a/crates/engine/src/cmd/sketch_modify_tests.rs+++ b/crates/engine/src/cmd/sketch_modify_tests.rs@@ -238,6 +238,41 @@ fn exact_extend_refuses_ambiguous_stop_without_history_change() {assert_eq!(s.undo.len(), history);}+#[test]+fn fillet_keeps_expression_corner_when_parameter_changes() {+ let mut s = new_sketch();+ run(&mut s, "parameters.add", json!({"name": "W", "expression": "40 mm"}));+ run(&mut s, "parameters.add", json!({"name": "H", "expression": "20 mm"}));+ let outline = run(&mut s, "sketch.line", json!({"closed": true, "points": [["0 mm", "0 mm"], ["W", "0 mm"], ["W", "H"], ["0 mm", "H"]]}));+ assert_eq!(outline["sketch"]["dof"], 0);+ let fillet = run(&mut s, "sketch.fillet", json!({"point": "l2.end", "radius": 5}));+ assert_eq!(fillet["sketch"]["dof"], 0, "{fillet}");+ let corners = ids(&fillet["virtual_corners"]);+ assert_eq!(corners.len(), 1, "{fillet}");++ for width in [60.0, 30.0] {+ run(&mut s, "parameters.change", json!({"name": "W", "expression": format!("{width} mm")}));+ let info = run(&mut s, "sketch.inspect", json!({}));+ assert_eq!(info["dof"], 0, "{info}");+ let sk = sketch(&s);+ let corner = &sk.points[sk.resolve_point(&corners[0]).unwrap()];+ assert!(corner.fixed && corner.exprs.is_some());+ for (point, expected) in [+ (corners[0].as_str(), Vec2::new(width, 20.0)),+ ("l2.start", Vec2::new(width, 0.0)),+ ("l2.end", Vec2::new(width, 15.0)),+ ("l3.start", Vec2::new(width - 5.0, 20.0)),+ ("l3.end", Vec2::new(0.0, 20.0)),+ ] {+ let actual = sk.point(sk.resolve_point(point).unwrap()).unwrap();+ assert!(actual.dist(expected) < 1e-6, "{point}: {actual:?}, expected {expected:?}");+ }+ let area = profiles(&s);+ assert_eq!(area.len(), 1);+ assert!(close(area[0], width * 20.0 - 25.0 * (1.0 - std::f64::consts::PI / 4.0)), "{area:?}");+ }+}+#[test]fn fillet_and_chamfers() {let mut s = new_sketch();