Skip to content

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

Sketch: a side squeezed to a hair in two solves is refused too (#9049)

semmelrinded4fb5538e674
diff --git a/crates/engine/src/cmd/sketch.rs b/crates/engine/src/cmd/sketch.rs
index 23e1951dfb..e2c5342d0b 100644
--- a/crates/engine/src/cmd/sketch.rs
+++ b/crates/engine/src/cmd/sketch.rs
@@ -355,8 +355,9 @@ fn settle(strict: bool, rep: SolveReport, sk: &mut Sketch, unsolved: Sketch) ->
}
/// The first line or circle that solving `before` into `after` shrank to a point: longer (or
-/// wider) than 1e-3 before and shorter than 1e-6 after. A length a dimension asks for is never
-/// that short.
+/// wider) than 1e-3 before and shorter than 1e-5 after. A length a dimension asks for is never
+/// that short. 1e-6 let a side squeezed to 1.2e-6 by one solve through, and the next solve
+/// took it the rest of the way.
fn shrunk(before: &Sketch, after: &Sketch) -> Option<String> {
let size = |sk: &Sketch, i: usize| match sk.curves.get(i).map(|c| &c.kind) {
Some(CurveKind::Line { .. }) => line_pts(sk, i).map(|(a, b)| a.dist(b)),
@@ -364,7 +365,7 @@ fn shrunk(before: &Sketch, after: &Sketch) -> Option<String> {
_ => None,
};
(0..before.curves.len().min(after.curves.len()))
- .find(|&i| matches!((size(before, i), size(after, i)), (Some(b), Some(a)) if b > 1e-3 && a < 1e-6))
+ .find(|&i| matches!((size(before, i), size(after, i)), (Some(b), Some(a)) if b > 1e-3 && a < 1e-5))
.and_then(|i| after.curves.get(i).map(|c| c.id.clone()))
}
diff --git a/crates/engine/src/cmd/sketch_constraints_tests.rs b/crates/engine/src/cmd/sketch_constraints_tests.rs
index 720cc21d47..1c21d29e74 100644
--- a/crates/engine/src/cmd/sketch_constraints_tests.rs
+++ b/crates/engine/src/cmd/sketch_constraints_tests.rs
@@ -1299,6 +1299,27 @@ fn a_constraint_that_would_shrink_a_rectangle_to_a_point_is_refused() {
}
}
+/// Two rectangles, a corner of one made coincident with a corner of the other and then a second
+/// pair of corners made coincident: one solve squeezed a 49 mm side to about 1.2e-6 mm, just
+/// longer than the check took for a point, and the next took it the rest of the way, so the
+/// constraint was taken (found by a local sketch fuzzer).
+#[test]
+fn a_constraint_that_squeezes_a_side_to_a_hair_is_refused() {
+ let mut s = new_sketch();
+ for (id, p) in [
+ ("sketch.rectangle.two_point", json!({"p0": [27, 29], "p1": [1, 19]})),
+ ("sketch.rectangle.two_point", json!({"p0": [23, -8], "p1": [-21, -20]})),
+ ("sketch.constraint.perpendicular", json!({"a": "l5", "b": "l4"})),
+ ("sketch.constraint.coincident", json!({"a": "p5", "b": "p1"})),
+ ] {
+ run(&mut s, id, p);
+ }
+ let before = sketch(&s);
+ let e = s.execute("sketch.constraint.coincident", &json!({"a": "p6", "b": "p3"})).unwrap_err().to_string();
+ assert!(e.contains("shrink") && e.contains("to a point"), "{e}");
+ assert_eq!(sketch(&s), before);
+}
+
#[test]
fn coincident_circles_lie_on_each_other() {
let mut s = new_sketch();