Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

\pgfpointanchor can insert spurious spaces if the anchor is an angle #946

Closed
marmotghost opened this issue Nov 6, 2020 · 4 comments
Closed
Milestone

Comments

@marmotghost
Copy link

Brief outline of the bug

\pgfpointanchor can insert spurious spaces if the anchor is an angle. This does not happen for "stringy" anchors like west.

Minimal working example (MWE)

\documentclass{article}
\usepackage{tikz}
\makeatletter
\pgfmathdeclarefunction*{x2d}{2}{%
\begingroup%
\pgf@process{\pgfpointanchor{#1}{#2}}%
\pgfmathparse{\pgf@x}%
\pgfmathsmuggle\pgfmathresult\endgroup%
}%
\pgfmathdeclarefunction*{test}{2}{%
\begingroup%
\pgfmathparse{0}%
\pgfmathsmuggle\pgfmathresult\endgroup%
}%
\makeatother
\begin{document}
\begin{tikzpicture} 
 \node[circle,draw,minimum size=2cm] (c) at (1,0) {};
 \draw (c.center)  -- ++ (0,2);
 \pgfmathparse{x2d("c","center")}
 \draw[blue,dashed] (c.center)  -- ++ (0,2);
 \pgfmathparse{x2d("c","20")}
 \draw[red,dashed] (c.center)  -- ++ (0,2);
\end{tikzpicture}
\begin{tikzpicture} 
 \node[circle,draw,minimum size=2cm] (c) at (1,0) {};
 \draw (c.center)  -- ++ (0,2);
 \pgfmathparse{test("c","center")}
 \draw[blue,dashed] (c.center)  -- ++ (0,2);
 \pgfmathparse{test("c","20")}
 \draw[red,dashed] (c.center)  -- ++ (0,2);
\end{tikzpicture}
\end{document}

Screen Shot 2020-11-06 at 9 58 48 AM

As you can see, the dashed red line gets shifted. This is not because the function uses strings (which is why there is a second picture with a function test). The problem is also absent if one uses nonnumerical anchors.

@hmenke
Copy link
Member

hmenke commented Nov 6, 2020

This is not a MWE.

@hmenke hmenke closed this as completed Nov 6, 2020
hmenke added a commit that referenced this issue Nov 6, 2020
@marmotghost
Copy link
Author

Your fix does not work.

@hmenke
Copy link
Member

hmenke commented Nov 6, 2020

Works on my machine.

@hmenke hmenke added this to the 3.1.7 milestone Nov 29, 2020
@Qrrbrbirlbel
Copy link
Contributor

Qrrbrbirlbel commented Mar 30, 2023

There are multiple spaces in the definitions of the anchors, the most common is the space after the opening {, e.g.

Some libraries don't have those spaces at all, others have %ed some of those spaces but not all or also have them after } at the end of a line:

\anchor{west}
{
\pgf@process{\radius}
\pgf@xa=\pgf@x%
\pgf@process{\centerpoint}
\advance\pgf@x by-\pgf@xa
}%
\anchor{mid west}
{%


Here's a simpler MWE.

Uncommenting any of the commented lines will place the circle at the correct point again.

In my own code, I've chosen to use \nullfont since removing the spaces in all anchors of all shapes isn't practable.

\documentclass[tikz]{standalone}
\pgfmathdeclarefunction{anglebetweencoordinates}{2}{%
  \begingroup
%    \nullfont
    \pgfmathanglebetweenpoints
      {\pgfpointanchor{#1}{center}}%
      {\pgfpointanchor{#2}{center}}%
    \pgfmathsmuggle\pgfmathresult
  \endgroup
}
\usepackage{etoolbox}
\makeatletter
%\patchcmd\pgf@anchor@rectangle@center{ \pgf@process}{\pgf@process}{}{\PatchFailed}
\makeatother
\begin{document}
\begin{tikzpicture}[nodes=draw]
\node (A) at (0,0)  {A}
 node (B) at (30:1) {B};
\draw (A.{180+anglebetweencoordinates("A","B")}) circle[radius=2pt];
\end{tikzpicture}
\end{document}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants