| 1 |
% Copyright 2019 by Mark Wibrow |
| 2 |
% |
| 3 |
% This file may be distributed and/or modified |
| 4 |
% |
| 5 |
% 1. under the LaTeX Project Public License and/or |
| 6 |
% 2. under the GNU Free Documentation License. |
| 7 |
% |
| 8 |
% See the file doc/generic/pgf/licenses/LICENSE for more details. |
| 9 |
|
| 10 |
\usepgflibrary{intersections}% |
| 11 |
|
| 12 |
% FIXME : the 'name path global' is not reset properly - and some |
| 13 |
% following 'name path' will append to it rather that reset it. |
| 14 |
|
| 15 |
\pgfkeys{% |
| 16 |
/tikz/name path global/.code={% |
| 17 |
% reset any "old" variables inherited from some other path |
| 18 |
% - we do not accidentally want to append to an old path with the |
| 19 |
% same name (or if someone provided the option twice)... |
| 20 |
\expandafter\global\expandafter\let\csname tikz@intersect@path@name@#1\endcsname=\relax |
| 21 |
\tikz@key@name@path{#1}{\gdef}% |
| 22 |
}, |
| 23 |
/tikz/name path local/.code={% |
| 24 |
\pgfkeys{/tikz/name path={#1}}% |
| 25 |
}, |
| 26 |
/tikz/name path/.code={% |
| 27 |
% hm. Do we need this "reset old option" as in 'name path global' |
| 28 |
% for this case as well? |
| 29 |
\tikz@key@name@path{#1}{\def}% |
| 30 |
}, |
| 31 |
}% |
| 32 |
|
| 33 |
% #1: the name to assign. |
| 34 |
% #2: one of '\def' or '\gdef'. |
| 35 |
\def\tikz@key@name@path#1#2{% |
| 36 |
\tikz@addmode{% |
| 37 |
\pgfsyssoftpath@getcurrentpath\tikz@intersect@temppath@round% |
| 38 |
\pgfprocessround\tikz@intersect@temppath@round\tikz@intersect@temppath% |
| 39 |
\ifx\tikz@intersect@namedpaths\pgfutil@empty% |
| 40 |
\else% |
| 41 |
\tikz@intersect@namedpaths% |
| 42 |
\fi% |
| 43 |
\tikz@intersect@addto@path@names{#1}{#2}% |
| 44 |
}% |
| 45 |
}% |
| 46 |
|
| 47 |
% #1: the name to assign. |
| 48 |
% #2: one of '\def' or '\gdef'. |
| 49 |
\def\tikz@intersect@addto@path@names#1#2{% |
| 50 |
\edef\tikz@marshal{#2\expandafter\noexpand\csname tikz@intersect@path@name@#1\endcsname}% |
| 51 |
\expandafter\expandafter\expandafter\def\expandafter\expandafter\expandafter\tikz@marshal% |
| 52 |
\expandafter\expandafter\expandafter{\expandafter\tikz@marshal\expandafter{\tikz@intersect@temppath}}% |
| 53 |
\expandafter\pgfutil@g@addto@macro\expandafter\tikz@intersect@namedpaths\expandafter{\tikz@marshal}% |
| 54 |
}% |
| 55 |
|
| 56 |
% at the end of every \path command ... |
| 57 |
\let\tikz@finish@orig=\tikz@finish |
| 58 |
\def\tikz@finish{% |
| 59 |
\tikz@finish@orig% |
| 60 |
\tikz@intersect@finish% |
| 61 |
}% |
| 62 |
|
| 63 |
% ... make the named path variables available |
| 64 |
\def\tikz@intersect@finish{% |
| 65 |
\tikz@intersect@namedpaths% |
| 66 |
}% |
| 67 |
|
| 68 |
\let\tikz@intersect@namedpaths=\pgfutil@empty |
| 69 |
\let\tikz@intersect@path@a=\pgfutil@empty |
| 70 |
\let\tikz@intersect@path@b=\pgfutil@empty |
| 71 |
\let\tikz@intersect@name=\pgfutil@empty |
| 72 |
\let\tikz@intersect@total=\pgfutil@empty |
| 73 |
|
| 74 |
\tikzset{ |
| 75 |
every scope/.append style={ |
| 76 |
execute at begin scope={\let\tikz@intersect@namedpaths@outside\tikz@intersect@namedpaths}, |
| 77 |
execute at end scope={\global\let\tikz@intersect@namedpaths\tikz@intersect@namedpaths@outside}, |
| 78 |
}, |
| 79 |
name intersections/.code={% |
| 80 |
\tikzset{/tikz/intersection/.cd, |
| 81 |
by=, |
| 82 |
#1}% |
| 83 |
\pgfutil@ifundefined{tikz@intersect@path@name@\tikz@intersect@path@a}{% |
| 84 |
\tikzerror{I do not know the path named `\tikz@intersect@path@a'. Perhaps you misspelt it}}% |
| 85 |
{\pgfutil@ifundefined{tikz@intersect@path@name@\tikz@intersect@path@b}{% |
| 86 |
\tikzerror{I do not know the path named `\tikz@intersect@path@b'. Perhaps you misspelt it}}% |
| 87 |
{% |
| 88 |
\pgfintersectionofpaths% |
| 89 |
{% |
| 90 |
\expandafter\pgfsetpath\csname tikz@intersect@path@name@\tikz@intersect@path@a\endcsname% |
| 91 |
}% |
| 92 |
{% |
| 93 |
\expandafter\pgfsetpath\csname tikz@intersect@path@name@\tikz@intersect@path@b\endcsname% |
| 94 |
}% |
| 95 |
\ifx\tikz@intersect@total\pgfutil@empty% |
| 96 |
\else% |
| 97 |
\expandafter\let\tikz@intersect@total=\pgfintersectionsolutions% |
| 98 |
\fi% |
| 99 |
\ifx\tikz@intersect@name\pgfutil@empty% |
| 100 |
\def\tikz@intersect@@name{intersection}% |
| 101 |
\else% |
| 102 |
\let\tikz@intersect@@name=\tikz@intersect@name% |
| 103 |
\fi% |
| 104 |
\pgfmathloop% |
| 105 |
\ifnum\pgfmathcounter>\pgfintersectionsolutions\relax% |
| 106 |
\else% |
| 107 |
\path[reset cm]\pgfextra{\pgftransformshift{\pgfpointintersectionsolution{\pgfmathcounter}}}% |
| 108 |
coordinate (\tikz@intersect@@name-\pgfmathcounter); |
| 109 |
\repeatpgfmathloop% |
| 110 |
\ifx\tikz@intersect@by\pgfutil@empty% |
| 111 |
\else% |
| 112 |
\foreach\tikz@intersect@name[count=\tikz@intersection@count] in \tikz@intersect@by% |
| 113 |
{\expandafter\tikz@intersect@name@parse\tikz@intersect@name\pgf@stop}% |
| 114 |
\fi% |
| 115 |
}% |
| 116 |
}% |
| 117 |
},% |
| 118 |
intersection/.cd, |
| 119 |
of/.code=\tikz@intersect@path@names@parse#1\tikz@stop,% |
| 120 |
name/.store in=\tikz@intersect@name, |
| 121 |
total/.store in=\tikz@intersect@total, |
| 122 |
by/.store in=\tikz@intersect@by, |
| 123 |
sort by/.code=\edef\tikz@intersect@sort@by{#1}\tikz@intersect@check@sort@by% |
| 124 |
}% |
| 125 |
|
| 126 |
|
| 127 |
\def\tikz@intersect@check@sort@by{% |
| 128 |
\ifx\tikz@intersect@sort@by\tikz@intersect@path@a% |
| 129 |
\pgfintersectionsortbyfirstpath% |
| 130 |
\else% |
| 131 |
\ifx\tikz@intersect@sort@by\tikz@intersect@path@b% |
| 132 |
\pgfintersectionsortbysecondpath% |
| 133 |
\else% |
| 134 |
\pgf@intersect@sortfalse% |
| 135 |
\fi% |
| 136 |
\fi% |
| 137 |
}% |
| 138 |
\def\tikz@intersect@path@names@parse#1 and #2\tikz@stop{% |
| 139 |
\def\tikz@intersect@path@a{#1}% |
| 140 |
\def\tikz@intersect@path@b{#2}% |
| 141 |
}% |
| 142 |
|
| 143 |
\def\tikz@intersect@name@parse{\pgfutil@ifnextchar[\tikz@intersect@name@parse@opt{\tikz@intersect@name@parse@opt[]}}%} |
| 144 |
\def\tikz@intersect@name@parse@opt[#1]#2\pgf@stop{% |
| 145 |
\coordinate [#1] (#2) at (\tikz@intersect@@name-\tikz@intersection@count); |
| 146 |
}% |
| 147 |
|
| 148 |
\endinput |