Sketch Coincident: refuse a line's two ends, as MidPoint refuses its own end (#8611)
* Sketch Coincident: refuse a line's two ends Making a line's two ends coincident shrinks it to a point; a Parallel or Perpendicular on it afterwards has no direction to hold and a later solve could throw points far away while reporting solved, as with a line's own end as its midpoint (#8562). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Sketch Coincident: keep the own-ends test with the other Coincident tests Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
746e1c633d
commit
e4cfbbd0c3
2 files changed
+31
-1
No files matched your search
@@ -1936,7 +1936,7 @@ fn c_coincident(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let rep = solve(&mut sk.clone());
|
||||
return Ok(json!({"constraint": c.id, "existing": true, "sketch": report_json(&rep)}));
|
||||
}
|
||||
constrain(s, p, cmd, |sk| {
|
||||
let pick = |sk: &mut Sketch| -> Result<ConstraintKind> {
|
||||
if let Some((a, b)) = line_points {
|
||||
return Ok(ConstraintKind::Coincident { p: a, q: b });
|
||||
}
|
||||
@@ -1955,6 +1955,17 @@ fn c_coincident(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
}
|
||||
let c = curve_or_axis(sk, bref)?.ok_or_else(|| bad(cmd, format!("unknown entity `{bref}`")))?;
|
||||
Ok(ConstraintKind::PointOnCurve { p: a, c })
|
||||
};
|
||||
constrain(s, p, cmd, |sk| {
|
||||
let k = pick(sk)?;
|
||||
// A line's two ends on each other shrink it to a point, as a line's own end at its
|
||||
// middle does (see `c_midpoint`).
|
||||
if let ConstraintKind::Coincident { p: a, q: b } = k
|
||||
&& sk.curves.iter().any(|c| matches!(c.kind, CurveKind::Line { a: x, b: y } if (x, y) == (a, b) || (x, y) == (b, a)))
|
||||
{
|
||||
return Err(bad(cmd, "a line's two ends can't be coincident: the line would shrink to a point"));
|
||||
}
|
||||
Ok(k)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -1182,6 +1182,25 @@ fn undoing_a_defining_dimension_removes_the_parameter_too() {
|
||||
/// Coincident on two circles (or arcs) lays the second on the first: one centre and one
|
||||
/// radius, in one step, and the first stays. It used to be refused ("two curves must both be
|
||||
/// straight lines").
|
||||
#[test]
|
||||
fn coincident_refuses_a_lines_two_ends() {
|
||||
let mut s = new_sketch();
|
||||
run(&mut s, "sketch.line", json!({"points":[[0,0],[60,0]],"infer":false,"connect":false}));
|
||||
run(&mut s, "sketch.line", json!({"points":[[0,20],[60,20]],"infer":false,"connect":false}));
|
||||
// The line would shrink to a point, leaving a later Parallel or Perpendicular on it no
|
||||
// direction to hold.
|
||||
for params in [json!({"a":"l1.start","b":"l1.end"}), json!({"a":"l1.end","b":"l1.start"})] {
|
||||
let before = s.doc.to_json();
|
||||
let undo = s.undo.len();
|
||||
let err = s.execute("sketch.constraint.coincident", ¶ms).unwrap_err().to_string();
|
||||
assert!(err.contains("shrink to a point"), "{params}: {err}");
|
||||
assert_eq!(s.doc.to_json(), before, "{params}");
|
||||
assert_eq!(s.undo.len(), undo, "{params}");
|
||||
}
|
||||
// Ends of two different lines still join.
|
||||
run(&mut s, "sketch.constraint.coincident", json!({"a":"l1.end","b":"l2.end"}));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn coincident_circles_lie_on_each_other() {
|
||||
let mut s = new_sketch();
|
||||
|
||||
Reference in new issue
Block a user