3

The \pgfgetlastxy syntax does not seem to yield the right results for coordinates when some coordinate transformation is applied to the tikzpicture.

Yet everything is right for nodes, or when we draw the coordinate.

Is this the same issue as in Transform defined coordinates in TikZ ?

MWE

\documentclass[tikz, border=20pt]{standalone}
\begin{document}
\begin{tikzpicture}
  [
    scale=.5,
    %cm={.5,0,0,.5,(0,0)}, %also changes the measurement
    %xslant=2, 
    %transform canvas= %fixes the measurement discrepancy
    %{
    %  scale=.5,
    %},
  ]

  \coordinate 
  [
    label=a,
    %circle, draw, %fixes the measurement discrepancy
  ]
  (a) at (1,1);
  \path (a);
  \pgfgetlastxy{\lastX}{\lastY}
  \node [anchor=north]at (0,0) {\verb|\lastX| for the coordinate : \lastX};

  \node 
  [
    label=b, 
    inner sep=0pt, 
    outer sep=0pt, 
    minimum height=0pt,
  ] (b) at (1,1){};
  \path (b);
  \pgfgetlastxy{\lastX}{\lastY}
  \node [anchor=south]at (0,0) {\verb|\lastX| for the node : \lastX};

\end{tikzpicture}
\end{document}

Output

enter image description here

marsupilam
  • 6,383

1 Answers1

1

Such PGF command is just a short cut to the internal dimension register \pgf@x and \pgf@y. The definition is simpler than you think

\def\pgfgetlastxy#1#2{%
  \edef#1{\the\pgf@x}%
  \edef#2{\the\pgf@y}%
}%

That is, since all advanced calculations are done by \pgf@x/\pgf@y/\pgf@xa/etc, there is no guarantee that \pgf@x is really what you want, specially in TikZ. For TikZ, there are \tikz@lastx and \tikz@lastxsaved.

By the way, as @Salim Bou mentioned, (b.center) is a coordinate and (b) is not.

When you write \path(b)circle(0);, TikZ will take the node seriously because it wants to know where to draw the circle. In this case the result is 14...pt (0.5cm). In this case, what actually happens is something like \path(b.center)circle(0);. But when you write only \path(b);, TikZ simply has nothing to do and \pgf@x can be anything.

(when you write \path(5,5)--(b);, TikZ will find a point on the border of (b) and on point on the border of (c). I expect that the result is the x-coordinate of the point on the border. However this calculation might be done in a group so you cannot see \pgf@x changing.)

Symbol 1
  • 36,855