@@ -769,7 +769,7 @@ mod impls {
769769 & rect,
770770 ) ;
771771 let alpha = params. time . sin ( ) as f32 * 0.5 + 0.5 ;
772- scene. push_layer ( Mix :: Normal , alpha, Affine :: IDENTITY , & rect) ;
772+ scene. push_layer ( Fill :: NonZero , Mix :: Normal , alpha, Affine :: IDENTITY , & rect) ;
773773 scene. fill (
774774 Fill :: NonZero ,
775775 Affine :: translate ( ( 100.0 , 100.0 ) ) * Affine :: scale ( 0.2 ) ,
@@ -1125,6 +1125,7 @@ mod impls {
11251125 let mut depth = 0 ;
11261126 for ( width, color) in & options[ ..params. complexity . min ( options. len ( ) - 1 ) ] {
11271127 scene. push_layer (
1128+ Fill :: NonZero ,
11281129 Mix :: Normal ,
11291130 0.9 ,
11301131 Affine :: IDENTITY ,
@@ -1152,7 +1153,7 @@ mod impls {
11521153 const CLIPS_PER_FILL : usize = 3 ;
11531154 for _ in 0 ..CLIPS_PER_FILL {
11541155 let rot = Affine :: rotate ( rng. random_range ( 0.0 ..PI ) ) ;
1155- scene. push_clip_layer ( translate * rot, & base_tri) ;
1156+ scene. push_clip_layer ( Fill :: NonZero , translate * rot, & base_tri) ;
11561157 }
11571158 let rot = Affine :: rotate ( rng. random_range ( 0.0 ..PI ) ) ;
11581159 let color = Color :: new ( [ rng. random ( ) , rng. random ( ) , rng. random ( ) , 1. ] ) ;
@@ -1212,7 +1213,7 @@ mod impls {
12121213 PathEl :: LineTo ( ( X0 , Y1 ) . into ( ) ) ,
12131214 PathEl :: ClosePath ,
12141215 ] ;
1215- scene. push_clip_layer ( Affine :: IDENTITY , & path) ;
1216+ scene. push_clip_layer ( Fill :: NonZero , Affine :: IDENTITY , & path) ;
12161217 }
12171218 let rect = Rect :: new ( X0 , Y0 , X1 , Y1 ) ;
12181219 scene. fill (
@@ -1243,7 +1244,11 @@ mod impls {
12431244 None ,
12441245 & make_diamond ( 1024.0 , 125.0 ) ,
12451246 ) ;
1246- scene. push_clip_layer ( Affine :: IDENTITY , & make_diamond ( 1024.0 , 150.0 ) ) ;
1247+ scene. push_clip_layer (
1248+ Fill :: NonZero ,
1249+ Affine :: IDENTITY ,
1250+ & make_diamond ( 1024.0 , 150.0 ) ,
1251+ ) ;
12471252 scene. fill (
12481253 Fill :: NonZero ,
12491254 Affine :: IDENTITY ,
@@ -1271,11 +1276,11 @@ mod impls {
12711276 scene. fill ( Fill :: NonZero , transform, & radial, None , & rect) ;
12721277 }
12731278 const COLORS : & [ Color ] = & [ palette:: css:: RED , palette:: css:: LIME , palette:: css:: BLUE ] ;
1274- scene. push_layer ( Mix :: Normal , 1.0 , transform, & rect) ;
1279+ scene. push_layer ( Fill :: NonZero , Mix :: Normal , 1.0 , transform, & rect) ;
12751280 for ( i, c) in COLORS . iter ( ) . enumerate ( ) {
12761281 let linear = Gradient :: new_linear ( ( 0.0 , 0.0 ) , ( 0.0 , 200.0 ) )
12771282 . with_stops ( [ palette:: css:: WHITE , * c] ) ;
1278- scene. push_layer ( blend, 1.0 , transform, & rect) ;
1283+ scene. push_layer ( Fill :: NonZero , blend, 1.0 , transform, & rect) ;
12791284 // squash the ellipse
12801285 let a = transform
12811286 * Affine :: translate ( ( 100. , 100. ) )
@@ -1579,7 +1584,7 @@ mod impls {
15791584 PathEl :: ClosePath ,
15801585 ]
15811586 } ;
1582- scene. push_clip_layer ( Affine :: IDENTITY , & clip) ;
1587+ scene. push_clip_layer ( Fill :: NonZero , Affine :: IDENTITY , & clip) ;
15831588 {
15841589 let text_size = 60.0 + 40.0 * ( params. time as f32 ) . sin ( ) ;
15851590 let s = "Some clipped text!" ;
@@ -1594,6 +1599,41 @@ mod impls {
15941599 }
15951600 scene. pop_layer ( ) ;
15961601
1602+ // Even-odd clip-layer demo: a self-intersecting star ("pentagram") has different results
1603+ // under non-zero vs even-odd fill rules (even-odd produces a hole).
1604+ let demo_rect = Rect :: new ( 250.0 , 20.0 , 450.0 , 220.0 ) ;
1605+ scene. fill (
1606+ Fill :: NonZero ,
1607+ Affine :: IDENTITY ,
1608+ palette:: css:: BLUE ,
1609+ None ,
1610+ & demo_rect,
1611+ ) ;
1612+ let mut star = BezPath :: new ( ) ;
1613+ let center = Point :: new ( 350.0 , 120.0 ) ;
1614+ let outer_r = 90.0 ;
1615+ let start_angle = -std:: f64:: consts:: FRAC_PI_2 ;
1616+ let pts: [ Point ; 5 ] = core:: array:: from_fn ( |i| {
1617+ let a = start_angle + ( i as f64 ) * ( 2.0 * std:: f64:: consts:: PI / 5.0 ) ;
1618+ center + Vec2 :: new ( a. cos ( ) * outer_r, a. sin ( ) * outer_r)
1619+ } ) ;
1620+ let order = [ 0_usize , 2 , 4 , 1 , 3 ] ;
1621+ star. move_to ( pts[ order[ 0 ] ] ) ;
1622+ for & idx in & order[ 1 ..] {
1623+ star. line_to ( pts[ idx] ) ;
1624+ }
1625+ star. close_path ( ) ;
1626+
1627+ scene. push_clip_layer ( Fill :: EvenOdd , Affine :: IDENTITY , & star) ;
1628+ scene. fill (
1629+ Fill :: NonZero ,
1630+ Affine :: IDENTITY ,
1631+ palette:: css:: RED ,
1632+ None ,
1633+ & demo_rect,
1634+ ) ;
1635+ scene. pop_layer ( ) ;
1636+
15971637 let large_background_rect = Rect :: new ( -1000.0 , -1000.0 , 2000.0 , 2000.0 ) ;
15981638 let inside_clip_rect = Rect :: new ( 11.0 , 13.399999999999999 , 59.0 , 56.6 ) ;
15991639 let outside_clip_rect = Rect :: new (
@@ -1606,6 +1646,7 @@ mod impls {
16061646 let scale = 2.0 ;
16071647
16081648 scene. push_layer (
1649+ Fill :: NonZero ,
16091650 BlendMode {
16101651 mix : Mix :: Normal ,
16111652 compose : Compose :: SrcOver ,
@@ -1926,6 +1967,7 @@ mod impls {
19261967 } ,
19271968 ) ;
19281969 scene. push_layer (
1970+ Fill :: NonZero ,
19291971 BlendMode :: new ( Mix :: Normal , Compose :: SrcOver ) ,
19301972 1.0 ,
19311973 Affine :: IDENTITY ,
@@ -1949,6 +1991,7 @@ mod impls {
19491991 } ,
19501992 ) ;
19511993 scene. push_luminance_mask_layer (
1994+ Fill :: NonZero ,
19521995 1.0 ,
19531996 Affine :: IDENTITY ,
19541997 & Rect {
@@ -1993,6 +2036,7 @@ mod impls {
19932036 . unwrap ( ) ;
19942037 // HACK: Porter-Duff "over" the base color, restoring full alpha
19952038 scene. push_layer (
2039+ Fill :: NonZero ,
19962040 BlendMode :: new ( Mix :: Normal , Compose :: SrcOver ) ,
19972041 1.0 ,
19982042 Affine :: IDENTITY ,
@@ -2028,6 +2072,7 @@ mod impls {
20282072 } ,
20292073 ) ;
20302074 scene. push_luminance_mask_layer (
2075+ Fill :: NonZero ,
20312076 1.0 ,
20322077 Affine :: IDENTITY ,
20332078 & Rect {
0 commit comments