Skip to content

Commit a01307e

Browse files
committed
Self intersecting star test
1 parent c7ca888 commit a01307e

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

star/src/turtle/elements/fill.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,4 +384,57 @@ mod tests {
384384
// they should be classified as two independent outer contours.
385385
assert_eq!(polygons.len(), 2);
386386
}
387+
388+
/// Pentagram (5-pointed star) drawn as a single self-intersecting M…Z subpath
389+
///
390+
/// The path visits the five outer tips in "skip-one" order, crossing itself five times
391+
/// and enclosing an inner pentagon whose fill depends on the fill rule:
392+
///
393+
/// - EvenOdd: hole in the center (incorrect currently)
394+
/// - NonZero: filled
395+
#[test]
396+
#[ignore = "self-intersecting single subpaths are not yet handled"]
397+
fn test_self_intersecting_pentagram() {
398+
let star = Stroke::new(
399+
Point::new(110.0, 45.0),
400+
vec![
401+
DrawCommand::LineTo {
402+
from: Point::new(110.0, 45.0),
403+
to: Point::new(162.0, 195.0),
404+
},
405+
DrawCommand::LineTo {
406+
from: Point::new(162.0, 195.0),
407+
to: Point::new(24.0, 100.0),
408+
},
409+
DrawCommand::LineTo {
410+
from: Point::new(24.0, 100.0),
411+
to: Point::new(196.0, 100.0),
412+
},
413+
DrawCommand::LineTo {
414+
from: Point::new(196.0, 100.0),
415+
to: Point::new(58.0, 195.0),
416+
},
417+
DrawCommand::LineTo {
418+
from: Point::new(58.0, 195.0),
419+
to: Point::new(110.0, 45.0),
420+
},
421+
],
422+
);
423+
424+
let evenodd = into_fill_polygons(vec![star.clone()], FillRule::EvenOdd);
425+
assert_eq!(evenodd.len(), 1, "EvenOdd: expected one outer contour");
426+
assert_eq!(
427+
evenodd[0].holes.len(),
428+
1,
429+
"EvenOdd: expected one hole (the inner pentagon)"
430+
);
431+
432+
let nonzero = into_fill_polygons(vec![star], FillRule::NonZero);
433+
assert_eq!(nonzero.len(), 1, "NonZero: expected one outer contour");
434+
assert_eq!(
435+
nonzero[0].holes.len(),
436+
0,
437+
"NonZero: expected no holes (inner pentagon is filled)"
438+
);
439+
}
387440
}

0 commit comments

Comments
 (0)