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

The check for a constraint that shrinks a curve to a point took under 1e-6
for a point. One solve could squeeze a 49 mm side to about 1.2e-6 mm and
the next take it the rest of the way, so neither solve tripped it (two
rectangles' corners made coincident, found by a local sketch fuzzer). Under
1e-5 now counts: in 4000 random sketches the constraints that still
collapsed a line went from 9 to 0, and every refusal rate stayed the same.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
semmelrinde
2026-10-29 21:52:36 +00:00
committed by GitHub
parent f6393ef211
commit d4fb5538e6
2 changed files with 25 additions and 3 deletions
+4 -3
View File
@@ -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()))
}
@@ -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();