Open robert-g-liu opened 4 months ago
BTW, the second code snippet worked though it's sort of bad idea to share the same name path between all rays.
In this case, it doesn't really matter because the path is only available for that iteration of the loop.
But that's no excuse for the apparent bug.
The problem comes from expansion.
For the of
key, the path names do not get fully expanded:
https://github.com/pgf-tikz/pgf/blob/44f8137449b34f62bc6371bd442ae5cc98f60f18/tex/generic/pgf/frontendlayer/tikz/libraries/tikzlibraryintersections.code.tex#L138-L141
while for the sort by
key ithe given argument gets expanded:
https://github.com/pgf-tikz/pgf/blob/44f8137449b34f62bc6371bd442ae5cc98f60f18/tex/generic/pgf/frontendlayer/tikz/libraries/tikzlibraryintersections.code.tex#L123
The code compares a macro that expands to Ray 1
with a macro that expands to \Ray \i
and the sorting will fall back to no sorting.
So, as a workaround, you can do of/.expanded = {Ray \i} and Circle
or we fix the of
key:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{intersections}
\makeatletter
\tikzset{
intersection/of/.code args={#1 and #2}{%
\edef\tikz@intersect@path@a{#1}%
\edef\tikz@intersect@path@b{#2}}}
\makeatother
\begin{document}
\begin{tikzpicture}[scale=2]
\draw [name path=Circle] (5,0) circle (2);
\foreach \i in {1} {
\draw [thick, name path={Ray \i}] (0, 0) -- (7,2);
\draw [fill=red, name intersections={of = {Ray \i} and Circle, name=c, sort by={Ray \i}}]
(c-1) circle (1mm);
}
\end{tikzpicture}
\end{document}
Brief outline of the bug
In below MWE three different coding styles were given for enabling sort-by option in name intersections. The first one didn't work. Not sure why name path {Ray \i} (or {Ray\i}, {Ray-\i}) wasn't accepted in inside a \foreach loop.
BTW, the second code snippet worked though it's sort of bad idea to share the same name path between all rays.
Minimal working example (MWE)