SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Sketch: stop tying expression-placed points to the origin with an automatic Coincident (#10703) (#10722)
Dahak Builds2b9261050f07
diff --git a/crates/engine/src/cmd/sketch.rs b/crates/engine/src/cmd/sketch.rsindex 59e6c59927..df826210ab 100644--- a/crates/engine/src/cmd/sketch.rs+++ b/crates/engine/src/cmd/sketch.rs@@ -472,6 +472,9 @@ const CONNECT_TOL: f64 = 1e-6;/// New points (index `first` on) that land on an existing point, the origin included, get a/// coincident constraint to it, as when a click snaps there; `connect: false` leaves them free.+/// A point placed by parameter expressions is never tied: it follows its expressions, and a+/// Coincident to where the expressions happened to come to at draw time conflicts with the+/// next parameter change (#10703).fn connect_points(sk: &mut Sketch, first: usize, p: &Value) -> Result<Vec<String>> {if !bool_(p, "connect").unwrap_or(true) {return Ok(Vec::new());@@ -481,6 +484,9 @@ fn connect_points(sk: &mut Sketch, first: usize, p: &Value) -> Result<Vec<Stringold.sort_by(|a, b| a.0.x.total_cmp(&b.0.x));let mut ties = Vec::new();for q in first..sk.points.len() {+ if sk.points.get(q).is_some_and(|pt| pt.exprs.is_some()) {+ continue;+ }let Some(at) = sk.point(q) else { continue };let from = old.partition_point(|(o, _)| o.x < at.x - CONNECT_TOL);let hit =diff --git a/crates/engine/src/cmd/sketch_point_expr_tests.rs b/crates/engine/src/cmd/sketch_point_expr_tests.rsindex 678fe5038a..c8b148ec8f 100644--- a/crates/engine/src/cmd/sketch_point_expr_tests.rs+++ b/crates/engine/src/cmd/sketch_point_expr_tests.rs@@ -400,3 +400,50 @@ fn a_rejected_size_or_corner_expression_leaves_nothing_behind() {assert_eq!(count(&s), before, "{cmd} {p}");}}++/// A corner typed as an expression that comes to 0 when drawn lands on the origin; it must not+/// be tied to it by the automatic Coincident a snapped click gets, or the next parameter change+/// conflicts with the tie (#10703).+#[test]+fn a_rectangle_corner_whose_expression_is_zero_when_drawn_is_not_tied_to_the_origin() {+ let mut s = Session::default();+ run(&mut s, "parameters.add", json!({"name": "x0", "expression": "0 mm"}));+ run(&mut s, "sketch.create", json!({"plane": "XY", "name": "S"}));+ let r = run(&mut s, "sketch.rectangle.two_point", json!({"p0": ["x0", 0], "p1": [40, 30]}));+ assert_eq!(r["constraints"].as_array().map(Vec::len), Some(4), "the four side constraints, no Coincident to the origin: {r}");+ run(&mut s, "sketch.finish", json!({}));+ run(&mut s, "solid.extrude", json!({"sketch": "S", "distance": 10}));+ no_trouble(&s);+ assert!((volume(&mut s) - 40.0 * 30.0 * 10.0).abs() < 1e-6);+ run(&mut s, "parameters.change", json!({"name": "x0", "expression": "15 mm"}));+ no_trouble(&s);+ assert!((volume(&mut s) - 25.0 * 30.0 * 10.0).abs() < 1e-6);+}++/// The same for a lone `sketch.point`: an expression that comes to the origin at draw time+/// leaves the point free, and it follows the parameter from there (#10703).+#[test]+fn a_point_whose_expression_is_zero_when_drawn_is_not_tied_to_the_origin() {+ let mut s = Session::default();+ run(&mut s, "parameters.add", json!({"name": "x0", "expression": "0 mm"}));+ run(&mut s, "sketch.create", json!({"plane": "XY", "name": "S"}));+ let r = run(&mut s, "sketch.point", json!({"point": ["x0", 0], "id": "p"}));+ assert_eq!(r["constraints"].as_array().map(Vec::len), Some(0), "no Coincident to the origin: {r}");+ run(&mut s, "sketch.finish", json!({}));+ no_trouble(&s);+ run(&mut s, "parameters.change", json!({"name": "x0", "expression": "15 mm"}));+ no_trouble(&s);+ assert_eq!(solved(&s, "p"), Vec2::new(15.0, 0.0));+}++/// A corner given as plain numbers on the origin still snaps to it, as a clicked point does:+/// only expression-placed points are exempt from the automatic Coincident.+#[test]+fn a_plain_corner_on_the_origin_still_snaps_to_it() {+ let mut s = Session::default();+ run(&mut s, "sketch.create", json!({"plane": "XY", "name": "S"}));+ let r = run(&mut s, "sketch.rectangle.two_point", json!({"p0": [0, 0], "p1": [40, 30]}));+ assert_eq!(r["constraints"].as_array().map(Vec::len), Some(5), "the four side constraints plus the Coincident to the origin: {r}");+ run(&mut s, "sketch.finish", json!({}));+ no_trouble(&s);+}