# How to invert even-odd filling?

Consider the following code. It uses eofill filling rule where only the region bounded by odd number of strokes will be filled. Is it possible to invert this rule such that the region bounded by even number of strokes will be filled?

\documentclass[pstricks,border=12pt]{standalone}

\begin{document}

\begin{pspicture}[linewidth=2pt](6,4)

\pscustom[fillcolor=blue,fillstyle=eofill,linestyle=none]
{
\psellipse(4,2)(2,2)
\moveto(4,2)
\psellipse(2,2)(2,2)
}

\psellipse[linecolor=yellow](4,2)(2,2)
\psellipse[linecolor=green](2,2)(2,2)

\end{pspicture}

\end{document}


Note: Please don't suggest solution with clipping or intersection. Answers in TikZ and Asymptote are welcome!

-
Well you have three regions so it's blue white blue. No clip no intersection how would you get white blue white ? You need an even number of pathsbut then first/last one would be blue – percusse Sep 12 '13 at 19:48
@percusse: By inverting the even-odd rule, theoretically we can get what I want to have. – kiss my armpit Sep 13 '13 at 1:32
Since zero is even, if you invert the even-odd rule, then theoretically the unbounded region outside all your paths will also be filled. Is this what you want? I'm not just being facetious: if it is, then you can simply add a huge circle or rectangle that encompasses your entire picture and use the usual even-odd rule (although I suppose this requires that you clip the picture to its bounding box; is that too much clipping?). If you don't want the outside filled, then your fill rule involves a special case and will probably require actual programming. – Charles Staats Dec 29 '13 at 19:43
@CharlesStaats: I have tried the idea with a huge circle or rectangle and I don't like the output. – kiss my armpit Dec 29 '13 at 19:45

The Postscript Language Reference does not provide, for example, an Odd-Even Rule (oefill) counterpart to the Even-Odd Rule (eofill). So, you have to find a way to retrace the entire area - specific to the shape - so that "odd" regions become "even", and "even" ones become "odd".

\documentclass[pstricks,border=5pt]{standalone}
\usepackage{pstricks}% http://tug.org/PSTricks/main.cgi/
\begin{document}
\begin{pspicture}[linewidth=2pt](6,4)
\pscustom[fillcolor=blue,fillstyle=eofill,linestyle=none,linewidth=0pt]
{%
\psellipticarc(2,2)(2,2){60}{-300}% Left (complete) ellipse/circle
\psellipticarc(4,2)(2,2){120}{-240}% Right (complete) ellipse/circle
\psellipticarc(2,2)(2,2){60}{-60}% Left (incomplete) segment
\psellipticarc(4,2)(2,2){-120}{120}% Right (incomplete) segment
}%
\psellipse[linecolor=yellow](4,2)(2,2)
\psellipse[linecolor=green](2,2)(2,2)
\end{pspicture}

\end{document}


The 4 stages of construction to recreate and retrace the shape is presented requires some explanation:

• The bizarre angles from which the shapes are drawn (say, from 60 to -300, spanning 360 degrees) is to fool TeX to draw a full revolution. Drawing an arc from 60 to 60 makes it non-existent.
• The choice for drawing these arcs based around the intersection is because the pen movement may cause some artifacts to show in the output (thin lines that have zero width, yet still show at certain zoom levels). Focusing on the intersection point as an interchange between shapes removes this annoying artifact.
-

The newest pstricks.tex provides an experimental value oefill which is the complement of eofill.

\documentclass[pstricks,border=12pt]{standalone}

\begin{document}

\begin{pspicture}[linewidth=2pt,showgrid](6,4)

\pscustom[fillstyle=oefill,fillcolor=blue,linestyle=none]
{
\psellipse(4,2)(2,2)
\moveto(4,2)
\psellipse(2,2)(2,2)
}

\psellipse[linecolor=yellow](4,2)(2,2)
\psellipse[linecolor=green](2,2)(2,2)

\end{pspicture}

\end{document}


But there are 4 problems:

1. fillstyle=oefill,fillcolor=blue cannot be swapped. In other words, fillcolor=blue,fillstyle=oefill does not produce the expected result.

2. The output gets unintentionally displaced to the right (see carefully the given output above). Probably because of white spaces that have not been disabled via %.

3. The crescent-like regions are no longer transparent because they have been filled by a solid white.
4. Clipping with odd-even rule is not possible because /oeclip does not exist.
-

How about "clearing" unwanted parts by oefill with white?

\pscustom[fillcolor=blue,fillstyle=solid,linestyle=none]
{
\psellipse(4,2)(2,2)
\moveto(4,2)
\psellipse(2,2)(2,2)
}

\psellipse[linecolor=yellow](4,2)(2,2)
\psellipse[linecolor=green](2,2)(2,2)

\pscustom[fillcolor=white,fillstyle=eofill,linestyle=none]
{
\psellipse(4,2)(2,2)
\moveto(4,2)
\psellipse(2,2)(2,2)
}

\psellipse[linecolor=yellow](4,2)(2,2)
\psellipse[linecolor=green](2,2)(2,2)


?

-
No. It is not useful for clipping. – kiss my armpit Dec 29 '13 at 17:18
So, what you want is complicated clipping rule? Must to think about this... Does this help: texample.net/tikz/examples/venn-diagram – Jori Mäntysalo Dec 29 '13 at 20:46
I am not looking for those Venn diagrams. My question is about how to invert clipping rule. – kiss my armpit Dec 29 '13 at 20:50