Skip to content

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

Sketch: a test that Symmetry about the origin point accepts two corners of the same rectangle edge (#4850) (#12772)

PaddleStroke4f77836834a2
diff --git a/crates/engine/src/cmd/sketch_constraints_tests.rs b/crates/engine/src/cmd/sketch_constraints_tests.rs
index d2c224a03a..84f954a123 100644
--- a/crates/engine/src/cmd/sketch_constraints_tests.rs
+++ b/crates/engine/src/cmd/sketch_constraints_tests.rs
@@ -749,6 +749,37 @@ fn symmetry_slides_a_rectangle_whose_width_is_dimensioned() {
assert!((r.x - l.x - 42.0).abs() < 1e-6 && (l.x + 21.0).abs() < 1e-6, "sides at ±21: {l:?} {r:?}");
}
+#[test]
+fn symmetry_of_two_corners_of_one_edge_about_the_origin() {
+ // #4850: two corners of the same rectangle edge, symmetric about the origin point, were
+ // refused as "neither entity can move" although sliding the rectangle meets it.
+ let mut s = new_sketch();
+ let r = run(&mut s, "sketch.rectangle.two_point", json!({"p0": [-12, -6], "p1": [18, 10]}));
+ let sides = ids(&r["curves"]);
+ let sk = sketch(&s);
+ let bottom = sides
+ .iter()
+ .find(|id| {
+ let (a, b) = line_ends(&sk, id);
+ (a.y + 6.0).abs() < 1e-9 && (b.y + 6.0).abs() < 1e-9
+ })
+ .unwrap_or_else(|| panic!("no bottom side in {sides:?}"))
+ .clone();
+ run(&mut s, "sketch.constraint.symmetry", json!({"a": format!("{bottom}.start"), "b": format!("{bottom}.end"), "point": "origin"}));
+ let sk = sketch(&s);
+ let (a, b) = line_ends(&sk, &bottom);
+ assert!((a.x + b.x).abs() < 1e-6 && (a.y + b.y).abs() < 1e-6, "corners not mirrored about the origin: {a:?} {b:?}");
+ assert!(a.y.abs() < 1e-6 && b.y.abs() < 1e-6, "corners not on y = 0: {a:?} {b:?}");
+ assert!((a.x - b.x).abs() > 1.0, "the bottom side collapsed: {a:?} {b:?}");
+ for corner in [a, b] {
+ let met = sides.iter().filter(|id| **id != bottom).any(|id| {
+ let (p, q) = line_ends(&sk, id);
+ p.dist(corner) < 1e-6 || q.dist(corner) < 1e-6
+ });
+ assert!(met, "no adjacent side meets the corner {corner:?}");
+ }
+}
+
#[test]
fn symmetry_pairs_the_ends_of_fixed_lines_drawn_the_opposite_way() {
// #1796: the sides of a face outline run in opposite directions (up one side, down the