Merge pull request #10881 from dotCooCoo/fix/artboard-guide-closing-anchor

Arrange Tools: a guide whose last anchor repeats its first is not added again
This commit is contained in:
.CooCoo authored and GitHub committed 2026-12-04 18:07:08 -08:00
commit e14a044217
2 files changed
+30 -2

No files matched your search

@@ -117,13 +117,17 @@ fn traces(path: &PathData, corners: &[Point; 4]) -> bool {
if (0..n).any(|i| !straight(&sp.anchors[i], &sp.anchors[(i + 1) % n])) {
return false;
}
// A last anchor on the first one only closes the path: the check above has kept its handles on that
// point, so the corners are read without it.
let m = if sp.anchors[n - 1].p == sp.anchors[0].p { n - 1 } else { n };
let points: Vec<Point> = sp
.anchors
.iter()
.take(m)
.enumerate()
.filter_map(|(i, a)| {
let prev = sp.anchors[(i + sp.anchors.len() - 1) % sp.anchors.len()].p;
let next = sp.anchors[(i + 1) % sp.anchors.len()].p;
let prev = sp.anchors[(i + m - 1) % m].p;
let next = sp.anchors[(i + 1) % m].p;
let interior = (prev.x == a.p.x && a.p.x == next.x && a.p.y > prev.y.min(next.y) && a.p.y < prev.y.max(next.y))
|| (prev.y == a.p.y && a.p.y == next.y && a.p.x > prev.x.min(next.x) && a.p.x < prev.x.max(next.x));
(!interior).then_some(a.p)
@@ -198,6 +198,30 @@ fn collinear_midpoints_do_not_add_another_guide_or_history_step() {
}
}
#[test]
fn a_closing_anchor_on_the_first_one_does_not_add_another_guide_or_history_step() {
let mut s = session();
let r = s.execute(COMMAND, &json!({})).unwrap();
let [id] = ids(&r)[..] else { panic!("one guide: {r}") };
let b = board(&s, 0);
let corners = [Point::new(b.x0, b.y0), Point::new(b.x1, b.y0), Point::new(b.x1, b.y1), Point::new(b.x0, b.y1)];
for reverse in [false, true] {
let mut points = corners.to_vec();
if reverse {
points.reverse();
}
points.push(points[0]);
let d = Arc::make_mut(&mut s.doc_mut().unwrap().doc);
let NodeKind::Path { path, .. } = &mut d.node_mut(id).unwrap().kind else { panic!("guide path") };
*path = PathData::single(SubPath::polyline(&points, true));
let (before, n) = (s.doc().unwrap().doc.clone(), steps(&s));
let again = s.execute(COMMAND, &json!({})).unwrap();
assert_eq!(again, json!({"ids": [], "layer": r["layer"], "skipped": 1}), "reverse: {reverse}");
assert_eq!(steps(&s), n);
assert_eq!(s.doc().unwrap().doc, before);
}
}
#[test]
fn handles_along_a_side_still_match_and_handles_off_it_do_not() {
let mut s = session();