pgf icon indicating copy to clipboard operation
pgf copied to clipboard

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

Open keinstein opened this issue 2 years ago • 3 comments

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}

keinstein avatar Mar 28 '23 11:03 keinstein

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
}

muzimuzhi avatar Mar 28 '23 13:03 muzimuzhi

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

keinstein avatar Mar 28 '23 19:03 keinstein

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

muzimuzhi avatar Mar 28 '23 19:03 muzimuzhi