Detect smooth anchors on all open subpaths in from_bezpath

Found while testing crates/geom/src/path.rs:284-288 (MoveTo branch of PathData::from_bezpath)

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-24 02:24:59 +00:00
co-authored by Claude Haiku 5.5
parent 3b71900097
commit 7c3e8a9dc7
+18 -1
View File
@@ -281,9 +281,12 @@ impl PathData {
for el in bp.elements() {
match *el {
PathEl::MoveTo(p) => {
if let Some(sp) = cur.take()
if let Some(mut sp) = cur.take()
&& !sp.anchors.is_empty()
{
for a in &mut sp.anchors {
*a = Anchor::with_handles(a.p, a.h_in, a.h_out);
}
subpaths.push(sp);
}
cur = Some(SubPath { anchors: vec![Anchor::corner(p)], closed: false });
@@ -418,6 +421,20 @@ mod tests {
PathData::single(SubPath::polyline(&[Point::new(0.0, 0.0), Point::new(10.0, 0.0), Point::new(10.0, 10.0), Point::new(0.0, 10.0)], true))
}
#[test]
fn from_bezpath_detects_smooth_on_every_open_subpath() {
let mut bp = BezPath::new();
for _ in 0..2 {
bp.move_to((0.0, 0.0));
bp.curve_to((0.0, 10.0), (10.0, 10.0), (10.0, 0.0));
bp.curve_to((10.0, -10.0), (20.0, -10.0), (20.0, 0.0));
}
let pd = PathData::from_bezpath(&bp);
assert_eq!(pd.subpaths.len(), 2);
assert_eq!(pd.subpaths[1].anchors[1].kind, AnchorKind::Smooth);
assert_eq!(pd.subpaths[0].anchors[1].kind, pd.subpaths[1].anchors[1].kind);
}
#[test]
fn anchors_serialize_compactly_and_read_v1_maps() {
let corner = Anchor::corner(Point::new(1.0, 2.0));