| 1 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2 |
%%% This file is a copy of some part of PGF/Tikz. |
| 3 |
%%% It has been copied here to provide : |
| 4 |
%%% - compatibility with older PGF versions |
| 5 |
%%% - availability of PGF contributions by Christian Feuersaenger |
| 6 |
%%% which are necessary or helpful for pgfplots. |
| 7 |
%%% |
| 8 |
%%% For reasons of simplicity, I have copied the whole file, including own contributions AND |
| 9 |
%%% PGF parts. The copyrights are as they appear in PGF. |
| 10 |
%%% |
| 11 |
%%% Note that pgfplots has compatible licenses. |
| 12 |
%%% |
| 13 |
%%% This copy has been modified in the following ways: |
| 14 |
%%% - nested \input commands have been updated |
| 15 |
%%% |
| 16 |
% |
| 17 |
% Support for the contents of this file will NOT be done by the PGF/TikZ team. |
| 18 |
% Please contact the author and/or maintainer of pgfplots (Christian Feuersaenger) if you need assistance in conjunction |
| 19 |
% with the deployment of this patch or partial content of PGF. Note that the author and/or maintainer of pgfplots has no obligation to fix anything: |
| 20 |
% This file comes without any warranty as the rest of pgfplots; there is no obligation for help. |
| 21 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 22 |
%%% Date of this copy: Di 14. Nov 22:41:45 CET 2017 %%% |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
% Copyright 2008 by Mark Wibrow |
| 27 |
% |
| 28 |
% This file may be distributed and/or modified |
| 29 |
% |
| 30 |
% 1. under the LaTeX Project Public License and/or |
| 31 |
% 2. under the GNU Free Documentation License. |
| 32 |
% |
| 33 |
% See the file doc/generic/pgf/licenses/LICENSE for more details. |
| 34 |
|
| 35 |
% Note: at the time of this writing, the library has quadratic runtime. |
| 36 |
% Experimentally, it performed well while computing ~12 intersections of two |
| 37 |
% plots, each with 600 samples. It failed when the number of samples exceeded 700. |
| 38 |
|
| 39 |
\usepgflibrary{fpu} |
| 40 |
|
| 41 |
\newcount\pgf@intersect@solutions |
| 42 |
|
| 43 |
\newif\ifpgf@intersect@sort |
| 44 |
\newif\ifpgf@intersect@sort@by@second@path |
| 45 |
|
| 46 |
\def\pgfintersectionsortbyfirstpath{% |
| 47 |
\pgf@intersect@sorttrue% |
| 48 |
\pgf@intersect@sort@by@second@pathfalse% |
| 49 |
} |
| 50 |
|
| 51 |
\def\pgfintersectionsortbysecondpath{% |
| 52 |
\pgf@intersect@sorttrue% |
| 53 |
\pgf@intersect@sort@by@second@pathtrue% |
| 54 |
} |
| 55 |
|
| 56 |
% #1: the index. It starts at 1 and ends with \pgfintersectionsolutions (inclusive). |
| 57 |
% Invalid values will implicitly result in the origin. |
| 58 |
\def\pgfpointintersectionsolution#1{% |
| 59 |
\ifnum#1<1\relax% |
| 60 |
\pgfpoint@intersect@solution@orgin% |
| 61 |
\else% |
| 62 |
\ifnum#1>\pgfintersectionsolutions\relax% |
| 63 |
\pgfpoint@intersect@solution@orgin% |
| 64 |
\else% |
| 65 |
\csname pgfpoint@intersect@solution@#1\endcsname% |
| 66 |
\fi% |
| 67 |
\fi% |
| 68 |
} |
| 69 |
|
| 70 |
% Gets the segment indices of solution #1. |
| 71 |
% |
| 72 |
% #1: the solution index (i.e. the same argument as in \pgfpointintersectionsolution) |
| 73 |
% #2: [output] a macro name which will contain the segment index of the first path which contains the solution |
| 74 |
% #3: [output] a macro name which will contain the segment index of the second path which contains the solution |
| 75 |
% |
| 76 |
% Example: \pgfintersectiongetsolutionsegmentindices{0}{\first}{\second} |
| 77 |
% |
| 78 |
% -> \first may be 0 if point #0 is in the 0'th segment |
| 79 |
% -> \second may be 42 if point #0 is in the 42'th segment |
| 80 |
% |
| 81 |
% The "segment index" is actually close to the "time" of the solution. |
| 82 |
% If a solution is at "time" 42.2, it will have segment index 42. |
| 83 |
\def\pgfintersectiongetsolutionsegmentindices#1#2#3{% |
| 84 |
\ifnum#1<1\relax% |
| 85 |
\let#2=\pgfutil@empty |
| 86 |
\let#3=\pgfutil@empty |
| 87 |
\else% |
| 88 |
\ifnum#1>\pgfintersectionsolutions\relax% |
| 89 |
\let#2=\pgfutil@empty |
| 90 |
\let#3=\pgfutil@empty |
| 91 |
\else% |
| 92 |
\def\pgf@temp##1##2##3##4{% |
| 93 |
\edef#2{##1}% |
| 94 |
\edef#3{##2}% |
| 95 |
}% |
| 96 |
\expandafter\let\expandafter\pgf@tempb\csname pgf@intersect@solution@props@#1\endcsname |
| 97 |
\expandafter\pgf@temp\pgf@tempb |
| 98 |
\fi% |
| 99 |
\fi% |
| 100 |
}% |
| 101 |
|
| 102 |
% Gets the time indices of solution #1. |
| 103 |
% |
| 104 |
% #1: the solution index (i.e. the same argument as in \pgfpointintersectionsolution) |
| 105 |
% #2: [output] a macro name which will contain the time of the first path which contains the solution |
| 106 |
% It will never be empty. |
| 107 |
% #3: [output] a macro name which will contain the time of the second path which contains the solution |
| 108 |
% It will never be empty. |
| 109 |
% |
| 110 |
% Example: \pgfintersectiongetsolutiontimes{0}{\first}{\second} |
| 111 |
% |
| 112 |
% -> \first may be 0.5 if point #0 is in just in the middle of the path |
| 113 |
% -> \second may be 42.8 if point #0 is in the 42'th segment (compare |
| 114 |
% \pgfintersectiongetsolutionsegmentindices) and is at 80% of the |
| 115 |
% 42'th segment |
| 116 |
% |
| 117 |
% Note that the precise time inside of a segment may be unavailable |
| 118 |
% (currently, it is only computed for curveto paths and not |
| 119 |
% necessarily for lineto). If the precise time is unavailable, this |
| 120 |
% call will return the value of |
| 121 |
% \pgfintersectiongetsolutionsegmentindices (which is a |
| 122 |
% "coarse-grained" time). |
| 123 |
\def\pgfintersectiongetsolutiontimes#1#2#3{% |
| 124 |
\ifnum#1<1\relax% |
| 125 |
\let#2=\pgfutil@empty |
| 126 |
\let#3=\pgfutil@empty |
| 127 |
\else% |
| 128 |
\ifnum#1>\pgfintersectionsolutions\relax% |
| 129 |
\let#2=\pgfutil@empty |
| 130 |
\let#3=\pgfutil@empty |
| 131 |
\else% |
| 132 |
\def\pgf@temp##1##2##3##4{% |
| 133 |
\edef#2{##3}% |
| 134 |
\edef#3{##4}% |
| 135 |
% |
| 136 |
% check for fallback to segment indices: |
| 137 |
\ifx#2\pgfutil@empty \edef#2{##1}\fi |
| 138 |
\ifx#3\pgfutil@empty \edef#3{##2}\fi |
| 139 |
}% |
| 140 |
\expandafter\let\expandafter\pgf@tempb\csname pgf@intersect@solution@props@#1\endcsname |
| 141 |
\expandafter\pgf@temp\pgf@tempb |
| 142 |
\fi% |
| 143 |
\fi% |
| 144 |
}% |
| 145 |
|
| 146 |
\def\pgfpoint@intersect@solution@orgin{% |
| 147 |
\begingroup% |
| 148 |
\pgftransforminvert% |
| 149 |
\pgfpointorigin% |
| 150 |
\pgf@pos@transform@glob |
| 151 |
\global\pgf@x=\pgf@x% |
| 152 |
\global\pgf@y=\pgf@y% |
| 153 |
\endgroup% |
| 154 |
} |
| 155 |
|
| 156 |
% #1 code which assigns the first path using \pgfsetpath. |
| 157 |
% #2 code which assigns the second path using \pgfsetpath. |
| 158 |
% |
| 159 |
% On output, the points, their properties, and the number of points are set. |
| 160 |
% Use \pgfintersectionsolutions which expands to the number of intersections |
| 161 |
\long\def\pgfintersectionofpaths#1#2{% |
| 162 |
\begingroup% |
| 163 |
\pgfinterruptpath% |
| 164 |
#1% |
| 165 |
\pgfgetpath\pgf@intersect@path@a% |
| 166 |
\global\let\pgf@intersect@path@temp=\pgf@intersect@path@a% |
| 167 |
\endpgfinterruptpath% |
| 168 |
\endgroup% |
| 169 |
\let\pgf@intersect@path@a=\pgf@intersect@path@temp% |
| 170 |
% |
| 171 |
\begingroup% |
| 172 |
\pgfinterruptpath% |
| 173 |
#2% |
| 174 |
\pgfgetpath\pgf@intersect@path@b% |
| 175 |
\global\let\pgf@intersect@path@temp=\pgf@intersect@path@b% |
| 176 |
\endpgfinterruptpath% |
| 177 |
\endgroup% |
| 178 |
\let\pgf@intersect@path@b=\pgf@intersect@path@temp% |
| 179 |
% |
| 180 |
\pgf@intersect@solutions=0\relax% |
| 181 |
\pgf@intersect@path@reset@a |
| 182 |
% |
| 183 |
\ifpgf@intersect@sort@by@second@path% |
| 184 |
\let\pgf@intersect@temp=\pgf@intersect@path@a% |
| 185 |
\let\pgf@intersect@path@a=\pgf@intersect@path@b% |
| 186 |
\let\pgf@intersect@path@b=\pgf@intersect@temp% |
| 187 |
\fi% |
| 188 |
% |
| 189 |
\pgfprocessround\pgf@intersect@path@a\pgf@intersect@path@a% |
| 190 |
\pgfprocessround\pgf@intersect@path@b\pgf@intersect@path@b% |
| 191 |
% |
| 192 |
\let\pgf@intersect@token@after=\pgf@intersect@path@process@a% |
| 193 |
\expandafter\pgf@intersectionofpaths\pgf@intersect@path@a\pgf@stop% |
| 194 |
\edef\pgfintersectionsolutions{\the\pgf@intersect@solutions}% |
| 195 |
\pgfmathloop% |
| 196 |
\ifnum\pgfmathcounter>\pgfintersectionsolutions\relax% |
| 197 |
\else% |
| 198 |
\pgfutil@namelet{pgfpoint@intersect@solution@\pgfmathcounter}% |
| 199 |
{pgfpoint@g@intersect@solution@\pgfmathcounter}% |
| 200 |
\edef\pgf@marshal{\noexpand\pgf@intersection@set@properties{\csname pgfpoint@g@intersect@solution@\pgfmathcounter @props\endcsname}}% |
| 201 |
\pgf@marshal |
| 202 |
\ifpgf@intersect@sort% |
| 203 |
\pgfutil@namelet{pgf@intersect@solution@\pgfmathcounter @time@a}% |
| 204 |
{pgf@g@intersect@solution@\pgfmathcounter @time@a}% |
| 205 |
\fi% |
| 206 |
\repeatpgfmathloop% |
| 207 |
\ifpgf@intersect@sort% |
| 208 |
\pgfintersectionsolutionsortbytime% |
| 209 |
\fi% |
| 210 |
} |
| 211 |
|
| 212 |
\def\pgf@intersection@set@properties#1{% |
| 213 |
\pgfutil@namedef{pgf@intersect@solution@props@\pgfmathcounter}{#1}% |
| 214 |
}% |
| 215 |
|
| 216 |
% #1 a global name prefix to store properties. |
| 217 |
\def\pgf@intersection@store@properties#1{% |
| 218 |
% we store the time offsets as well and make them available programmatically: |
| 219 |
% note that \pgf@intersect@time@a and \pgf@intersect@time@b may be empty. |
| 220 |
% |
| 221 |
% However, \pgf@intersect@time@offset and |
| 222 |
% \pgf@intersect@time@offset@b are *always* valid. In fact,they |
| 223 |
% resemble a part of the time: it holds |
| 224 |
% 0 <= \pgf@intersect@time@a < 1 |
| 225 |
% and \pgf@intersect@time@offset > 0. |
| 226 |
% |
| 227 |
% If we have an intersection in segment 42 of path A, |
| 228 |
% \pgf@intersect@time@offset will be 42. The time inside of that |
| 229 |
% segment is given as number in the interval [0,1]. If it is 0.3, |
| 230 |
% the total time will be 42.3 and that number will be stored as |
| 231 |
% \pgf@intersect@time@a. |
| 232 |
% |
| 233 |
\expandafter\xdef\csname #1@props\endcsname{{\pgf@intersect@time@offset}{\pgf@intersect@time@offset@b}{\pgf@intersect@time@a}{\pgf@intersect@time@b}}% |
| 234 |
} |
| 235 |
|
| 236 |
\def\pgf@intersectionofpaths#1{% |
| 237 |
\ifx#1\pgf@stop% |
| 238 |
\let\pgf@intersect@next=\relax% |
| 239 |
\else% |
| 240 |
\ifx#1\pgfsyssoftpath@movetotoken% |
| 241 |
\let\pgf@intersect@next=\pgf@intersect@token@moveto% |
| 242 |
\else% |
| 243 |
\ifx#1\pgfsyssoftpath@linetotoken% |
| 244 |
\let\pgf@intersect@next=\pgf@intersect@token@lineto% |
| 245 |
\else% |
| 246 |
\ifx#1\pgfsyssoftpath@closepathtoken% |
| 247 |
\let\pgf@intersect@next=\pgf@intersect@token@lineto% |
| 248 |
\else% |
| 249 |
\ifx#1\pgfsyssoftpath@curvetosupportatoken% |
| 250 |
\let\pgf@intersect@next=\pgf@intersect@token@curveto% |
| 251 |
\else% |
| 252 |
\ifx#1\pgfsyssoftpath@rectcornertoken% |
| 253 |
\let\pgf@intersect@next=\pgf@intersect@token@rect% |
| 254 |
\fi% |
| 255 |
\fi% |
| 256 |
\fi% |
| 257 |
\fi% |
| 258 |
\fi% |
| 259 |
\fi% |
| 260 |
\pgf@intersect@next} |
| 261 |
|
| 262 |
\def\pgf@intersect@token@moveto#1#2{% |
| 263 |
\def\pgfpoint@intersect@start{\pgfqpoint{#1}{#2}}% |
| 264 |
\pgf@intersectionofpaths% |
| 265 |
} |
| 266 |
|
| 267 |
\def\pgf@intersect@token@lineto#1#2{% |
| 268 |
\def\pgfpoint@intersect@end{\pgfqpoint{#1}{#2}}% |
| 269 |
\def\pgf@intersect@type{line}% |
| 270 |
\pgf@intersect@token@after% |
| 271 |
} |
| 272 |
\def\pgf@intersect@token@curveto#1#2\pgfsyssoftpath@curvetosupportbtoken#3#4\pgfsyssoftpath@curvetotoken#5#6{% |
| 273 |
\def\pgfpoint@intersect@firstsupport{\pgfqpoint{#1}{#2}}% |
| 274 |
\def\pgfpoint@intersect@secondsupport{\pgfqpoint{#3}{#4}}% |
| 275 |
\def\pgfpoint@intersect@end{\pgfqpoint{#5}{#6}}% |
| 276 |
\def\pgf@intersect@type{curve}% |
| 277 |
\pgf@intersect@token@after% |
| 278 |
} |
| 279 |
|
| 280 |
\def\pgf@intersect@token@rect#1#2\pgfsyssoftpath@rectsizetoken#3#4{% |
| 281 |
\pgf@xa=#1\relax% |
| 282 |
\advance\pgf@xa by#3\relax% |
| 283 |
\pgf@ya=#2\relax% |
| 284 |
\advance\pgf@ya by#4\relax% |
| 285 |
\edef\pgf@marshal{% |
| 286 |
\noexpand\pgfsyssoftpath@movetotoken{#1}{#2}% |
| 287 |
\noexpand\pgfsyssoftpath@linetotoken{#1}{\the\pgf@ya}% |
| 288 |
\noexpand\pgfsyssoftpath@linetotoken{\the\pgf@xa}{\the\pgf@ya}% |
| 289 |
\noexpand\pgfsyssoftpath@linetotoken{\the\pgf@xa}{#2}% |
| 290 |
\noexpand\pgfsyssoftpath@closepathtoken{#1}{#2}% |
| 291 |
}% |
| 292 |
\expandafter\pgf@intersectionofpaths\pgf@marshal% |
| 293 |
} |
| 294 |
|
| 295 |
\def\pgf@intersect@path@process@a{% |
| 296 |
\pgf@intersect@path@getpoints@a% |
| 297 |
\let\pgf@intersect@token@after=\pgf@intersect@path@process@b% |
| 298 |
\pgf@intersect@path@reset@b |
| 299 |
\expandafter\pgf@intersectionofpaths\pgf@intersect@path@b\pgf@stop% |
| 300 |
\let\pgfpoint@intersect@start=\pgfpoint@intersect@end@a% |
| 301 |
\let\pgf@intersect@token@after=\pgf@intersect@path@process@a% |
| 302 |
\c@pgf@counta=\pgf@intersect@time@offset\relax% |
| 303 |
\advance\c@pgf@counta by1\relax% |
| 304 |
\edef\pgf@intersect@time@offset{\the\c@pgf@counta}% |
| 305 |
\pgf@intersectionofpaths% |
| 306 |
} |
| 307 |
|
| 308 |
\def\pgf@intersect@path@reset@a{% |
| 309 |
\def\pgf@intersect@time@offset{0}% |
| 310 |
\def\pgf@intersect@time@a{}% |
| 311 |
}% |
| 312 |
|
| 313 |
\def\pgf@intersect@path@reset@b{% |
| 314 |
\def\pgf@intersect@time@offset@b{0}% |
| 315 |
\def\pgf@intersect@time@b{}% |
| 316 |
}% |
| 317 |
|
| 318 |
\def\pgf@intersect@path@getpoints@a{% |
| 319 |
\let\pgfpoint@intersect@start@a=\pgfpoint@intersect@start% |
| 320 |
\let\pgfpoint@intersect@end@a=\pgfpoint@intersect@end% |
| 321 |
\let\pgfpoint@intersect@firstsupport@a=\pgfpoint@intersect@firstsupport% |
| 322 |
\let\pgfpoint@intersect@secondsupport@a=\pgfpoint@intersect@secondsupport% |
| 323 |
\let\pgf@intersect@type@a=\pgf@intersect@type% |
| 324 |
} |
| 325 |
|
| 326 |
\def\pgf@intersect@path@process@b{% |
| 327 |
\pgf@intersect@path@getpoints@b% |
| 328 |
\csname pgf@intersect@\pgf@intersect@type@a @and@\pgf@intersect@type@b\endcsname% |
| 329 |
\let\pgfpoint@intersect@start=\pgfpoint@intersect@end@b% |
| 330 |
\c@pgf@counta=\pgf@intersect@time@offset@b\relax% |
| 331 |
\advance\c@pgf@counta by1\relax% |
| 332 |
\edef\pgf@intersect@time@offset@b{\the\c@pgf@counta}% |
| 333 |
\pgf@intersectionofpaths} |
| 334 |
|
| 335 |
\def\pgf@intersect@path@getpoints@b{% |
| 336 |
\let\pgfpoint@intersect@start@b=\pgfpoint@intersect@start% |
| 337 |
\let\pgfpoint@intersect@end@b=\pgfpoint@intersect@end% |
| 338 |
\let\pgfpoint@intersect@firstsupport@b=\pgfpoint@intersect@firstsupport% |
| 339 |
\let\pgfpoint@intersect@secondsupport@b=\pgfpoint@intersect@secondsupport% |
| 340 |
\let\pgf@intersect@type@b=\pgf@intersect@type% |
| 341 |
} |
| 342 |
|
| 343 |
\def\pgf@intersect@line@and@line{% |
| 344 |
\pgf@intersectionoflines{\pgfpoint@intersect@start@a}{\pgfpoint@intersect@end@a}% |
| 345 |
{\pgfpoint@intersect@start@b}{\pgfpoint@intersect@end@b}% |
| 346 |
}% |
| 347 |
|
| 348 |
\def\pgf@intersect@line@and@curve{% |
| 349 |
\pgf@intersectionoflineandcurve% |
| 350 |
{\pgf@process{\pgfpoint@intersect@start@a}}{\pgf@process{\pgfpoint@intersect@end@a}}% |
| 351 |
{\pgf@process{\pgfpoint@intersect@start@b}}{\pgf@process{\pgfpoint@intersect@firstsupport@b}}% |
| 352 |
{\pgf@process{\pgfpoint@intersect@secondsupport@b}}{\pgf@process{\pgfpoint@intersect@end@b}}% |
| 353 |
} |
| 354 |
|
| 355 |
\def\pgf@intersect@curve@and@line{% |
| 356 |
\pgf@intersectionofcurveandline% |
| 357 |
{\pgf@process{\pgfpoint@intersect@start@a}}{\pgf@process{\pgfpoint@intersect@firstsupport@a}}% |
| 358 |
{\pgf@process{\pgfpoint@intersect@secondsupport@a}}{\pgf@process{\pgfpoint@intersect@end@a}}% |
| 359 |
{\pgf@process{\pgfpoint@intersect@start@b}}{\pgf@process{\pgfpoint@intersect@end@b}}% |
| 360 |
} |
| 361 |
|
| 362 |
\def\pgf@intersect@curve@and@curve{% |
| 363 |
\pgf@intersectionofcurves% |
| 364 |
{\pgf@process{\pgfpoint@intersect@start@a}}{\pgf@process{\pgfpoint@intersect@firstsupport@a}}% |
| 365 |
{\pgf@process{\pgfpoint@intersect@secondsupport@a}}{\pgf@process{\pgfpoint@intersect@end@a}}% |
| 366 |
{\pgf@process{\pgfpoint@intersect@start@b}}{\pgf@process{\pgfpoint@intersect@firstsupport@b}}% |
| 367 |
{\pgf@process{\pgfpoint@intersect@secondsupport@b}}{\pgf@process{\pgfpoint@intersect@end@b}}% |
| 368 |
} |
| 369 |
|
| 370 |
|
| 371 |
\def\pgfintersectionoflines#1#2#3#4{% |
| 372 |
\pgf@intersect@solutions=0\relax% |
| 373 |
\pgf@intersectionoflines{#1}{#2}{#3}{#4}% |
| 374 |
} |
| 375 |
|
| 376 |
\def\pgf@intersectionoflines#1#2#3#4{% |
| 377 |
\pgf@iflinesintersect{#1}{#2}{#3}{#4}% |
| 378 |
{% |
| 379 |
\pgfextract@process\pgf@intersect@solution@candidate{% |
| 380 |
% pgf@x and pgf@y are already assigned by \pgf@iflinesintersect |
| 381 |
}% |
| 382 |
\pgf@ifsolution@duplicate{\pgf@intersect@solution@candidate}{% |
| 383 |
% ah - we a duplicate. Apparently, we have a hit on an |
| 384 |
% endpoint. |
| 385 |
}{% |
| 386 |
\global\advance\pgf@intersect@solutions by1\relax% |
| 387 |
\expandafter\global\expandafter\let\csname pgfpoint@g@intersect@solution@\the\pgf@intersect@solutions\endcsname=\pgf@intersect@solution@candidate |
| 388 |
\ifpgf@intersect@sort% |
| 389 |
\pgf@xc=\pgf@x% |
| 390 |
\pgf@yc=\pgf@y% |
| 391 |
\pgf@process{\pgfpointdiff{\pgfpoint@intersect@start@a}{\pgfpoint@intersect@end@a}}% |
| 392 |
\edef\pgf@marshal{% |
| 393 |
\noexpand\pgfmathveclen@{\pgfmath@tonumber{\pgf@xa}}{\pgfmath@tonumber{\pgf@ya}}% |
| 394 |
}% |
| 395 |
\pgf@marshal% |
| 396 |
\let\pgf@intersect@length@a=\pgfmathresult% |
| 397 |
\pgf@process{\pgfpointdiff{\pgfpoint@intersect@start@a}{\pgfqpoint{\pgf@xc}{\pgf@yc}}}% |
| 398 |
\edef\pgf@marshal{% |
| 399 |
\noexpand\pgfmathveclen@{\pgfmath@tonumber{\pgf@x}}{\pgfmath@tonumber{\pgf@y}}% |
| 400 |
}% |
| 401 |
\pgf@marshal% |
| 402 |
\pgfmathdivide@{\pgfmathresult}{\pgf@intersect@length@a}% |
| 403 |
\pgf@x=\pgfmathresult pt\relax% |
| 404 |
\advance\pgf@x by\pgf@intersect@time@offset pt\relax% |
| 405 |
\edef\pgf@intersect@time@a{\pgfmath@tonumber{\pgf@x}}% |
| 406 |
\expandafter\global\expandafter\let\csname pgf@g@intersect@solution@\the\pgf@intersect@solutions @time@a\endcsname= |
| 407 |
\pgf@intersect@time@a |
| 408 |
\else |
| 409 |
\let\pgf@intersect@time@a=\pgfutil@empty |
| 410 |
\fi% |
| 411 |
\let\pgf@intersect@time@b=\pgfutil@empty |
| 412 |
\pgf@intersection@store@properties{pgfpoint@g@intersect@solution@\the\pgf@intersect@solutions}% |
| 413 |
}% |
| 414 |
% |
| 415 |
}{% |
| 416 |
}% |
| 417 |
} |
| 418 |
|
| 419 |
% Test if two lines L1 and L2 intersect. |
| 420 |
% |
| 421 |
% #1 - first point P1 on L1. |
| 422 |
% #2 - second point P2 on L1. |
| 423 |
% #3 - first point P3 on L2. |
| 424 |
% #2 - second point P4 on L2. |
| 425 |
% #5 - code executed if intersection occurs. |
| 426 |
% #6 - code executed if intersection does no occur. |
| 427 |
% |
| 428 |
% Let L1 be represented by P1+(P2-P1)s where 0<=s<=1 |
| 429 |
% Let L2 be represented by P3+(P4-P3)t where 0<=t<=1 |
| 430 |
% |
| 431 |
% Then L1 and L2 intersect at |
| 432 |
% |
| 433 |
% s = |x2-x1 x3-x1| / |x4-x3 x2-x1| |
| 434 |
% |y2-y1 y3-y1| |y4-y3 y2-y1| |
| 435 |
% |
| 436 |
% t = |x4-x3 x3-x1| / |x4-x3 x2-x1| |
| 437 |
% |y4-y3 y3-y1| |y4-y3 y2-y1| |
| 438 |
% |
| 439 |
% with 0<=s,t<=1 |
| 440 |
% |
| 441 |
% s and t do not need to be calculated: |
| 442 |
% |
| 443 |
% Let s = A / C and t = B / C |
| 444 |
% |
| 445 |
% Then 0<=s<=1 if !(C=0) && ((A=0) || ((A>0) && !(C<A)) || ((A<0) && !(C>A))) |
| 446 |
% 0<=t<=1 if !(C=0) && ((B=0) || ((B>0) && !(C<B)) || ((B<0) && !(C>B))) |
| 447 |
% |
| 448 |
\newif\ifpgf@s |
| 449 |
\newif\ifpgf@t |
| 450 |
\def\pgfiflinesintersect#1#2#3#4{% |
| 451 |
\begingroup% |
| 452 |
\pgf@iflinesintersect{\pgf@process{#1}}{\pgf@process{#2}}{\pgf@process{#3}}{\pgf@process{#4}}% |
| 453 |
{\aftergroup\pgfutil@firstoftwo}{\aftergroup\pgfutil@secondoftwo}% |
| 454 |
\endgroup% |
| 455 |
} |
| 456 |
|
| 457 |
% queried by pgfplots. Do not delete, only increase. |
| 458 |
\def\pgf@intersections@version{2}% |
| 459 |
|
| 460 |
% #1,#2: line 1 |
| 461 |
% #3,#4: line 2 |
| 462 |
\def\pgf@iflinesintersect#1#2#3#4{% |
| 463 |
% first: check bounding boxes -- but somewhat increased such that we do not |
| 464 |
% exclude "visible" hits due to rounding issues (i.e. use an upper bound): |
| 465 |
\pgf@intersect@boundingbox@reset% |
| 466 |
\pgf@intersect@boundingbox@update{#1}% |
| 467 |
\pgf@intersect@boundingbox@update{#2}% |
| 468 |
\pgf@intersect@boundingbox@assign@b% |
| 469 |
% |
| 470 |
\pgf@intersect@boundingbox@reset% |
| 471 |
\pgf@intersect@boundingbox@update{#3}% |
| 472 |
\pgf@intersect@boundingbox@update{#4}% |
| 473 |
\pgf@intersect@boundingbox@assign@a% |
| 474 |
% |
| 475 |
\pgf@intersect@boundingbox@a% |
| 476 |
\pgf@intersect@boundingbox@b% |
| 477 |
% |
| 478 |
\pgf@intersect@boundingbox@ifoverlap@upperbound{% |
| 479 |
\pgf@iflinesintersect@{#1}{#2}{#3}{#4}% |
| 480 |
}{% |
| 481 |
\let\pgf@intersect@next=\pgfutil@secondoftwo% |
| 482 |
}% |
| 483 |
\pgf@intersect@next% |
| 484 |
}% |
| 485 |
|
| 486 |
% a helper routine which simply defines \pgf@intersect@next. |
| 487 |
% |
| 488 |
% In principle, this routine is capable of computing the entire intersection... but we only invoke it after checking for bounding box overlaps. This has two reasons: |
| 489 |
% 1. robustness. almost-parallel lines could cause "dimension too large" when solving the linear equation system |
| 490 |
% XXX : I still needed to replace the linear solver by one using the FPU. Perhaps I do not need the BB check anymore? |
| 491 |
% 2. performance. I hope it is faster to first check for BB (but this is not sure in TeX) |
| 492 |
% |
| 493 |
% #1,#2: line 1 |
| 494 |
% #3,#4: line 2 |
| 495 |
\def\pgf@iflinesintersect@#1#2#3#4{% |
| 496 |
% we have two lines of sorts |
| 497 |
% l_1(s) := #1 + s * (#2 - #1), 0<= s <= 1 |
| 498 |
% and |
| 499 |
% l_2(t) := #3 + t * (#4 - #3), 0<= t <= 1 |
| 500 |
% -> |
| 501 |
% set up LGS |
| 502 |
% ( #2 - #1 ) *s + (#3-#4) * t = #3-#1 |
| 503 |
% we have a hit if 0<= s,t <= 1 . |
| 504 |
#1\relax% |
| 505 |
\pgf@xa=\pgf@x% |
| 506 |
\pgf@ya=\pgf@y% |
| 507 |
#2\relax% |
| 508 |
\pgf@xb=\pgf@x% |
| 509 |
\pgf@yb=\pgf@y% |
| 510 |
#3\relax% |
| 511 |
\pgf@xc=\pgf@x% |
| 512 |
\pgf@yc=\pgf@y% |
| 513 |
#4\relax% |
| 514 |
% |
| 515 |
% will be overwritten, remember it: |
| 516 |
\edef\pgf@intersect@A{% |
| 517 |
\pgf@xa=\the\pgf@xa\space |
| 518 |
\pgf@ya=\the\pgf@ya\space |
| 519 |
}% |
| 520 |
% |
| 521 |
% B := (2-1) |
| 522 |
\advance\pgf@xb by-\pgf@xa |
| 523 |
\advance\pgf@yb by-\pgf@ya |
| 524 |
% |
| 525 |
% A := (3-1) |
| 526 |
\advance\pgf@xa by-\pgf@xc |
| 527 |
\advance\pgf@ya by-\pgf@yc |
| 528 |
\pgf@xa=-\pgf@xa |
| 529 |
\pgf@ya=-\pgf@ya |
| 530 |
% |
| 531 |
% C := (3-4) |
| 532 |
\advance\pgf@xc by-\pgf@x |
| 533 |
\advance\pgf@yc by-\pgf@y |
| 534 |
% |
| 535 |
\begingroup |
| 536 |
% compute the |.|_1 norm of each of lines. We need to compute |
| 537 |
% tolerance factors in order to decide if we have an intersection. |
| 538 |
% line 1: compute |#2 - #1|_1 : |
| 539 |
\ifdim\pgf@xb<0sp \pgf@xb=-\pgf@xb\fi |
| 540 |
\ifdim\pgf@yb<0sp \pgf@yb=-\pgf@yb\fi |
| 541 |
\advance\pgf@xb by\pgf@yb |
| 542 |
\xdef\pgf@intersect@len@a{\pgf@sys@tonumber\pgf@xb}% |
| 543 |
% |
| 544 |
% line 2: compute |#3 - #4|_1 : |
| 545 |
\ifdim\pgf@xc<0sp \pgf@xc=-\pgf@xc\fi |
| 546 |
\ifdim\pgf@yc<0sp \pgf@yc=-\pgf@yc\fi |
| 547 |
\advance\pgf@xc by\pgf@yc |
| 548 |
\xdef\pgf@intersect@len@b{\pgf@sys@tonumber\pgf@xc}% |
| 549 |
\endgroup |
| 550 |
% |
| 551 |
\edef\pgf@marshal{% |
| 552 |
\noexpand\pgfutilsolvetwotwoleqfloat{% |
| 553 |
{\pgf@sys@tonumber\pgf@xb}{\pgf@sys@tonumber\pgf@xc}% |
| 554 |
{\pgf@sys@tonumber\pgf@yb}{\pgf@sys@tonumber\pgf@yc}% |
| 555 |
}{% |
| 556 |
{\pgf@sys@tonumber\pgf@xa}% |
| 557 |
{\pgf@sys@tonumber\pgf@ya}% |
| 558 |
}% |
| 559 |
}% |
| 560 |
\pgf@marshal |
| 561 |
% |
| 562 |
\let\pgf@intersect@next=\pgfutil@secondoftwo% |
| 563 |
\ifx\pgfmathresult\pgfutil@empty |
| 564 |
% matrix was singular. |
| 565 |
\else |
| 566 |
\def\pgf@marshal##1##2{% |
| 567 |
\global\pgf@x=##1pt % |
| 568 |
\global\pgf@y=##2pt % |
| 569 |
}% |
| 570 |
\expandafter\pgf@marshal\pgfmathresult |
| 571 |
% |
| 572 |
\def\pgf@marshal{XXXX}% this should never be read |
| 573 |
% FIRST: check line 1: |
| 574 |
\ifdim\pgf@x<0sp |
| 575 |
% let it count as hit if |
| 576 |
% || l_1(s) - l_1(0) || < eps |
| 577 |
% <=> |s| * ||#2 - #1|| < eps |
| 578 |
% and, since s< 0 here: |
| 579 |
% <=> -s * ||#2 - #1|| < eps |
| 580 |
\pgf@xa=-\pgf@intersect@len@a\pgf@x |
| 581 |
\ifdim\pgf@xa<\pgfintersectiontolerance\relax |
| 582 |
% close enough to first endpoint of line 1: |
| 583 |
\def\pgf@marshal{1}% |
| 584 |
\else |
| 585 |
\def\pgf@marshal{0}% |
| 586 |
\fi |
| 587 |
\else |
| 588 |
\ifdim\pgf@x>1pt |
| 589 |
% let it count as hit if |
| 590 |
% || l_1(s) - l_1(1) || < eps |
| 591 |
% <=> |s-1| * ||#2 - #1|| < eps |
| 592 |
% and, since s > 1 here: |
| 593 |
% <=> s * ||#2 - #1|| - ||#2 - #1|| < eps |
| 594 |
\pgf@xa=\pgf@intersect@len@a\pgf@x |
| 595 |
\advance\pgf@xa by-\pgf@intersect@len@a pt % |
| 596 |
\ifdim\pgf@xa<\pgfintersectiontolerance\relax |
| 597 |
% close enough to second endpoint of line 1: |
| 598 |
\def\pgf@marshal{1}% |
| 599 |
\else |
| 600 |
\def\pgf@marshal{0}% |
| 601 |
\fi |
| 602 |
\else |
| 603 |
% 0<= s <= 1: we have an intersection within line 1. |
| 604 |
\def\pgf@marshal{1}% |
| 605 |
\fi |
| 606 |
\fi |
| 607 |
% |
| 608 |
% SECOND: check line 2: |
| 609 |
\if1\pgf@marshal |
| 610 |
\ifdim\pgf@y<0sp |
| 611 |
% see remarks for line 1. same applies here. |
| 612 |
\pgf@xa=-\pgf@intersect@len@b\pgf@y |
| 613 |
\ifdim\pgf@xa<\pgfintersectiontolerance\relax |
| 614 |
% close enough to first endpoint of line 2: |
| 615 |
\def\pgf@marshal{1}% |
| 616 |
\else |
| 617 |
\def\pgf@marshal{0}% |
| 618 |
\fi |
| 619 |
\else |
| 620 |
\ifdim\pgf@y>1pt |
| 621 |
% see remarks for line 1. same applies here. |
| 622 |
\pgf@xa=\pgf@intersect@len@b\pgf@y |
| 623 |
\advance\pgf@xa by-\pgf@intersect@len@b pt % |
| 624 |
\ifdim\pgf@xa<\pgfintersectiontolerance\relax |
| 625 |
% close enough to second endpoint of line 2: |
| 626 |
\def\pgf@marshal{1}% |
| 627 |
\else |
| 628 |
\def\pgf@marshal{0}% |
| 629 |
\fi |
| 630 |
\else |
| 631 |
% 0<= t <= 1: we have an intersection within line 2. |
| 632 |
\def\pgf@marshal{1}% |
| 633 |
\fi |
| 634 |
\fi |
| 635 |
\fi |
| 636 |
% |
| 637 |
\if1\pgf@marshal |
| 638 |
% Ok, compute the intersection point and return it: |
| 639 |
% we use (x,y) = A + s * (B-A) |
| 640 |
% keep in mind that (s,t) == (\pgf@x,\pgf@y) |
| 641 |
\pgf@intersect@A |
| 642 |
\pgf@yc=\pgf@x |
| 643 |
\global\pgf@x=\pgf@sys@tonumber\pgf@xb\pgf@yc |
| 644 |
\global\pgf@y=\pgf@sys@tonumber\pgf@yb\pgf@yc |
| 645 |
\global\advance\pgf@x by \pgf@xa |
| 646 |
\global\advance\pgf@y by \pgf@ya |
| 647 |
\let\pgf@intersect@next=\pgfutil@firstoftwo% |
| 648 |
\fi |
| 649 |
\fi |
| 650 |
} |
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
\def\pgfintersectionoflineandcurve#1#2#3#4#5#6{% |
| 656 |
\pgf@intersect@solutions=0\relax% |
| 657 |
\pgf@intersectionoflineandcurve{#1}{#2}{#3}{#4}{#5}{#6}% |
| 658 |
} |
| 659 |
|
| 660 |
\def\pgf@intersectionoflineandcurve#1#2#3#4#5#6{% |
| 661 |
\pgf@intersectionofcurves% |
| 662 |
{\pgf@process{#1}}% |
| 663 |
{% |
| 664 |
\pgf@process{% |
| 665 |
\pgfpointadd{#1\relax\pgf@x=0.666666\pgf@x\pgf@y=0.666666\pgf@y}% |
| 666 |
{#2\relax\pgf@x=0.333333\pgf@x\pgf@y=0.333333\pgf@y}% |
| 667 |
}% |
| 668 |
}% |
| 669 |
{% |
| 670 |
\pgf@process{% |
| 671 |
\pgfpointadd{#1\relax\pgf@x=0.333333\pgf@x\pgf@y=0.333333\pgf@y}% |
| 672 |
{#2\relax\pgf@x=0.666666\pgf@x\pgf@y=0.666666\pgf@y}% |
| 673 |
}% |
| 674 |
}% |
| 675 |
{\pgf@process{#2}}% |
| 676 |
{\pgf@process{#3}}% |
| 677 |
{\pgf@process{#4}}% |
| 678 |
{\pgf@process{#5}}% |
| 679 |
{\pgf@process{#6}}% |
| 680 |
}% |
| 681 |
|
| 682 |
\def\pgf@intersectionofcurveandline#1#2#3#4#5#6{% |
| 683 |
\pgf@intersectionofcurves% |
| 684 |
{\pgf@process{#1}}% |
| 685 |
{\pgf@process{#2}}% |
| 686 |
{\pgf@process{#3}}% |
| 687 |
{\pgf@process{#4}}% |
| 688 |
{\pgf@process{#5}}% |
| 689 |
{% |
| 690 |
\pgf@process{% |
| 691 |
\pgfpointadd{#5\relax\pgf@x=0.666666\pgf@x\pgf@y=0.666666\pgf@y}% |
| 692 |
{#6\relax\pgf@x=0.333333\pgf@x\pgf@y=0.333333\pgf@y}% |
| 693 |
}% |
| 694 |
}% |
| 695 |
{% |
| 696 |
\pgf@process{% |
| 697 |
\pgfpointadd{#5\relax\pgf@x=0.333333\pgf@x\pgf@y=0.333333\pgf@y}% |
| 698 |
{#6\relax\pgf@x=0.666666\pgf@x\pgf@y=0.666666\pgf@y}% |
| 699 |
}% |
| 700 |
}% |
| 701 |
{\pgf@process{#6}}% |
| 702 |
}% |
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
\def\pgfintersectiontolerance{0.1pt} |
| 708 |
\def\pgfintersectiontoleranceupperbound{1pt} |
| 709 |
\def\pgfintersectiontolerancefactor{0.1} |
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
% Find the intersections of two bezier curves. |
| 714 |
% |
| 715 |
% #1 - #4 = curve 1. |
| 716 |
% #5 - #8 = curve 2. |
| 717 |
% #9 = the solution number. |
| 718 |
% |
| 719 |
% There is no guarantee of ordering of solutions. If there are |
| 720 |
% no solutions, the origin is returned. |
| 721 |
% |
| 722 |
\def\pgfpointintersectionofcurves#1#2#3#4#5#6#7#8#9{% |
| 723 |
\pgf@intersect@solutions=0\relax% |
| 724 |
\pgf@intersectionofcurves% |
| 725 |
{\pgf@process{#1}}{\pgf@process{#2}}{\pgf@process{#3}}{\pgf@process{#4}}% |
| 726 |
{\pgf@process{#5}}{\pgf@process{#6}}{\pgf@process{#7}}{\pgf@process{#8}}% |
| 727 |
\pgfpointintersectionsolution{#9}% |
| 728 |
} |
| 729 |
|
| 730 |
% Return any intersection points of two curves C1 and C2. |
| 731 |
% No order can be guaranteed for the solutions. |
| 732 |
% |
| 733 |
% #1, #2, #3, #4 - the points on C1 |
| 734 |
% #5, #6, #7, #8 - the points on C2 |
| 735 |
% |
| 736 |
% Returns: |
| 737 |
% |
| 738 |
% \pgf@intersect@solutions - the number of solutions. |
| 739 |
% \pgfpointintersectionsolution{<S>} - the point for soultion S. |
| 740 |
% |
| 741 |
% (Sort of) use: |
| 742 |
% |
| 743 |
% intersection(C1,C2) |
| 744 |
% S = {}; |
| 745 |
% intersection'(C1,C2); |
| 746 |
% return S; |
| 747 |
% |
| 748 |
% intersection'(C1,C2) |
| 749 |
% B1 = boundingbox(C1); |
| 750 |
% B2 = boundingbox(C2); |
| 751 |
% if intersect(B1,B2) |
| 752 |
% if (B1.width < q) and (B1.height < q) and |
| 753 |
% (B2.width < q) and (B2.height < q) |
| 754 |
% S = S + {average_of_all_points(B1,B2)}; \\ is there a better choice? |
| 755 |
% else |
| 756 |
% Q = subdivideLeft(C1); |
| 757 |
% R = subdivideRight(C1); |
| 758 |
% intersection'(C2,Q); |
| 759 |
% intersection'(C2,R); |
| 760 |
% |
| 761 |
% where q is a small value (tolerance). |
| 762 |
% |
| 763 |
\def\pgfintersectionofcurves#1#2#3#4#5#6#7#8{% |
| 764 |
\pgf@intersect@solutions=0\relax% |
| 765 |
\pgf@intersectionofcurves% |
| 766 |
{\pgf@process{#1}}{\pgf@process{#2}}{\pgf@process{#3}}{\pgf@process{#4}}% |
| 767 |
{\pgf@process{#5}}{\pgf@process{#6}}{\pgf@process{#7}}{\pgf@process{#8}}% |
| 768 |
}% |
| 769 |
\def\pgf@intersectionofcurves#1#2#3#4#5#6#7#8{% |
| 770 |
\begingroup% |
| 771 |
\dimendef\pgf@time@a=2\relax% |
| 772 |
\dimendef\pgf@time@aa=4\relax% |
| 773 |
\dimendef\pgf@time@b=6\relax% |
| 774 |
\dimendef\pgf@time@bb=8\relax% |
| 775 |
\pgf@time@a=0pt\relax% |
| 776 |
\pgf@time@aa=1pt\relax% |
| 777 |
\pgf@time@b=0pt\relax% |
| 778 |
\pgf@time@bb=1pt\relax% |
| 779 |
\let\pgf@intersect@subdivide@curve=\pgf@intersect@subdivide@curve@b% |
| 780 |
\let\pgf@curve@subdivde@after=\pgf@@intersectionofcurves% |
| 781 |
\pgf@@intersectionofcurves{#1}{#2}{#3}{#4}{#5}{#6}{#7}{#8}% |
| 782 |
\endgroup% |
| 783 |
} |
| 784 |
|
| 785 |
\def\pgf@intersect@boundingbox@assign@a{% |
| 786 |
\edef\pgf@intersect@boundingbox@a{% |
| 787 |
% lower left: |
| 788 |
\noexpand\pgf@xb=\the\pgf@xa\space% |
| 789 |
\noexpand\pgf@yb=\the\pgf@ya\space% |
| 790 |
% upper right: |
| 791 |
\noexpand\pgf@xc=\the\pgf@xb\space% |
| 792 |
\noexpand\pgf@yc=\the\pgf@yb\space% |
| 793 |
}% |
| 794 |
} |
| 795 |
\def\pgf@intersect@boundingbox@assign@b{% |
| 796 |
\edef\pgf@intersect@boundingbox@b{% |
| 797 |
% lower left: |
| 798 |
\noexpand\global\noexpand\pgf@x=\the\pgf@xa\space% |
| 799 |
\noexpand\global\noexpand\pgf@y=\the\pgf@ya\space% |
| 800 |
% upper right: |
| 801 |
\noexpand\pgf@xa=\the\pgf@xb\space% |
| 802 |
\noexpand\pgf@ya=\the\pgf@yb\space% |
| 803 |
}% |
| 804 |
} |
| 805 |
|
| 806 |
% see \pgf@intersect@boundingbox@assign@a and \pgf@intersect@boundingbox@assign@b for the naming conventions |
| 807 |
\def\pgf@intersect@boundingbox@ifoverlap{% |
| 808 |
\def\pgf@intersect@next{\pgfutil@secondoftwo}% |
| 809 |
% |
| 810 |
\ifdim\pgf@xa<\pgf@xb% |
| 811 |
\else% |
| 812 |
\ifdim\pgf@x>\pgf@xc% |
| 813 |
\else% |
| 814 |
\ifdim\pgf@ya<\pgf@yb% |
| 815 |
\else% |
| 816 |
\ifdim\pgf@y>\pgf@yc% |
| 817 |
\else% |
| 818 |
\def\pgf@intersect@next{\pgfutil@firstoftwo}% |
| 819 |
\fi |
| 820 |
\fi |
| 821 |
\fi |
| 822 |
\fi |
| 823 |
\pgf@intersect@next |
| 824 |
}% |
| 825 |
\def\pgf@intersect@boundingbox@ifoverlap@upperbound{% |
| 826 |
\begingroup |
| 827 |
\def\pgf@intersect@next{\pgfutil@secondoftwo}% |
| 828 |
% |
| 829 |
\advance\pgf@xa by+\pgfintersectiontolerance\relax |
| 830 |
\ifdim\pgf@xa<\pgf@xb% |
| 831 |
\else% |
| 832 |
\global\advance\pgf@x by-\pgfintersectiontolerance\relax |
| 833 |
\ifdim\pgf@x>\pgf@xc% |
| 834 |
\else% |
| 835 |
\advance\pgf@ya by\pgfintersectiontolerance\relax |
| 836 |
\ifdim\pgf@ya<\pgf@yb% |
| 837 |
\else% |
| 838 |
\global\advance\pgf@y by-\pgfintersectiontolerance\relax |
| 839 |
\ifdim\pgf@y>\pgf@yc% |
| 840 |
\else% |
| 841 |
\def\pgf@intersect@next{\pgfutil@firstoftwo}% |
| 842 |
\fi |
| 843 |
\fi |
| 844 |
\fi |
| 845 |
\fi |
| 846 |
\expandafter |
| 847 |
\endgroup |
| 848 |
\pgf@intersect@next |
| 849 |
}% |
| 850 |
\def\pgf@intersect@boundingbox@ifoverlap@UNUSED{% |
| 851 |
\let\pgf@intersect@next=\pgfutil@secondoftwo% |
| 852 |
\ifdim\pgf@xa<\pgf@xb% |
| 853 |
\else% |
| 854 |
\ifdim\pgf@x>\pgf@xc% |
| 855 |
\else% |
| 856 |
\ifdim\pgf@ya<\pgf@yb% |
| 857 |
\else% |
| 858 |
\ifdim\pgf@y>\pgf@yc% |
| 859 |
\else% |
| 860 |
\let\pgf@intersect@next=\pgfutil@firstoftwo% |
| 861 |
\fi |
| 862 |
\fi |
| 863 |
\fi |
| 864 |
\fi |
| 865 |
\pgf@intersect@next |
| 866 |
}% |
| 867 |
\def\pgf@@intersectionofcurves#1#2#3#4#5#6#7#8{% |
| 868 |
\pgf@intersect@boundingbox@reset% |
| 869 |
\pgf@intersect@boundingbox@update{#1}% |
| 870 |
\pgf@intersect@boundingbox@update{#2}% |
| 871 |
\pgf@intersect@boundingbox@update{#3}% |
| 872 |
\pgf@intersect@boundingbox@update{#4}% |
| 873 |
\pgf@intersect@boundingbox@assign@b% |
| 874 |
% |
| 875 |
\pgf@intersect@boundingbox@reset% |
| 876 |
\pgf@intersect@boundingbox@update{#5}% |
| 877 |
\pgf@intersect@boundingbox@update{#6}% |
| 878 |
\pgf@intersect@boundingbox@update{#7}% |
| 879 |
\pgf@intersect@boundingbox@update{#8}% |
| 880 |
\pgf@intersect@boundingbox@assign@a% |
| 881 |
% |
| 882 |
\pgf@intersect@boundingbox@a% |
| 883 |
\pgf@intersect@boundingbox@b% |
| 884 |
% |
| 885 |
\pgf@intersect@boundingbox@ifoverlap{% |
| 886 |
\pgf@@@intersectionofcurves{#1}{#2}{#3}{#4}{#5}{#6}{#7}{#8}% |
| 887 |
}{% |
| 888 |
% no overlap -- no intersection. |
| 889 |
}% |
| 890 |
} |
| 891 |
|
| 892 |
\def\pgf@@@intersectionofcurves#1#2#3#4#5#6#7#8{% |
| 893 |
% compute DIFFERENCE vectors: |
| 894 |
\advance\pgf@xc by-\pgf@xb% |
| 895 |
\advance\pgf@yc by-\pgf@yb% |
| 896 |
\advance\pgf@xa by-\pgf@x% |
| 897 |
\advance\pgf@ya by-\pgf@y% |
| 898 |
\let\pgf@intersect@subdivde=\relax% |
| 899 |
% check if both difference vectors are point wise |
| 900 |
% less than tolerance (i.e. |v|_infty < eps ). |
| 901 |
% That means that both bounding boxes are "small enough" |
| 902 |
\ifdim\pgf@xc<\pgfintersectiontolerance\relax% |
| 903 |
\ifdim\pgf@xa<\pgfintersectiontolerance\relax% |
| 904 |
\ifdim\pgf@yc<\pgfintersectiontolerance\relax% |
| 905 |
\ifdim\pgf@ya<\pgfintersectiontolerance\relax% |
| 906 |
\pgfextract@process\pgf@intersect@solution@candidate{% |
| 907 |
% set (x,y) = mean(the 4 points of the two bounding boxes): |
| 908 |
\pgf@intersect@boundingbox@a% |
| 909 |
\pgf@intersect@boundingbox@b% |
| 910 |
\pgf@x=0.25\pgf@x% |
| 911 |
\advance\pgf@x by0.25\pgf@xa% |
| 912 |
\advance\pgf@x by0.25\pgf@xb% |
| 913 |
\advance\pgf@x by0.25\pgf@xc% |
| 914 |
\pgf@y=0.25\pgf@y% |
| 915 |
\advance\pgf@y by0.25\pgf@ya% |
| 916 |
\advance\pgf@y by0.25\pgf@yb% |
| 917 |
\advance\pgf@y by0.25\pgf@yc% |
| 918 |
}% |
| 919 |
% We must avoid duplicate solutions. |
| 920 |
\let\pgf@intersect@subdivde=\pgf@stop% |
| 921 |
\pgf@ifsolution@duplicate\pgf@intersect@solution@candidate{}% |
| 922 |
{% |
| 923 |
\global\advance\pgf@intersect@solutions by1\relax% |
| 924 |
\begingroup |
| 925 |
\advance\pgf@time@a by\pgf@time@aa% |
| 926 |
\divide\pgf@time@a by2\relax% |
| 927 |
\advance\pgf@time@a by\pgf@intersect@time@offset pt\relax% |
| 928 |
\edef\pgf@intersect@time@a{\pgfmath@tonumber{\pgf@time@a}}% |
| 929 |
% |
| 930 |
\advance\pgf@time@b by\pgf@time@bb% |
| 931 |
\divide\pgf@time@b by2\relax% |
| 932 |
\advance\pgf@time@b by\pgf@intersect@time@offset@b pt\relax% |
| 933 |
\edef\pgf@intersect@time@b{\pgfmath@tonumber{\pgf@time@b}}% |
| 934 |
% |
| 935 |
\pgf@intersection@store@properties{pgfpoint@g@intersect@solution@\the\pgf@intersect@solutions}% |
| 936 |
\expandafter\global\expandafter\let% |
| 937 |
\csname pgfpoint@g@intersect@solution@\the\pgf@intersect@solutions\endcsname=% |
| 938 |
\pgf@intersect@solution@candidate% |
| 939 |
\ifpgf@intersect@sort% |
| 940 |
\expandafter\xdef% |
| 941 |
\csname pgf@g@intersect@solution@\the\pgf@intersect@solutions @time@a\endcsname% |
| 942 |
{\pgf@intersect@time@a}% |
| 943 |
\fi% |
| 944 |
\endgroup |
| 945 |
}% |
| 946 |
\fi% |
| 947 |
\fi% |
| 948 |
\fi% |
| 949 |
\fi% |
| 950 |
\ifx\pgf@intersect@subdivde\pgf@stop% |
| 951 |
\else% |
| 952 |
\pgf@intersect@subdivide@curve{#1}{#2}{#3}{#4}{#5}{#6}{#7}{#8}% |
| 953 |
\fi% |
| 954 |
} |
| 955 |
|
| 956 |
\def\pgf@intersect@subdivide@curve@b#1#2#3#4#5#6#7#8{% |
| 957 |
\begingroup% |
| 958 |
\advance\pgf@time@bb by\pgf@time@b\relax% |
| 959 |
\divide\pgf@time@bb by2\relax% |
| 960 |
\let\pgf@intersect@subdivide@curve=\pgf@intersect@subdivide@curve@a% |
| 961 |
\pgf@curve@subdivide@left{#5}{#6}{#7}{#8}{#1}{#2}{#3}{#4}% |
| 962 |
\endgroup% |
| 963 |
\begingroup% |
| 964 |
\advance\pgf@time@b by\pgf@time@bb\relax% |
| 965 |
\divide\pgf@time@b by2\relax% |
| 966 |
\let\pgf@intersect@subdivide@curve=\pgf@intersect@subdivide@curve@a% |
| 967 |
\pgf@curve@subdivide@right{#5}{#6}{#7}{#8}{#1}{#2}{#3}{#4}% |
| 968 |
\endgroup% |
| 969 |
} |
| 970 |
|
| 971 |
\def\pgf@intersect@subdivide@curve@a#1#2#3#4#5#6#7#8{% |
| 972 |
\begingroup% |
| 973 |
\advance\pgf@time@aa by\pgf@time@a\relax% |
| 974 |
\divide\pgf@time@aa by2\relax% |
| 975 |
\let\pgf@intersect@subdivide@curve=\pgf@intersect@subdivide@curve@b% |
| 976 |
\pgf@curve@subdivide@left{#5}{#6}{#7}{#8}{#1}{#2}{#3}{#4}% |
| 977 |
\endgroup% |
| 978 |
\begingroup% |
| 979 |
\advance\pgf@time@a by\pgf@time@aa\relax% |
| 980 |
\divide\pgf@time@a by2\relax% |
| 981 |
\let\pgf@intersect@subdivide@curve=\pgf@intersect@subdivide@curve@b% |
| 982 |
\pgf@curve@subdivide@right{#5}{#6}{#7}{#8}{#1}{#2}{#3}{#4}% |
| 983 |
\endgroup% |
| 984 |
} |
| 985 |
|
| 986 |
\def\pgf@intersect@boundingbox@reset{% |
| 987 |
\pgf@xa=16000pt\relax% |
| 988 |
\pgf@ya=16000pt\relax% |
| 989 |
\pgf@xb=-16000pt\relax% |
| 990 |
\pgf@yb=-16000pt\relax% |
| 991 |
} |
| 992 |
|
| 993 |
\def\pgf@intersect@boundingbox@update#1{% |
| 994 |
#1\relax% |
| 995 |
\ifdim\pgf@x<\pgf@xa\pgf@xa=\pgf@x\fi% |
| 996 |
\ifdim\pgf@y<\pgf@ya\pgf@ya=\pgf@y\fi% |
| 997 |
\ifdim\pgf@x>\pgf@xb\pgf@xb=\pgf@x\fi% |
| 998 |
\ifdim\pgf@y>\pgf@yb\pgf@yb=\pgf@y\fi% |
| 999 |
} |
| 1000 |
|
| 1001 |
% The following subroutines are part of a conversion from pgfbasic |
| 1002 |
% math to FPU. This transition is necessary due to the restricted |
| 1003 |
% accuracy of pgfbasic. In order to limit the error rate of the |
| 1004 |
% transition pgfbasic -> FPU, I chose to |
| 1005 |
% keep the old "pattern" of sorts \advance\pgf@xa by0.5\pgf@y etc and |
| 1006 |
% simply adapt to some FPU call. |
| 1007 |
% |
| 1008 |
% The following routines constitute the "adapter": |
| 1009 |
|
| 1010 |
\def\pgf@float@adapter@setxy{% |
| 1011 |
\pgfmathfloatparsenumber{\pgf@sys@tonumber\pgf@x}\let\pgf@fpu@x=\pgfmathresult |
| 1012 |
\pgfmathfloatparsenumber{\pgf@sys@tonumber\pgf@y}\let\pgf@fpu@y=\pgfmathresult |
| 1013 |
}% |
| 1014 |
\def\pgf@float@adapter@mult#1=#2*#3{% |
| 1015 |
\pgfmathfloatmultiplyfixed@{#3}{#2}% |
| 1016 |
\let#1=\pgfmathresult |
| 1017 |
}% |
| 1018 |
\def\pgf@float@adapter@advance#1by#2*#3{% |
| 1019 |
\pgfmathfloatmultiplyfixed@{#3}{#2}% |
| 1020 |
\let\pgfutil@temp=\pgfmathresult |
| 1021 |
\pgfmathfloatadd@{#1}{\pgfutil@temp}% |
| 1022 |
\let#1=\pgfmathresult |
| 1023 |
}% |
| 1024 |
|
| 1025 |
\def\pgf@float@adapter@tostring#1{% |
| 1026 |
\pgfmathfloattofixed{#1}\edef#1{\pgfmathresult pt }% |
| 1027 |
}% |
| 1028 |
|
| 1029 |
\def\pgf@curve@subdivide@left#1#2#3#4{% |
| 1030 |
% |
| 1031 |
% The left curve (from t=0 to t=.5) |
| 1032 |
% |
| 1033 |
\begingroup |
| 1034 |
#1\relax% |
| 1035 |
\pgfutil@tempdima=\pgf@x% |
| 1036 |
\pgfutil@tempdimb=\pgf@y% |
| 1037 |
\pgf@float@adapter@setxy |
| 1038 |
\pgf@float@adapter@mult\pgf@fpu@xa=.5*\pgf@fpu@x \pgf@float@adapter@mult\pgf@fpu@ya=.5*\pgf@fpu@y% |
| 1039 |
\pgf@float@adapter@mult\pgf@fpu@xb=.25*\pgf@fpu@x \pgf@float@adapter@mult\pgf@fpu@yb=.25*\pgf@fpu@y% |
| 1040 |
\pgf@float@adapter@mult\pgf@fpu@xc=.125*\pgf@fpu@x\pgf@float@adapter@mult\pgf@fpu@yc=.125*\pgf@fpu@y% |
| 1041 |
#2\relax% |
| 1042 |
\pgf@float@adapter@setxy |
| 1043 |
\pgf@float@adapter@advance\pgf@fpu@xa by.5*\pgf@fpu@x\pgf@float@adapter@advance\pgf@fpu@ya by.5*\pgf@fpu@y% |
| 1044 |
\pgf@float@adapter@advance\pgf@fpu@xb by.5*\pgf@fpu@x\pgf@float@adapter@advance\pgf@fpu@yb by.5*\pgf@fpu@y% |
| 1045 |
\pgf@float@adapter@advance\pgf@fpu@xc by.375*\pgf@fpu@x\pgf@float@adapter@advance\pgf@fpu@yc by.375*\pgf@fpu@y% |
| 1046 |
#3\relax% |
| 1047 |
\pgf@float@adapter@setxy |
| 1048 |
\pgf@float@adapter@advance\pgf@fpu@xb by.25*\pgf@fpu@x\pgf@float@adapter@advance\pgf@fpu@yb by.25*\pgf@fpu@y% |
| 1049 |
\pgf@float@adapter@advance\pgf@fpu@xc by.375*\pgf@fpu@x\pgf@float@adapter@advance\pgf@fpu@yc by.375*\pgf@fpu@y% |
| 1050 |
#4\relax% |
| 1051 |
\pgf@float@adapter@setxy |
| 1052 |
\pgf@float@adapter@advance\pgf@fpu@xc by.125*\pgf@fpu@x\pgf@float@adapter@advance\pgf@fpu@yc by.125*\pgf@fpu@y% |
| 1053 |
% |
| 1054 |
\pgf@float@adapter@tostring\pgf@fpu@xa |
| 1055 |
\pgf@float@adapter@tostring\pgf@fpu@ya |
| 1056 |
\pgf@float@adapter@tostring\pgf@fpu@xb |
| 1057 |
\pgf@float@adapter@tostring\pgf@fpu@yb |
| 1058 |
\pgf@float@adapter@tostring\pgf@fpu@xc |
| 1059 |
\pgf@float@adapter@tostring\pgf@fpu@yc |
| 1060 |
\edef\pgf@marshal{% |
| 1061 |
\noexpand\pgf@curve@subdivde@after% |
| 1062 |
{\noexpand\pgf@x=\the\pgfutil@tempdima\noexpand\pgf@y=\the\pgfutil@tempdimb}% |
| 1063 |
{\noexpand\pgf@x=\pgf@fpu@xa\noexpand\pgf@y=\pgf@fpu@ya}% |
| 1064 |
{\noexpand\pgf@x=\pgf@fpu@xb\noexpand\pgf@y=\pgf@fpu@yb} |
| 1065 |
{\noexpand\pgf@x=\pgf@fpu@xc\noexpand\pgf@y=\pgf@fpu@yc}% |
| 1066 |
}% |
| 1067 |
\expandafter |
| 1068 |
\endgroup |
| 1069 |
\pgf@marshal% |
| 1070 |
} |
| 1071 |
|
| 1072 |
\def\pgf@curve@subdivide@right#1#2#3#4{% |
| 1073 |
% |
| 1074 |
% The right curve (from t=0.5 to t=1) |
| 1075 |
% |
| 1076 |
\begingroup |
| 1077 |
#1\relax% |
| 1078 |
\pgf@float@adapter@setxy |
| 1079 |
\pgf@float@adapter@mult\pgf@float@tmpa=.125*\pgf@fpu@x\pgf@float@adapter@mult\pgf@float@tmpb=.125*\pgf@fpu@y% |
| 1080 |
#2\relax% |
| 1081 |
\pgf@float@adapter@setxy |
| 1082 |
\pgf@float@adapter@advance\pgf@float@tmpa by.375*\pgf@fpu@x\pgf@float@adapter@advance\pgf@float@tmpb by.375*\pgf@fpu@y% |
| 1083 |
\pgf@float@adapter@mult\pgf@fpu@xa=.25*\pgf@fpu@x\pgf@float@adapter@mult\pgf@fpu@ya=.25*\pgf@fpu@y% |
| 1084 |
#3\relax% |
| 1085 |
\pgf@float@adapter@setxy |
| 1086 |
\pgf@float@adapter@advance\pgf@float@tmpa by.375*\pgf@fpu@x\pgf@float@adapter@advance\pgf@float@tmpb by.375*\pgf@fpu@y% |
| 1087 |
\pgf@float@adapter@advance\pgf@fpu@xa by.5*\pgf@fpu@x\pgf@float@adapter@advance\pgf@fpu@ya by.5*\pgf@fpu@y% |
| 1088 |
\pgf@float@adapter@mult\pgf@fpu@xb=.5*\pgf@fpu@x\pgf@float@adapter@mult\pgf@fpu@yb=.5*\pgf@fpu@y% |
| 1089 |
#4\relax% |
| 1090 |
\pgf@float@adapter@setxy |
| 1091 |
\pgf@float@adapter@advance\pgf@float@tmpa by.125*\pgf@fpu@x\pgf@float@adapter@advance\pgf@float@tmpb by.125*\pgf@fpu@y% |
| 1092 |
\pgf@float@adapter@advance\pgf@fpu@xa by.25*\pgf@fpu@x\pgf@float@adapter@advance\pgf@fpu@ya by.25*\pgf@fpu@y% |
| 1093 |
\pgf@float@adapter@advance\pgf@fpu@xb by.5*\pgf@fpu@x\pgf@float@adapter@advance\pgf@fpu@yb by.5*\pgf@fpu@y% |
| 1094 |
\let\pgf@fpu@xc=\pgf@fpu@x\let\pgf@fpu@yc=\pgf@fpu@y% |
| 1095 |
% |
| 1096 |
\pgf@float@adapter@tostring\pgf@float@tmpa |
| 1097 |
\pgf@float@adapter@tostring\pgf@float@tmpb |
| 1098 |
\pgf@float@adapter@tostring\pgf@fpu@xa |
| 1099 |
\pgf@float@adapter@tostring\pgf@fpu@ya |
| 1100 |
\pgf@float@adapter@tostring\pgf@fpu@xb |
| 1101 |
\pgf@float@adapter@tostring\pgf@fpu@yb |
| 1102 |
\pgf@float@adapter@tostring\pgf@fpu@xc |
| 1103 |
\pgf@float@adapter@tostring\pgf@fpu@yc |
| 1104 |
\edef\pgf@marshal{% |
| 1105 |
\noexpand\pgf@curve@subdivde@after% |
| 1106 |
{\noexpand\pgf@x=\pgf@float@tmpa\noexpand\pgf@y=\pgf@float@tmpb}% |
| 1107 |
{\noexpand\pgf@x=\pgf@fpu@xa\noexpand\pgf@y=\pgf@fpu@ya} |
| 1108 |
{\noexpand\pgf@x=\pgf@fpu@xb\noexpand\pgf@y=\pgf@fpu@yb} |
| 1109 |
{\noexpand\pgf@x=\pgf@fpu@xc\noexpand\pgf@y=\pgf@fpu@yc}% |
| 1110 |
}% |
| 1111 |
\expandafter |
| 1112 |
\endgroup |
| 1113 |
\pgf@marshal% |
| 1114 |
} |
| 1115 |
|
| 1116 |
|
| 1117 |
% A solution S1 is considered a duplicate of S2, if |
| 1118 |
% |
| 1119 |
% |x1 - x2|f < q and |y1 - y2|f < q |
| 1120 |
% |
| 1121 |
% where q is a small value (tolerance). |
| 1122 |
% |
| 1123 |
% #1 - the solution. |
| 1124 |
% |
| 1125 |
\def\pgf@ifsolution@duplicate#1{% |
| 1126 |
#1% |
| 1127 |
\pgf@xa=\pgf@x% |
| 1128 |
\pgf@ya=\pgf@y% |
| 1129 |
\let\pgf@intersect@next=\pgfutil@secondoftwo% |
| 1130 |
\pgfmathloop% |
| 1131 |
\ifnum\pgfmathcounter>\pgf@intersect@solutions\relax% |
| 1132 |
\else% |
| 1133 |
\pgf@ifsolution@duplicate@{\pgfmathcounter}% |
| 1134 |
\repeatpgfmathloop% |
| 1135 |
\pgf@intersect@next% |
| 1136 |
} |
| 1137 |
|
| 1138 |
\def\pgf@ifsolution@duplicate@#1{% |
| 1139 |
\pgf@process{\csname pgfpoint@g@intersect@solution@#1\endcsname}% |
| 1140 |
\advance\pgf@x by-\pgf@xa% |
| 1141 |
\advance\pgf@y by-\pgf@ya% |
| 1142 |
\ifdim\pgf@x<0pt\relax\pgf@x=-\pgf@x\fi% |
| 1143 |
\ifdim\pgf@y<0pt\relax\pgf@y=-\pgf@y\fi% |
| 1144 |
% |
| 1145 |
\pgf@x=\pgfintersectiontolerancefactor\pgf@x% |
| 1146 |
\pgf@y=\pgfintersectiontolerancefactor\pgf@y% |
| 1147 |
\ifdim\pgf@x<\pgfintersectiontolerance\relax% |
| 1148 |
\ifdim\pgf@y<\pgfintersectiontolerance\relax% |
| 1149 |
\let\pgf@intersect@next=\pgfutil@firstoftwo% |
| 1150 |
\fi% |
| 1151 |
\fi% |
| 1152 |
}% |
| 1153 |
|
| 1154 |
\newif\ifpgf@intersect@solutions@sortfinish |
| 1155 |
|
| 1156 |
% Sort solutions according to their time index. |
| 1157 |
% |
| 1158 |
\def\pgfintersectionsolutionsortbytime{% |
| 1159 |
\pgf@intersect@solutions@sortfinishtrue% |
| 1160 |
\pgfmathloop% |
| 1161 |
\ifnum\pgfmathcounter<\pgfintersectionsolutions\relax% |
| 1162 |
\pgfutil@tempcnta=\pgfmathcounter% |
| 1163 |
\advance\pgfutil@tempcnta by1\relax% |
| 1164 |
\ifdim\csname pgf@intersect@solution@\pgfmathcounter @time@a\endcsname pt>% |
| 1165 |
\csname pgf@intersect@solution@\the\pgfutil@tempcnta @time@a\endcsname pt\relax% |
| 1166 |
\pgf@intersect@solutions@sortfinishfalse% |
| 1167 |
% |
| 1168 |
\pgfintersectionsolutionsortbytime@swap{pgfpoint@intersect@solution@\pgfmathcounter}% |
| 1169 |
{pgfpoint@intersect@solution@\the\pgfutil@tempcnta}% |
| 1170 |
% |
| 1171 |
\pgfintersectionsolutionsortbytime@swap{pgf@intersect@solution@\pgfmathcounter @time@a}% |
| 1172 |
{pgf@intersect@solution@\the\pgfutil@tempcnta @time@a}% |
| 1173 |
% |
| 1174 |
\pgfintersectionsolutionsortbytime@swap{pgf@intersect@solution@props@\pgfmathcounter}% |
| 1175 |
{pgf@intersect@solution@props@\the\pgfutil@tempcnta}% |
| 1176 |
\fi% |
| 1177 |
\repeatpgfmathloop% |
| 1178 |
\ifpgf@intersect@solutions@sortfinish% |
| 1179 |
\else% |
| 1180 |
\expandafter\pgfintersectionsolutionsortbytime% |
| 1181 |
\fi% |
| 1182 |
} |
| 1183 |
|
| 1184 |
\def\pgfintersectionsolutionsortbytime@swap#1#2{% |
| 1185 |
\pgfutil@namelet{pgf@intersect@temp}{#1}% |
| 1186 |
\pgfutil@namelet{#1}{#2}% |
| 1187 |
\pgfutil@namelet{#2}{pgf@intersect@temp}% |
| 1188 |
}% |
| 1189 |
|
| 1190 |
\endinput |