Sketch: preserve short reference-line directions when dimensioning (#11001) (#11117)

* claim: #11001

* fix(sketch): keep short infinite references aligned
This commit is contained in:
Colin Faulkingham
2026-11-02 13:45:36 +00:00
committed by GitHub
parent 2ccca96929
commit b978eeddcd
3 changed files with 112 additions and 5 deletions
@@ -29,6 +29,44 @@ fn new_sketch() -> Session {
s
}
#[test]
fn a_short_horizontal_reference_holds_through_dimension_edits_drag_and_reopen() {
let mut s = new_sketch();
let id = s.active_sketch.unwrap();
// A saved infinite line may have very close defining points (#11001).
let sk = s.doc_mut().sketch_mut(id).unwrap();
let end = sk.add_point(Vec2::new(6.36e-8, 0.0), Some("axis.end")).unwrap();
let arm_end = sk.add_point(Vec2::new(12.0, 10.0), Some("arm.end")).unwrap();
let axis = sk.add_line_pts(0, end, Some("axis")).unwrap();
sk.curves[axis].infinite = true;
sk.curves[axis].construction = true;
sk.add_line_pts(0, arm_end, Some("arm")).unwrap();
sk.add_constraint(solidcraft_sketch::ConstraintKind::Horizontal { l: axis }, None).unwrap();
s.refresh();
let check = |s: &Session, degrees: f64| {
let state = s.model.state();
let solved = state.sketch(id).unwrap();
assert!(solved.report.ok(), "{:?}", solved.report);
let axis = solved.sketch.points[end].pos.normalized().unwrap();
let arm = solved.sketch.points[arm_end].pos.normalized().unwrap();
assert!(axis.dist(Vec2::X) < 1e-6, "the horizontal reference rotated: {axis:?}");
assert!((arm.y.atan2(arm.x) - degrees.to_radians()).abs() < 1e-6, "the free line has the wrong angle: {arm:?}");
};
let out = run(&mut s, "sketch.dimension", json!({"entities": ["axis", "arm"], "type": "angle", "value": "30 deg"}));
check(&s, 30.0);
run(&mut s, "parameters.change", json!({"name": out["param"], "expression": "15 deg"}));
check(&s, 15.0);
let at = sketch(&s).points[arm_end].pos;
run(&mut s, "sketch.drag", json!({"entity": "arm.end", "from": [at.x, at.y], "to": [14, 10]}));
run(&mut s, "sketch.drag_end", json!({}));
check(&s, 15.0);
let doc = solidcraft_doc::Document::from_json(&s.doc.to_json()).unwrap();
*s.doc_mut() = doc;
s.refresh();
check(&s, 15.0);
}
fn profiles(s: &Session) -> usize {
s.model.state().sketch(s.active_sketch.unwrap()).unwrap().profiles.len()
}