| 1 |
%-------------------------------------------- |
| 2 |
% |
| 3 |
% Package pgfplots |
| 4 |
% |
| 5 |
% Provides a user-friendly interface to create function plots (normal |
| 6 |
% plots, semi-logplots and double-logplots). |
| 7 |
% |
| 8 |
% It is based on Till Tantau's PGF package. |
| 9 |
% |
| 10 |
% Copyright 2013 by Christian Feuersaenger |
| 11 |
% |
| 12 |
% This program is free software: you can redistribute it and/or modify |
| 13 |
% it under the terms of the GNU General Public License as published by |
| 14 |
% the Free Software Foundation, either version 3 of the License, or |
| 15 |
% (at your option) any later version. |
| 16 |
% |
| 17 |
% This program is distributed in the hope that it will be useful, |
| 18 |
% but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 |
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 |
% GNU General Public License for more details. |
| 21 |
% |
| 22 |
% You should have received a copy of the GNU General Public License |
| 23 |
% along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 24 |
% |
| 25 |
%-------------------------------------------- |
| 26 |
|
| 27 |
|
| 28 |
% This library adds support for high-level instructions for "fill area |
| 29 |
% between two arbitrary plots of functions". |
| 30 |
% |
| 31 |
% It activates the syntax \pgfpathfillbetween |
| 32 |
% where A and B are two plots named by 'name path='. |
| 33 |
% |
| 34 |
% In fact, this here is not much more than a low-level invocation of |
| 35 |
% \pgfpathfillbetween |
| 36 |
% and a couple of styles. It could become a TikZ library because it |
| 37 |
% actually works on any two named paths, but it has its restrictions |
| 38 |
% regarding the supported input paths: both need to be plots of |
| 39 |
% functions (non-intersecting, should have at most one function value |
| 40 |
% for each canvas X coord) |
| 41 |
|
| 42 |
\pgfutil@IfUndefined{pgfplotsset}{% |
| 43 |
\pgferror{Please load pgfplots before pgfplots.fillbetween.}% |
| 44 |
\endinput |
| 45 |
}{}% |
| 46 |
|
| 47 |
\usetikzlibrary{intersections} |
| 48 |
\usetikzlibrary{decorations.softclip} |
| 49 |
|
| 50 |
% COMPATIBILITY WITH PGF RELEASE: |
| 51 |
\pgfutil@IfUndefined{pgfintersectiongetsolutiontimes}{% |
| 52 |
\pgfplotsusecompatibilityfile{pgflibraryintersections.code.tex}% |
| 53 |
}{}% |
| 54 |
\def\tikz@key@name@path@wrong#1#2{% |
| 55 |
\tikz@addmode{% |
| 56 |
\pgfsyssoftpath@getcurrentpath\tikz@intersect@temppath@round% |
| 57 |
\pgfprocessround\tikz@intersect@temppath@round\tikz@intersect@temppath% |
| 58 |
\ifx\tikz@intersect@namedpaths\pgfutil@empty% |
| 59 |
\else% |
| 60 |
\tikz@intersect@namedpaths% |
| 61 |
\pgfutil@ifundefined{tikz@intersect@path@name@#1}{}% |
| 62 |
{% |
| 63 |
\expandafter\expandafter\expandafter\def\expandafter\expandafter\expandafter\tikz@intersect@@temppath% |
| 64 |
\expandafter\expandafter\expandafter{\csname tikz@intersect@path@name@#1\endcsname}% |
| 65 |
\expandafter\expandafter\expandafter\def\expandafter\expandafter\expandafter\tikz@intersect@temppath% |
| 66 |
\expandafter\expandafter\expandafter{\expandafter\tikz@intersect@temppath\tikz@intersect@temppath}% |
| 67 |
}% |
| 68 |
\fi% |
| 69 |
\tikz@intersect@addto@path@names{#1}{#2}% |
| 70 |
}% |
| 71 |
}% |
| 72 |
|
| 73 |
\def\tikz@key@name@path@new#1#2{% |
| 74 |
\tikz@addmode{% |
| 75 |
\pgfsyssoftpath@getcurrentpath\tikz@intersect@temppath@round% |
| 76 |
\pgfprocessround\tikz@intersect@temppath@round\tikz@intersect@temppath% |
| 77 |
\ifx\tikz@intersect@namedpaths\pgfutil@empty% |
| 78 |
\else% |
| 79 |
\tikz@intersect@namedpaths% |
| 80 |
\fi% |
| 81 |
\tikz@intersect@addto@path@names{#1}{#2}% |
| 82 |
}% |
| 83 |
}% |
| 84 |
|
| 85 |
\ifx\tikz@key@name@path@wrong\tikz@key@name@path |
| 86 |
\immediate\write16{Package pgfplots: loading complementary 'name path' implementation for your pgf version...} |
| 87 |
\let\tikz@key@name@path=\tikz@key@name@path@new |
| 88 |
\fi |
| 89 |
|
| 90 |
% ------------------------------------------------------------ |
| 91 |
|
| 92 |
\newif\iftikzfillbetween@optimize@name@intersections |
| 93 |
|
| 94 |
\pgfkeys{% |
| 95 |
/tikz/fill between/of/.code=\tikzlibraryfillbetween@parse#1\pgf@stop, |
| 96 |
% |
| 97 |
/tikz/fill between/on layer/.initial=pre main, |
| 98 |
/tikz/fill between/every segment/.style={}, |
| 99 |
/tikz/fill between/every odd segment/.style={}, |
| 100 |
/tikz/fill between/every even segment/.style={}, |
| 101 |
/tikz/fill between/every last segment/.style={}, |
| 102 |
% |
| 103 |
% Allows to add path instructions *after* the segment. |
| 104 |
% If you want to add some *before* the segment, you can rely on |
| 105 |
% 'every segment no 0/.style={ ... suitable tikz options ... }' |
| 106 |
/tikz/fill between/path after segment/.initial={}, |
| 107 |
% |
| 108 |
% soft clip={(axis cs:0,0) rectangle (axis cs:1,1)} |
| 109 |
/tikz/fill between/soft clip/.style={ |
| 110 |
/tikz/fill between/soft clip first={#1},% |
| 111 |
/tikz/fill between/soft clip second={#1},% |
| 112 |
},% |
| 113 |
/tikz/fill between/soft clip first/.initial=,% |
| 114 |
/tikz/fill between/soft clip second/.initial=, |
| 115 |
% |
| 116 |
% #1: drawing options. |
| 117 |
/tikz/fill between/@draw style/.style={ |
| 118 |
/pgf/fill between/result stream/begin/.code={% |
| 119 |
\gdef\tikzsegmentindex{0}% |
| 120 |
\xdef\tikzsegmentindices{##1}% |
| 121 |
\c@pgf@countc=##1 % |
| 122 |
\advance\c@pgf@countc by-1 % |
| 123 |
\xdef\tikzsegmentlastindex{\the\c@pgf@countc}% |
| 124 |
},% |
| 125 |
/pgf/fill between/result stream/next ready/.code={% |
| 126 |
\let\pgflibraryfill@path=\pgfretval |
| 127 |
\def\pgfplots@loc@TMPa{% |
| 128 |
/tikz/fill between/every segment, |
| 129 |
#1,% |
| 130 |
/tikz/fill between/every segment no \tikzsegmentindex/.try, |
| 131 |
}% |
| 132 |
\ifodd\tikzsegmentindex\relax |
| 133 |
\expandafter\def\expandafter\pgfplots@loc@TMPa\expandafter{\pgfplots@loc@TMPa |
| 134 |
/tikz/fill between/every odd segment, |
| 135 |
}% |
| 136 |
\else |
| 137 |
\expandafter\def\expandafter\pgfplots@loc@TMPa\expandafter{\pgfplots@loc@TMPa |
| 138 |
/tikz/fill between/every even segment, |
| 139 |
}% |
| 140 |
\fi |
| 141 |
% |
| 142 |
\ifnum\tikzsegmentindex=\tikzsegmentlastindex\relax |
| 143 |
\expandafter\def\expandafter\pgfplots@loc@TMPa\expandafter{\pgfplots@loc@TMPa |
| 144 |
/tikz/fill between/every last segment, |
| 145 |
}% |
| 146 |
\fi |
| 147 |
% |
| 148 |
\expandafter\fill\expandafter[\pgfplots@loc@TMPa] |
| 149 |
\pgfextra |
| 150 |
\pgfsetpathandBB{\pgflibraryfill@path}% |
| 151 |
\pgfkeysgetvalue{/tikz/fill between/path after segment}\tikz@fillbetween@post@segment |
| 152 |
\expandafter |
| 153 |
\endpgfextra |
| 154 |
\tikz@fillbetween@post@segment |
| 155 |
;% |
| 156 |
\pgfplotsutil@advancestringcounter@global\tikzsegmentindex |
| 157 |
},% |
| 158 |
/pgf/fill between/result stream/end/.code=,% |
| 159 |
}, |
| 160 |
/tikz/fill between/.search also={/pgf/fill between,/pgfplots}, |
| 161 |
/tikz/fill between/optimize name intersections/.is if=tikzfillbetween@optimize@name@intersections, |
| 162 |
% |
| 163 |
% FIXME : this optimization needs much more work... I believe it |
| 164 |
% would be stable enough, but it covers too few cases. |
| 165 |
%/tikz/fill between/optimize name intersections=true, |
| 166 |
% |
| 167 |
% |
| 168 |
% |
| 169 |
%-------------------------------------------------- |
| 170 |
% /pgfplots/execute at begin axis@@/.add={% |
| 171 |
% \def\b@pgfplotslibraryfill@added |
| 172 |
% }{% |
| 173 |
% |
| 174 |
% },% |
| 175 |
%-------------------------------------------------- |
| 176 |
} |
| 177 |
|
| 178 |
\def\tikzlibraryfillbetween@parse#1 and #2\pgf@stop{% |
| 179 |
\def\tikz@fillbetween@a{#1}% |
| 180 |
\def\tikz@fillbetween@b{#2}% |
| 181 |
}% |
| 182 |
|
| 183 |
% \tikzfillbetween[<options>]{<draw style>} |
| 184 |
% |
| 185 |
% <options> must contain 'of=<A> and <B>' and may configure how the |
| 186 |
% area is computed. |
| 187 |
% |
| 188 |
% <draw style> affects every drawn region. |
| 189 |
% |
| 190 |
\def\tikzfillbetween{\pgfutil@ifnextchar[{\tikzfillbetween@opt}{\tikzfillbetween@opt[]}} |
| 191 |
\def\tikzfillbetween@opt[#1]#2{% |
| 192 |
\begingroup |
| 193 |
\pgfqkeys{/tikz/fill between}{% |
| 194 |
% prepare the low-level path generation instruction(s): |
| 195 |
/tikz/fill between/@draw style={#2},% |
| 196 |
% |
| 197 |
% set up input options: |
| 198 |
#1,% |
| 199 |
}% |
| 200 |
% automagically try to use the correct layer: |
| 201 |
\pgfkeysgetvalue{/tikz/fill between/on layer}\tikzlibraryfillbetween@path@layer@name |
| 202 |
\tikzlibraryfillbetween@determine@layer |
| 203 |
% |
| 204 |
\ifx\tikzlibraryfillbetween@path@layer@name\pgfutil@empty \else |
| 205 |
\pgfonlayer{\tikzlibraryfillbetween@path@layer@name}% |
| 206 |
\fi |
| 207 |
% |
| 208 |
\tikzlibraryfillbetween@path@generatepath |
| 209 |
% |
| 210 |
\ifx\tikzlibraryfillbetween@path@layer@name\pgfutil@empty \else |
| 211 |
\endpgfonlayer% |
| 212 |
\fi |
| 213 |
% |
| 214 |
\endgroup |
| 215 |
}% |
| 216 |
|
| 217 |
% Defines \tikzlibraryfillbetween@path@layer@name |
| 218 |
\def\tikzlibraryfillbetween@determine@layer{% |
| 219 |
\ifx\tikzlibraryfillbetween@path@layer@name\pgfutil@empty |
| 220 |
\else |
| 221 |
\pgfutil@IfUndefined{pgf@layerlist}{% |
| 222 |
% hm. No layers active!? A pity... |
| 223 |
\tikzlibraryfillbetween@path@warn@layer |
| 224 |
\let\tikzlibraryfillbetween@path@layer@name\pgfutil@empty% |
| 225 |
}{% |
| 226 |
\edef\pgfplots@loc@TMPa{\noexpand\pgfutil@in@{\tikzlibraryfillbetween@path@layer@name}}% |
| 227 |
\expandafter\pgfplots@loc@TMPa\expandafter{\pgf@layerlist}% |
| 228 |
\ifpgfutil@in@ |
| 229 |
\else |
| 230 |
\tikzlibraryfillbetween@path@warn@layer |
| 231 |
\let\tikzlibraryfillbetween@path@layer@name\pgfutil@empty% |
| 232 |
\fi |
| 233 |
}% |
| 234 |
\fi |
| 235 |
}% |
| 236 |
|
| 237 |
\def\tikzlibraryfillbetween@path@warn@layer{% |
| 238 |
\pgfplots@warning{'fill between': Could not activate graphics layer '\tikzlibraryfillbetween@path@layer@name'. Filled path will be on top of the other ones. Please ensure that '\tikzlibraryfillbetween@path@layer@name' is somewhere in the layer list (or set '/tikz/fill between/on layer=').}% |
| 239 |
}% |
| 240 |
|
| 241 |
\def\tikzlibraryfillbetween@parse@softclip{% |
| 242 |
\pgfkeysgetvalue{/tikz/fill between/soft clip first}\pgf@temp |
| 243 |
\pgfkeysgetvalue{/tikz/fill between/soft clip second}\pgf@tempb |
| 244 |
\ifx\pgf@temp\pgf@tempb |
| 245 |
% Ah - both have the same value! |
| 246 |
\ifx\pgf@temp\pgfutil@empty |
| 247 |
% ... and both are empty. |
| 248 |
\pgffillbetweensetsoftclippath{\pgfutil@empty}% |
| 249 |
\else |
| 250 |
% ... and both contain some path! Process it (once): |
| 251 |
\def\tikz@marshal{\tikzlibsoftclip@setkey{\pgffillbetweensetsoftclippath}}% |
| 252 |
\expandafter\tikz@marshal\pgf@temp\pgf@stop |
| 253 |
\fi |
| 254 |
\else |
| 255 |
% handle 'soft clip first': |
| 256 |
\ifx\pgf@temp\pgfutil@empty |
| 257 |
\pgffillbetweensetsoftclippathfirst{\pgfutil@empty}% |
| 258 |
\else |
| 259 |
\def\tikz@marshal{\tikzlibsoftclip@setkey{\pgffillbetweensetsoftclippathfirst}}% |
| 260 |
\expandafter\tikz@marshal\pgf@temp\pgf@stop |
| 261 |
\fi |
| 262 |
% |
| 263 |
% handle 'soft clip second': |
| 264 |
\pgfkeysgetvalue{/tikz/fill between/soft clip second}\pgf@tempb |
| 265 |
\ifx\pgf@tempb\pgfutil@empty |
| 266 |
\pgffillbetweensetsoftclippathsecond{\pgfutil@empty}% |
| 267 |
\else |
| 268 |
\def\tikz@marshal{\tikzlibsoftclip@setkey{\pgffillbetweensetsoftclippathsecond}}% |
| 269 |
\expandafter\tikz@marshal\pgf@tempb\pgf@stop |
| 270 |
\fi |
| 271 |
\fi |
| 272 |
}% |
| 273 |
|
| 274 |
\def\tikzlibraryfillbetween@path@generatepath{% |
| 275 |
% |
| 276 |
\tikzlibraryfillbetween@parse@softclip |
| 277 |
% |
| 278 |
\tikzlibraryfillbetween@path@check |
| 279 |
\expandafter\let\expandafter\tikz@fillbetween@a@path |
| 280 |
\csname tikz@intersect@path@name@\tikz@fillbetween@a\endcsname |
| 281 |
\expandafter\let\expandafter\tikz@fillbetween@b@path |
| 282 |
\csname tikz@intersect@path@name@\tikz@fillbetween@b\endcsname |
| 283 |
% |
| 284 |
\iftikzfillbetween@optimize@name@intersections |
| 285 |
\ifpgfpathfillbetween@split |
| 286 |
\tikzfillbetween@optimize@name@intersections\tikz@fillbetween@a\tikz@fillbetween@b |
| 287 |
\fi |
| 288 |
\fi |
| 289 |
% |
| 290 |
\pgfpathfillbetween{\tikz@fillbetween@a@path}{\tikz@fillbetween@b@path}% |
| 291 |
}% |
| 292 |
|
| 293 |
\def\tikzlibraryfillbetween@path@check{% |
| 294 |
\pgfutil@IfUndefined{tikz@intersect@path@name@\tikz@fillbetween@a}{% |
| 295 |
\pgferror |
| 296 |
{fill between: the mandatory argument 'of=<name path A> and <name path B> is missing or has empty arguments. Please ensure that the option has been set and that both path names have been assigned (perhaps you need 'name path global=\tikz@fillbetween@a' somewhere?)}% |
| 297 |
}{}% |
| 298 |
\pgfutil@IfUndefined{tikz@intersect@path@name@\tikz@fillbetween@b}{% |
| 299 |
\pgferror |
| 300 |
{fill between: the mandatory argument 'of=<name path A> and <name path B> is missing or has empty arguments. Please ensure that the option has been set and that both path names have been assigned (perhaps you need 'name path global=\tikz@fillbetween@b' somewhere?)}% |
| 301 |
}{}% |
| 302 |
} |
| 303 |
|
| 304 |
|
| 305 |
%----------------------------------------- |
| 306 |
% |
| 307 |
% Utilities to work with path segments |
| 308 |
% |
| 309 |
%----------------------------------------- |
| 310 |
|
| 311 |
% Defines \pgfretval such that it contains the named path '#1' |
| 312 |
\def\tikzgetnamedpath#1{% |
| 313 |
\pgfutil@IfUndefined{tikz@intersect@path@name@#1}{% |
| 314 |
\pgferror{There is no named path called '#1'. Perhaps you misspelled it?}% |
| 315 |
}{% |
| 316 |
\expandafter\let\expandafter\pgfretval |
| 317 |
\csname tikz@intersect@path@name@#1\endcsname |
| 318 |
}% |
| 319 |
}% |
| 320 |
|
| 321 |
\def\tikznamecurrentpath#1{% |
| 322 |
\pgfgetpath\pgf@temp |
| 323 |
\pgfprocessround\pgf@temp\pgf@tempb% |
| 324 |
\expandafter\global\expandafter\let\csname tikz@intersect@path@name@#1\endcsname=\pgf@tempb |
| 325 |
}% |
| 326 |
|
| 327 |
% --------------------------------------------------------------------------------------- |
| 328 |
|
| 329 |
\newif\iftikzpathsegments@reverse |
| 330 |
\def\tikzlibrarysegments@parse#1 and #2\pgf@stop{% |
| 331 |
\def\tikz@path@segments@a{#1}% |
| 332 |
\def\tikz@path@segments@b{#2}% |
| 333 |
}% |
| 334 |
|
| 335 |
|
| 336 |
\pgfkeys{ |
| 337 |
% allows to append intersection segments to the current path by |
| 338 |
% writing |
| 339 |
% \path[intersection segments={of=first and second, sequence=A0 -- B1 -- B3 A3[reverse] -- A1}]; |
| 340 |
/tikz/intersection segments/.code={% |
| 341 |
\tikzpathintersectionsegments[#1]% |
| 342 |
}, |
| 343 |
/tikz/segments/of/.code=\tikzlibrarysegments@parse#1\pgf@stop, |
| 344 |
/tikz/segments/of={} and {}, |
| 345 |
/tikz/segments/sequence/.initial=A0 -- B1, |
| 346 |
/tikz/segments/reverse/.is if=tikzpathsegments@reverse, |
| 347 |
/tikz/segments/reverse/.default=true, |
| 348 |
} |
| 349 |
|
| 350 |
% Programmatic method to do the same as 'intersection |
| 351 |
% segments={<options>} |
| 352 |
% |
| 353 |
% #1: <options> |
| 354 |
\def\tikzpathintersectionsegments[#1]{% |
| 355 |
\begingroup |
| 356 |
\pgfqkeys{/tikz/segments}{#1}% |
| 357 |
\tikzgetnamedpath{\tikz@path@segments@a}% |
| 358 |
\let\tikz@path@segments@A=\pgfretval |
| 359 |
\tikzgetnamedpath{\tikz@path@segments@b}% |
| 360 |
\let\tikz@path@segments@B=\pgfretval |
| 361 |
% |
| 362 |
% this macro will be called whenever we need an intersection |
| 363 |
% segment. Perhaps we do not need it at all |
| 364 |
\def\tikz@ensurehascomputedintersection{% |
| 365 |
% compute intersections using the PGF intersection lib... |
| 366 |
\pgfintersectionofpaths{\pgfsetpath\tikz@path@segments@A}{\pgfsetpath\tikz@path@segments@B}% |
| 367 |
% |
| 368 |
\ifnum\pgfintersectionsolutions=0 % |
| 369 |
\pgferror{The argument of 'sequence' requests an intersection segment -- but the two input paths do not intersect. Please use A* or B* to select the whole path}% |
| 370 |
\def\b@tikz@select@all{1}% |
| 371 |
\else |
| 372 |
% |
| 373 |
% ... and compute the intersection *segments* for both input |
| 374 |
% paths... |
| 375 |
\pgfcomputeintersectionsegments1% |
| 376 |
\pgfcomputeintersectionsegments2% |
| 377 |
\fi |
| 378 |
\let\tikz@ensurehascomputedintersection=\relax |
| 379 |
}% |
| 380 |
% |
| 381 |
\pgfkeysgetvalue{/tikz/segments/sequence}\tikz@sequence |
| 382 |
% |
| 383 |
\def\b@tikz@isect@nextismoveto{1}% |
| 384 |
\let\pgfpointlastofsetpath=\pgfutil@empty |
| 385 |
\expandafter\tikzpathintersectionsegments@parse@loop\tikz@sequence\pgf@stop |
| 386 |
\pgfmath@smuggleone\pgfpointlastofsetpath |
| 387 |
\endgroup |
| 388 |
\tikz@make@last@position{\pgfpointlastofsetpath}% |
| 389 |
}% |
| 390 |
|
| 391 |
\def\tikzpathintersectionsegments@parse@loop{% |
| 392 |
\pgfutil@ifnextchar-{% |
| 393 |
\tikz@isect@p@lineto |
| 394 |
}{% |
| 395 |
\pgfutil@ifnextchar A{% |
| 396 |
\tikz@isect@p@next |
| 397 |
}{% |
| 398 |
\pgfutil@ifnextchar B{% |
| 399 |
\tikz@isect@p@next |
| 400 |
}{% |
| 401 |
\pgfutil@ifnextchar L{% |
| 402 |
\tikz@isect@p@next |
| 403 |
}{% |
| 404 |
\pgfutil@ifnextchar R{% |
| 405 |
\tikz@isect@p@next |
| 406 |
}{% |
| 407 |
\pgfutil@ifnextchar\pgf@stop{% |
| 408 |
\tikz@isect@finish |
| 409 |
}{% |
| 410 |
\tikz@isect@p@error |
| 411 |
}% |
| 412 |
}% |
| 413 |
}% |
| 414 |
}% |
| 415 |
}% |
| 416 |
}% |
| 417 |
}% |
| 418 |
|
| 419 |
\def\tikz@isect@finish\pgf@stop{}% |
| 420 |
|
| 421 |
\def\tikz@isect@p@lineto--{% |
| 422 |
\def\b@tikz@isect@nextismoveto{0}% |
| 423 |
\tikzpathintersectionsegments@parse@loop |
| 424 |
}% |
| 425 |
|
| 426 |
\def\tikz@isect@p@error#1\pgf@stop{% |
| 427 |
\pgferror{The argument of 'sequence' has an unexpected format near '#1'. Please write something like A0 -- B1 -- A1}% |
| 428 |
} |
| 429 |
|
| 430 |
\def\tikz@isect@p@next#1#2{% |
| 431 |
\def\tikz@temp{#2}% |
| 432 |
\def\tikz@@temp{-}% |
| 433 |
\ifx\tikz@@temp\tikz@temp |
| 434 |
% also accept minus signs without curly braces, i.e. |
| 435 |
% L-2 instead of L{-2} |
| 436 |
\def\tikz@next{\tikz@isect@p@next@{#1}{#2}}% |
| 437 |
\else |
| 438 |
\def\tikz@next{\tikz@isect@p@next@{#1}{#2}{}}% |
| 439 |
\fi |
| 440 |
\tikz@next |
| 441 |
}% |
| 442 |
\def\tikz@isect@p@next@#1#2#3{% |
| 443 |
\pgfutil@ifnextchar[{% |
| 444 |
\tikz@isect@p@next@opt{#1}{#2#3}% |
| 445 |
}{% |
| 446 |
\tikz@isect@p@next@opt{#1}{#2#3}[]% |
| 447 |
}% |
| 448 |
}% |
| 449 |
|
| 450 |
\def\tikz@isect@p@next@opt#1#2[#3]{% |
| 451 |
\begingroup |
| 452 |
% |
| 453 |
% set keys (if any): |
| 454 |
\def\tikz@temp{#3}% |
| 455 |
\ifx\tikz@temp\pgfutil@empty |
| 456 |
\else |
| 457 |
\pgfqkeys{/tikz/segments}{#3}% |
| 458 |
\fi |
| 459 |
% |
| 460 |
\def\tikz@indexshift{}% |
| 461 |
\if A#1% |
| 462 |
% FIRST function (0-based index) |
| 463 |
\def\tikz@path{1}% |
| 464 |
\def\tikz@path@ab{A}% |
| 465 |
\else |
| 466 |
\if B#1% |
| 467 |
% SECOND function (0-based index) |
| 468 |
\def\tikz@path{2}% |
| 469 |
\def\tikz@path@ab{B}% |
| 470 |
\else |
| 471 |
\if L#1% |
| 472 |
% FIRST function (1-based index) |
| 473 |
\def\tikz@path{1}% |
| 474 |
\def\tikz@indexshift{-1}% |
| 475 |
\def\tikz@path@ab{A}% |
| 476 |
\else |
| 477 |
\if R#1% |
| 478 |
% SECOND function (1-based index) |
| 479 |
\def\tikz@path{2}% |
| 480 |
\def\tikz@indexshift{-1}% |
| 481 |
\def\tikz@path@ab{B}% |
| 482 |
\else |
| 483 |
\def\tikz@path{}% |
| 484 |
\pgferror{The argument of 'sequence' has an unexpected format near '#1#2': expected L#2 or R#2}% |
| 485 |
\fi |
| 486 |
\fi |
| 487 |
\fi |
| 488 |
\fi |
| 489 |
% |
| 490 |
% parse arguments: |
| 491 |
\def\pgfmathresult{#2}% |
| 492 |
\def\tikz@temp{*}% |
| 493 |
\ifx\pgfmathresult\tikz@temp |
| 494 |
\def\b@tikz@select@all{1}% |
| 495 |
\else |
| 496 |
\def\b@tikz@select@all{0}% |
| 497 |
\tikz@ensurehascomputedintersection |
| 498 |
\pgfmathparse{round(#2)}% |
| 499 |
\let\tikz@index=\pgfmathresult |
| 500 |
\ifx\tikz@indexshift\pgfutil@empty |
| 501 |
\else |
| 502 |
\afterassignment\pgfutil@gobble@until@relax |
| 503 |
\c@pgf@countc=\tikz@index\relax |
| 504 |
\ifnum\c@pgf@countc<0 \else |
| 505 |
% the index shift is ONLY for positive numbers: we |
| 506 |
% want to start indexing at 1, not at 0 -- and the |
| 507 |
% negative ones start at -1 anyway. |
| 508 |
\advance\c@pgf@countc by\tikz@indexshift\relax |
| 509 |
\edef\tikz@index{\the\c@pgf@countc}% |
| 510 |
\fi |
| 511 |
\fi |
| 512 |
\fi |
| 513 |
% |
| 514 |
% |
| 515 |
% PROCESS IT: |
| 516 |
\ifx\tikz@path\pgfutil@empty |
| 517 |
\let\pgfpointlastofsetpath=\pgfutil@empty |
| 518 |
\else |
| 519 |
\if1\b@tikz@select@all% |
| 520 |
% ok... select the *entire* path. |
| 521 |
% #1 = A|B : |
| 522 |
\expandafter\let\expandafter\pgfretval\csname tikz@path@segments@\tikz@path@ab\endcsname |
| 523 |
\else |
| 524 |
\pgfgetintersectionsegmentpath{\tikz@path}{\tikz@index}% |
| 525 |
\fi |
| 526 |
\iftikzpathsegments@reverse |
| 527 |
\pgf@reverse@path\pgfretval |
| 528 |
\fi |
| 529 |
\if0\b@tikz@isect@nextismoveto |
| 530 |
\pgfpathreplacefirstmoveto\pgfretval |
| 531 |
\fi |
| 532 |
\pgfaddpathandBB\pgfretval |
| 533 |
\fi |
| 534 |
\pgfmath@smuggleone\pgfpointlastofsetpath |
| 535 |
\endgroup |
| 536 |
\def\b@tikz@isect@nextismoveto{1}% |
| 537 |
\tikzpathintersectionsegments@parse@loop |
| 538 |
}% |
| 539 |
|
| 540 |
\def\tikzfillbetween@optimize@name@intersections#1#2{% |
| 541 |
\edef\tikzfillbetween@precached@intersectionofpaths@A{#1}% |
| 542 |
\edef\tikzfillbetween@precached@intersectionofpaths@B{#2}% |
| 543 |
\pgfkeys{% |
| 544 |
/tikz/name intersections/.add code={% |
| 545 |
\let\pgfintersectionofpaths=\tikzfillbetween@precached@intersectionofpaths |
| 546 |
}{% |
| 547 |
\let\pgfintersectionofpaths=\pgfintersectionofpaths@orig |
| 548 |
} |
| 549 |
}% |
| 550 |
}% |
| 551 |
|
| 552 |
\let\pgfintersectionofpaths@orig=\pgfintersectionofpaths |
| 553 |
|
| 554 |
\def\tikzfillbetween@precached@intersectionofpaths@log{% |
| 555 |
\immediate\write-1{fill between: outcome of 'name intersections={of=\tikz@intersect@path@a\space and \tikz@intersect@path@b}' has been computed from available information of fill between}% |
| 556 |
} |
| 557 |
\def\tikzfillbetween@precached@intersectionofpaths#1#2{% |
| 558 |
\def\pgf@loc@TMPa{0}% |
| 559 |
\ifx\tikz@intersect@path@a\tikzfillbetween@precached@intersectionofpaths@A |
| 560 |
\ifx\tikz@intersect@path@b\tikzfillbetween@precached@intersectionofpaths@B |
| 561 |
\def\pgf@loc@TMPa{1}% |
| 562 |
\fi |
| 563 |
\fi |
| 564 |
\ifx\tikz@intersect@path@b\tikzfillbetween@precached@intersectionofpaths@A |
| 565 |
\ifx\tikz@intersect@path@a\tikzfillbetween@precached@intersectionofpaths@B |
| 566 |
\def\pgf@loc@TMPa{1}% |
| 567 |
\fi |
| 568 |
\fi |
| 569 |
% |
| 570 |
\if1\pgf@loc@TMPa |
| 571 |
\tikzfillbetween@precached@intersectionofpaths@log |
| 572 |
\relax |
| 573 |
\else |
| 574 |
\pgfintersectionofpaths@orig{#1}{#2}% |
| 575 |
\fi |
| 576 |
}% |
| 577 |
\endinput |