Keep open subpaths open in ReverseSubpaths::reverse_subpaths

Found while testing crates/geom/src/lib.rs:287

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
NetterSilver
2026-10-21 02:46:23 +02:00
co-authored by Claude Haiku 5.5
parent d9c924c3ba
commit 2e12bdfd91
2 changed files with 18 additions and 1 deletions
+3 -1
View File
@@ -284,7 +284,9 @@ impl ReverseSubpaths for BezPath {
kurbo::PathSeg::Cubic(c) => out.curve_to(c.p1, c.p2, c.p3),
}
}
out.close_path();
if matches!(seg_path.elements().last(), Some(kurbo::PathEl::ClosePath)) {
out.close_path();
}
}
out
}
+15
View File
@@ -108,3 +108,18 @@ fn set_rotation_keeps_center() {
}
}
}
#[test]
fn reverse_subpaths_preserves_open_and_closed() {
let mut open = BezPath::new();
open.move_to((0.0, 0.0));
open.line_to((10.0, 0.0));
open.line_to((10.0, 10.0));
let r = <BezPath as ReverseSubpaths>::reverse_subpaths(&open);
assert!(!r.elements().iter().any(|e| matches!(e, kurbo::PathEl::ClosePath)), "{:?}", r.elements());
let mut closed = open.clone();
closed.close_path();
let r = <BezPath as ReverseSubpaths>::reverse_subpaths(&closed);
assert!(matches!(r.elements().last(), Some(kurbo::PathEl::ClosePath)), "{:?}", r.elements());
}