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

bend left / bend right has wrong ending using “name prefix” #1251

Open
keinstein opened this issue Mar 28, 2023 · 3 comments
Open

bend left / bend right has wrong ending using “name prefix” #1251

keinstein opened this issue Mar 28, 2023 · 3 comments
Labels

Comments

@keinstein
Copy link

Brief outline of the bug

When an edge is bended using bend left or bend right the line endings are not calculated correctly in combination with name prefix and nodes. One end ends at the shape border, the other not. If the name is given explicitely, the line is drawn correctly.

Example:

Antrieb3-crop-1

The left edge shows the error, while the right two edges show the correct behaviour.

I assume that the error is connected to the calculation or usage of \tikz@second@point in \tikz@@@to@compute@relative .

Minimal working example (MWE)

\documentclass{minimal}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[every node/.style={draw},name prefix=pre]
	\node (1) at (0,0) {};
	\node (2) at (-1.429,1.786){};
	\node (3) at (0,1.429){};
	\node (4) at (1.429,1.786){};
	\path[draw,bend left] (1) edge (2);%
	\path[draw] (3) edge (4);
	\draw[/tikz/bend right](pre3) edge (pre4);
\end{tikzpicture}
\end{document}
@muzimuzhi
Copy link
Member

muzimuzhi commented Mar 28, 2023

Try this:

\documentclass{minimal}
\usepackage{tikz}

\makeatletter
\def\tikz@@to@or@edge@@coordinate(#1){%
  % before, \tikztotarget holds the coordinate unparsed
  % \def\tikztotarget{#1}%
  % after, \tikztotarget holds the parsed coordinate, hence `name prefix` and
  % `name suffix` are taken into account
  \tikz@scan@one@point\tikz@to@use@last@coordinate@as@target(#1)%
  \tikz@to@or@edge@function% unchanged
}

\def\tikz@to@use@last@coordinate@as@target#1{%
  \iftikz@shapeborder
    \edef\tikztotarget{\tikz@shapeborder@name}%
  \else
    \edef\tikztotarget{\the\tikz@lastx,\the\tikz@lasty}%
  \fi
}
\makeatother

\begin{document}
\begin{tikzpicture}[nodes={draw}, name prefix=pre]
  \node (1) at (0,0) {1};
  \node (2) at (-1,1){2};

  \draw (1) to (2);
  \draw[out=120, in=-30] (1) to (2);
  \draw[out=90, in=-10] (1) to (pre2);

  \draw[blue, bend left] (1) to (2);
\end{tikzpicture}
\end{document}

image

In \tikz@@@to@compute@relative there's some treatment symmetric for both \tikztostart and \tikztotarget, but currently only \tikztostart represents an parsed coordinate hence takes name prefix and name suffix into account if it's a node. My patch above adds the corresponding parsing for \tikztotarget.

\def\tikz@@@to@compute@relative#1{%
  % ...
  \begingroup
    \pgfutil@ifundefined{pgf@sh@ns@\tikztostart}
    {}% \tikztostart is not a node
    {%
      {%
        % ...
        \pgfpointshapeborder{\tikztostart}{\pgfqpoint{\pgf@xc}{\pgf@yc}}%
        % ...
      }%
    }%
    \pgfutil@ifundefined{pgf@sh@ns@\tikztotarget}
    {}% \tikztotarget is not a node
    {%
      {%
        % ...
        \pgfpointshapeborder{\tikztotarget}{\pgfqpoint{\pgf@xc}{\pgf@yc}}%
        % ...
      }%
    }%
  \endgroup
}

@keinstein
Copy link
Author

The original finder just confirmed that it works. Do you integrate the fix into the next release?

@muzimuzhi
Copy link
Member

Sure, though currently development of pgf is blocked by #1116. I may (?) have the energy to work on it in next week.

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

No branches or pull requests

2 participants