1. eofill
Paints the area enclosed by the current path using the even-odd rule.
1.2. Stack Effects
| Level | Object |
|---|---|
(empty) |
No operands required |
| Level | Object |
|---|---|
(empty) |
No results |
1.3. Description
eofill paints the inside of the current path with the current color, using the even-odd rule to determine what points are inside. Except for the choice of insideness rule, the behavior of eofill is identical to that of fill.
The even-odd rule determines whether a point is inside a path by drawing a ray from that point in any direction and counting the number of path segments that the ray crosses. If this number is odd, the point is inside; if even, the point is outside. This rule is useful for creating shapes with holes.
1.5. Examples
newpath
50 50 moveto
250 50 lineto
250 250 lineto
50 250 lineto
closepath
eofill
% Outer rectangle (counterclockwise)
newpath
50 50 moveto
250 50 lineto
250 250 lineto
50 250 lineto
closepath
% Inner rectangle (same direction - creates hole)
100 100 moveto
200 100 lineto
200 200 lineto
100 200 lineto
closepath
eofill % Creates a frame (hole in center)
/drawStarEO {
% x y radius drawStarEO
/r exch def
/y exch def
/x exch def
newpath
% Five-pointed star with overlapping lines
x y r add moveto
0 1 4 {
144 mul rotate
x y r add lineto
} for
closepath
eofill
} def
150 150 75 drawStarEO
1.6. Common Use Cases
1.6.1. Creating Frames and Holes
% Circle with hole in center
newpath
200 200 100 0 360 arc
closepath
200 200 50 0 360 arc
closepath
eofill % Creates donut shape
1.7. Common Pitfalls
Different Results from fill - The even-odd rule produces different results than the non-zero winding number rule used by fill.
|
% Same path, different fill rules
newpath
100 100 moveto
200 100 lineto
200 200 lineto
100 200 lineto
closepath
150 150 moveto
180 150 lineto
180 180 lineto
150 180 lineto
closepath
gsave
fill % Non-zero: both rectangles filled
grestore
eofill % Even-odd: inner rectangle is a hole
% Clockwise vs counterclockwise doesn't matter
newpath
50 50 moveto
250 50 lineto
250 250 lineto
50 250 lineto
closepath
% Either direction creates same hole
100 100 moveto
200 200 lineto
200 100 lineto
100 200 lineto
closepath
eofill % Same result regardless of direction
Use for Shapes with Holes - eofill is ideal for shapes with holes, regardless of path direction:
|
% Multiple concentric circles
newpath
200 200 100 0 360 arc closepath
200 200 75 0 360 arc closepath
200 200 50 0 360 arc closepath
200 200 25 0 360 arc closepath
eofill % Creates ring pattern
1.9. Implementation Notes
-
The even-odd rule counts path crossings to determine inside/outside
-
Path direction does not affect the fill result
-
Multiple overlapping subpaths create alternating filled and unfilled regions
-
Very complex paths may exceed implementation limits
-
The algorithm is generally simpler than the non-zero winding number rule
1.10. Comparing Even-Odd vs Non-Zero Winding
eofill)-
Counts crossings: odd = inside, even = outside
-
Path direction doesn’t matter
-
Simple to understand and predict
-
Natural for shapes with holes
-
Alternating fill pattern for overlapping paths
fill)-
Counts direction of crossings
-
Path direction matters
-
More complex but more flexible
-
Can create solid fills from complex paths
-
Direction-dependent results
1.11. Best Practices
1.11.1. Choose Appropriate Fill Rule
% For shapes with holes, use eofill
/drawFrame {
newpath
0 0 100 0 360 arc closepath
0 0 75 0 360 arc closepath
eofill
} def
% For solid complex shapes, use fill
/drawStar {
newpath
% ... star path construction ...
fill
} def