- 1. eoclip
- 1.1. Syntax
- 1.2. Stack Effects
- 1.3. Description
- 1.4. PostScript Level
- 1.5. Examples
- 1.6. Common Use Cases
- 1.7. Common Pitfalls
- 1.8. Error Conditions
- 1.9. Implementation Notes
- 1.10. Even-Odd Rule Details
- 1.11. Best Practices
- 1.12. Comparing Even-Odd vs Non-Zero Winding
- 1.13. Performance Considerations
- 1.14. Advanced Techniques
- 1.15. See Also
1. eoclip
Intersects the current clipping path with 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
eoclip intersects the inside of the current clipping path with the inside of the current path to produce a new, smaller current clipping path. The inside of the current path is determined by the even-odd rule, while the inside of the current clipping path is determined by whatever rule was used at the time that path was created.
The even-odd rule determines whether a point is inside by counting path crossings: an odd number means inside, an even number means outside. This rule is particularly useful for creating clipping regions with holes.
1.5. Examples
newpath
150 150 75 0 360 arc
closepath
eoclip
newpath
% Graphics clipped to circle
0 0 moveto
300 300 lineto
stroke
gsave
newpath
% Outer rectangle
50 50 moveto
250 50 lineto
250 250 lineto
50 250 lineto
closepath
% Inner rectangle (creates hole)
100 100 moveto
200 100 lineto
200 200 lineto
100 200 lineto
closepath
eoclip
newpath
% Draw something - only visible in frame
0 0 300 300 rectfill
grestore
gsave
newpath
150 150 100 0 360 arc
closepath
150 150 50 0 360 arc
closepath
eoclip
newpath
% Visible only in ring
0 0 300 300 rectfill
grestore
1.6. Common Use Cases
1.6.1. Creating Windows or Frames
/windowClip {
% Create window frame with 4 panes
gsave
newpath
% Outer frame
10 10 moveto
290 10 lineto
290 290 lineto
10 290 lineto
closepath
% Four window panes (holes)
20 20 moveto
140 20 lineto
140 140 lineto
20 140 lineto
closepath
160 20 moveto
280 20 lineto
280 140 lineto
160 140 lineto
closepath
20 160 moveto
140 160 lineto
140 280 lineto
20 280 lineto
closepath
160 160 moveto
280 160 lineto
280 280 lineto
160 280 lineto
closepath
eoclip
newpath
% Draw window content
% ...
grestore
} def
1.6.2. Text Knockout Effect
/Helvetica-Bold findfont 120 scalefont setfont
gsave
newpath
% Background rectangle
0 0 moveto
400 0 lineto
400 200 lineto
0 200 lineto
closepath
% Text as hole
50 50 moveto
(KNOCKOUT) true charpath
eoclip
newpath
% Fill everything except text
0 0 400 200 rectfill
grestore
1.7. Common Pitfalls
Different Results from clip - The even-odd rule produces different results than the non-zero winding number rule used by clip.
|
% Same path, different clipping rules
newpath
50 50 moveto
250 50 lineto
250 250 lineto
50 250 lineto
closepath
100 100 moveto
200 100 lineto
200 200 lineto
100 200 lineto
closepath
gsave
clip % Non-zero: both rectangles clipped
newpath
0 0 300 300 rectfill
grestore
gsave
eoclip % Even-odd: inner is a hole
newpath
0 0 300 300 rectfill
grestore
% Clockwise vs counterclockwise doesn't matter
newpath
150 150 100 0 360 arc closepath % Outer
150 150 50 0 360 arc closepath % Inner
eoclip % Always creates hole regardless of direction
newpath
newpath
100 100 moveto
200 200 lineto
eoclip
% Path still exists - must clear explicitly
newpath
Use for Predictable Holes - eoclip is ideal for creating holes regardless of path direction:
|
gsave
newpath
% Any direction creates same hole
outer_path
inner_path % Direction doesn't matter
eoclip
newpath
% Draw clipped content
% ...
grestore
1.8. Error Conditions
| Error | Condition |
|---|---|
[ |
Clipping path becomes too complex for implementation |
1.9. Implementation Notes
-
The even-odd rule counts path crossings to determine inside/outside
-
Path direction does not affect the clipping result
-
Multiple overlapping subpaths create alternating clipped and unclipped regions
-
The algorithm is generally simpler than the non-zero winding number rule
-
Complex clipping paths may impact rendering performance
1.10. Even-Odd Rule Details
The even-odd rule for eoclip:
-
Draw a ray from the point in any direction
-
Count the number of path segment crossings
-
If the count is odd, the point is inside
-
If the count is even, the point is outside
This produces alternating inside/outside regions for overlapping paths, making it perfect for creating holes.
1.11. Best Practices
1.11.1. Always Use with gsave/grestore
gsave
newpath
% Outer boundary
50 50 moveto
250 50 lineto
250 250 lineto
50 250 lineto
closepath
% Inner hole
100 100 moveto
200 100 lineto
200 200 lineto
100 200 lineto
closepath
eoclip
newpath
% Clipped operations
% ...
grestore
% Clip restored
1.11.2. Clear Path After eoclip
newpath
% Construct clipping path
% ...
eoclip
newpath % Important!
% Draw clipped content
1.11.3. Use for Shapes with Holes
% Good: creates predictable holes
gsave
newpath
% Border
0 0 200 200 link:/commands/references/arc/[`arc`] closepath
% Holes (any direction works)
50 50 30 30 link:/commands/references/arc/[`arc`] closepath
150 50 30 30 link:/commands/references/arc/[`arc`] closepath
50 150 30 30 link:/commands/references/arc/[`arc`] closepath
150 150 30 30 link:/commands/references/arc/[`arc`] closepath
eoclip
newpath
% Draw
% ...
grestore
1.12. Comparing Even-Odd vs Non-Zero Winding
eoclip)-
Counts crossings: odd = inside, even = outside
-
Path direction doesn’t matter
-
Simple to understand and predict
-
Natural for regions with holes
-
Alternating pattern for overlapping paths
clip)-
Counts direction of crossings
-
Path direction matters
-
More complex but more flexible
-
Can create solid clips from complex paths
-
Direction-dependent results
1.13. Performance Considerations
-
Even-odd rule calculation is generally faster than non-zero winding
-
Number of subpaths affects performance more than their complexity
-
Very large numbers of crossings may slow processing
-
Simple convex clipping regions are fastest
-
Each clip operation adds overhead
1.14. Advanced Techniques
1.14.1. Multiple Holes
/multiHoleClip {
gsave
newpath
% Outer boundary
10 10 moveto
290 10 lineto
290 290 lineto
10 290 lineto
closepath
% Add multiple holes
20 {
rand 280 mod 10 add % x
rand 280 mod 10 add % y
rand 20 mod 5 add % radius
0 360 arc closepath
} repeat
eoclip
newpath
% Draw through holes
% ...
grestore
} def
1.15. See Also
-
clip- Clip using non-zero winding rule -
clippath- Get current clipping path -
eofill- Fill using even-odd rule -
rectclip- Clip to rectangles (Level 2) -
initclip- Reset to device default -
gsave- Save graphics state -
grestore- Restore graphics state -
newpath- Clear current path -
closepath- Close current subpath