Sketch MidPoint: refuse a line's own end as its midpoint (#8562)
A line's own end held at its middle shrinks the line to a point. The solve accepted that, and a later angle, tangent or parallel on the line had no direction to hold: its points went millions of millimetres away while the sketch still reported solved. MidPoint now refuses the pick, saying why, and leaves the sketch as it was. Constraints already in a design are untouched (only the command refuses). Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2106,7 +2106,7 @@ fn c_midpoint(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let cmd = "sketch.constraint.midpoint";
|
||||
let p = &super::sketch_project::project_operands(s, p, cmd, &["a", "b", "point", "line"])?;
|
||||
let p = &line_stays(s, p, cmd);
|
||||
constrain(s, p, cmd, |sk| {
|
||||
let pick = |sk: &mut Sketch| -> Result<ConstraintKind> {
|
||||
if p.get("a").is_none() && p.get("b").is_none() {
|
||||
return Ok(ConstraintKind::Midpoint { p: point_ref(sk, p.get("point"), cmd, "point")?, l: curve_ref(sk, p.get("line"), cmd, "line")? });
|
||||
}
|
||||
@@ -2139,6 +2139,18 @@ fn c_midpoint(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
}
|
||||
_ => Err(bad(cmd, "MidPoint needs a point and a line, or two lines")),
|
||||
}
|
||||
};
|
||||
constrain(s, p, cmd, |sk| {
|
||||
let k = pick(sk)?;
|
||||
// A line's own end at its middle shrinks the line to a point; an angle, tangent or
|
||||
// parallel on it afterwards had no direction to hold and threw points millions of
|
||||
// millimetres away.
|
||||
if let ConstraintKind::Midpoint { p: q, l } = k
|
||||
&& matches!(sk.curves.get(l).map(|c| &c.kind), Some(CurveKind::Line { a, b }) if *a == q || *b == q)
|
||||
{
|
||||
return Err(bad(cmd, "a line's own end can't be its midpoint: the line would shrink to a point"));
|
||||
}
|
||||
Ok(k)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -979,6 +979,10 @@ fn midpoint_rejects_wrong_picks_without_changing_the_sketch() {
|
||||
json!({"a":"l1","b":"missing"}),
|
||||
json!({"a":"l1"}),
|
||||
json!({"a":12,"b":"l1"}),
|
||||
// The line's own end: it would shrink the line to a point.
|
||||
json!({"a":"l1.end","b":"l1"}),
|
||||
json!({"a":"l1","b":"l1.start"}),
|
||||
json!({"point":"l1.end","line":"l1"}),
|
||||
] {
|
||||
let before = s.doc.to_json();
|
||||
let undo = s.undo.len();
|
||||
|
||||
Reference in New Issue
Block a user