# How does PSTricks determine the final path direction of composite objects made by \reversepath?

Let me divide the discussion into 2 cases:

# Using \CW

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

\def\CW{\psline(2,2)(3,4)(4,1)(4,-3)}

\begin{document}
\begin{pspicture}[showgrid=top](-5,-5)(5,5)
\pscustom[fillstyle=solid,fillcolor=red,linewidth=5pt]
{
\CW
\reversepath
\scale{-1 1}
\CW
\closepath
\pscircle{1}
}
\end{pspicture}
\end{document}


Analysis

• \def\CW{\psline(2,2)(3,4)(4,1)(4,-3)} is a clockwise path when we observe at the origin.

• The following snippet "traces" the left part counter clockwise by path reversing \CW.

\CW
\reversepath

• The following snippet "traces" the right part counter clockwise by mirroring \CW vertically.

\scale{-1 1}
\CW

• The following snippet "makes" a polygon by closing the path. The polygon has counter clockwise direction.

\closepath

• The following snippet "makes" a circle which is counter clockwise by design.

\pscircle{1}

• Note that \pscustom uses nonzero rule by default. As the polygon and circle have the same direction (counte clockwise) then all points are "inside" so there is no hole. Thus the output given above is inconsistent.

# Using \CCW

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

\def\CCW{\psline(4,-3)(4,1)(3,4)(2,2)}

\begin{document}
\begin{pspicture}[showgrid=top](-5,-5)(5,5)
\pscustom[fillstyle=solid,fillcolor=red,linewidth=5pt]
{
\CCW
\reversepath
\scale{-1 1}
\CCW
\closepath
\pscircle{1}
}
\end{pspicture}
\end{document}


Analysis

• \def\CCW{\psline(4,-3)(4,1)(3,4)(2,2)} is a counter clockwise path when we observe at the origin.

• The following snippet "traces" the left part clockwise by path reversing \CCW.

\CCW
\reversepath

• The following snippet "traces" the right part clockwise by mirroring \CCW vertically.

\scale{-1 1}
\CCW

• The following snippet "makes" a polygon by closing the path. The polygon has clockwise direction.

\closepath

• The following snippet "makes" a circle which is counter clockwise by design.

\pscircle{1}

• Note that \pscustom uses nonzero rule by default. As the polygon and circle have the different direction then points in the circle becomes "outside" so there is a hole. Thus the output given above is also inconsistent.

# Question

How does PSTricks determine the final path direction of composite objects made by \reversepath? It seems to me PSTricks adds an extra \reversepath when closing the path. Please correct me.

\scale{-1 1} is the reason for the clockwise created circle.

\documentclass[border=12pt]{standalone}
\usepackage{pstricks}
\def\CW{\psline(2,2)(3,4)(4,1)(4,-3)}
\begin{document}
\begin{pspicture}[showgrid=top](-5,-5)(5,5)
\pscustom[fillstyle=solid,fillcolor=red,linewidth=5pt]
{
\CW % (2,2)(3,4)(4,1)(4,-3)
\reversepath % now (4,-3)(4,1)(3,4)(2,2)
\scale{-1 1}
\CW % (-2,2)(-3,4)(-4,1)(-4,-3)
\closepath % line from -4,-3 to 4,-3 counter clockwise path
% \pscircle moves the current path to (-1,0) !!
\pscircle(0,0){1}% clockwise: circle not filled (scale -1 1)!!
}% The inner of the circle is _not_ inside the path
\end{pspicture}
\end{document}