pgf-tikz / pgf

A Portable Graphic Format for TeX
https://pgf-tikz.github.io/
1.15k stars 108 forks source link

`final` decoration state uses wrong coordinate transformation when remaining length is 0 #1337

Open schtandard opened 5 months ago

schtandard commented 5 months ago

Brief outline of the bug

When previous states have exactly used up the length of the decorated path, the coordinate transformation of the final state is the one belonging to the first state (usually initial). When there is some length remaining, the transformation is correct.

\pgfpointdecoratedpathlast is correct in both cases, which is probably why this is not an issue in the standard decorations.

Minimal working example (MWE)

Blue circles mark (0pt,0pt) in the initial state, the red circle marks (0pt,0pt) in the final state, the green circle marks \pgfpointdecoratedpathlast.

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{decorations}

\pgfdeclaredecoration{wrong final point}{initial}
  {%
    \state{initial}[width=1cm]
      {
        \pgfpathcircle{\pgfpoint{0pt}{0pt}}{1pt}
        \pgfsetstrokecolor{blue}
        \pgfusepath{stroke}
      }%
    \state{final}
      {
        \pgfpathcircle{\pgfpoint{0pt}{0pt}}{2pt}%
        \pgfsetstrokecolor{red}
        \pgfusepath{stroke}
        \pgfpathcircle{\pgfpointdecoratedpathlast}{2pt}
        \pgfsetstrokecolor{green}
        \pgfusepath{stroke}
      }%
  }

\begin{document}

\begin{tikzpicture}
  \draw [help lines] (0,-2) grid (4,1);
  \path [decorate, decoration=wrong final point] (0,0) -- ++(4,0);
  \path [decorate, decoration=wrong final point] (0,-1) -- ++(3.5,0);
\end{tikzpicture}

\end{document}

image