jonschz / tikz-nfold

Triple, quadruple, and n-fold paths and arrows with TikZ
LaTeX Project Public License v1.3c
11 stars 1 forks source link

pgfoffsetpath with counterclockwise path fails #13

Closed Qrrbrbirlbel closed 1 year ago

Qrrbrbirlbel commented 1 year ago

In the following document each row should show the same diagram.

The left ones are constructed clockwise, the second one is constructed counterclockwise. Both a positive or a negative offset work or fail. This only happens when the path has rounded corners and is closed.

Further tests show that even clockwise rounded closed paths fail, in this case even more catastrophic than the counterclockwise ones.

For fully rounded paths, the work around would be to use rounded corners with the offset path but even that won't work in some cases. I guess those are all some of those edge cases mentioned in the known issue.

\documentclass[tikz]{standalone}
\usetikzlibrary{nfold}
\begin{document}
\tikz[column sep=5mm, row sep=5mm, align=center, anchor=base,
      row 3/.style={shift={(.5,.5)}, scale=.5}]\matrix{
  \node at (.5,0) {clockwise}; & \node at (.5,0) {counter\\clockwise}; \\
  \draw [rounded corners=2mm] (0,0) -- (0,1) -- (1,1) -- (1,0) -- cycle[save path=\mypath];
  \draw[red]\pgfextra\pgfoffsetpath\mypath{-1mm}\endpgfextra;
  \draw[blue]\pgfextra\pgfoffsetpath\mypath{+1mm}\endpgfextra;
&
  \draw [rounded corners=2mm] (0,0) -- (1,0) -- (1,1) -- (0,1) -- cycle[save path=\mypath];
  \draw[red]\pgfextra\pgfoffsetpath\mypath{-1mm}\endpgfextra;
  \draw[blue]\pgfextra\pgfoffsetpath\mypath{+1mm}\endpgfextra;
\\
  \draw [rounded corners=2mm] (1,0) -- (0,-1) -- (-1,0) -- (0,1) -- cycle [save path=\mypath];
  \draw[red]\pgfextra\pgfoffsetpath\mypath{-1mm}\endpgfextra;
  \draw[blue]\pgfextra\pgfoffsetpath\mypath{+1mm}\endpgfextra;
&
  \draw [rounded corners=2mm] (1,0) -- (0,1) -- (-1,0) -- (0,-1) -- cycle [save path=\mypath];
  \draw[red]\pgfextra\pgfoffsetpath\mypath{-1mm}\endpgfextra;
  \draw[blue]\pgfextra\pgfoffsetpath\mypath{+1mm}\endpgfextra;
\\};
\end{document}

687673

jonschz commented 1 year ago

It turns out you only found a special case of a more general problem, which I have not fully fixed yet. I will open another issue for that.

The underlying reason was a lack of special treatment for \pgfpathclose if the final segment has length zero. Your first example came out correct by chance - the tangent of a zero-length line segment defaults to (1,0), which happens to be the tangent of the last segment in the first example but not in the others.

Thanks for reporting!