Debian Codegraph @

texmf-dist/tex/generic/pgf/modules/pgfmoduledecorations.code.tex

raw
1 % Copyright 2019 by Mark Wibrow and Till Tantau
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 Public License.
7 %
8 % See the file doc/generic/pgf/licenses/LICENSE for more details.
9
10
11 % The following naming conventions are (more or less) observed:
12 %
13 % `decorated' : the path that is being decorated.
14 % `decoration' : any path created/left by the automaton
15 % `decorate' : generic use where distinction is probably unimportant
16 % (e.g. internal macros).
17
18
19
20 % These should be moved.
21 %
22 \def\pgfgetpath#1{\pgfsyssoftpath@getcurrentpath{#1}}%
23 \def\pgfsetpath#1{\pgfsyssoftpath@setcurrentpath{#1}}%
24
25
26 % Required registers.
27 %
28 \newdimen\pgfdecoratedcompleteddistance
29 \newdimen\pgfdecoratedremainingdistance
30 \newdimen\pgfdecoratedinputsegmentcompleteddistance
31 \newdimen\pgfdecoratedinputsegmentremainingdistance
32 \newdimen\pgf@decorate@distancetomove
33
34 \newcount\pgf@decorate@repeatstate
35
36
37 % Extra options used in all libraries
38
39 \newdimen\pgfdecorationsegmentamplitude
40 \newdimen\pgfdecorationsegmentlength
41 \pgfdecorationsegmentamplitude2.5pt
42 \pgfdecorationsegmentlength10pt
43 \def\pgfdecorationsegmentangle{45}%
44 \def\pgfdecorationsegmentaspect{0.5}%
45 \def\pgfmetadecorationsegmentamplitude{2.5pt}%
46 \def\pgfmetadecorationsegmentlength{1cm}%
47
48 \pgfkeys{%
49 /pgf/decoration/.code={\pgfkeys{/pgf/decoration/.cd,#1}},
50 /pgf/decoration/.cd,
51 amplitude/.code={\pgfmathsetlength\pgfdecorationsegmentamplitude{#1}},
52 meta-amplitude/.store in=\pgfmetadecorationsegmentamplitude,
53 segment length/.code={\pgfmathsetlength\pgfdecorationsegmentlength{#1}},
54 meta-segment length/.store in=\pgfmetadecorationsegmentlength,
55 angle/.code={\pgfmathparse{#1}\let\pgfdecorationsegmentangle\pgfmathresult},
56 aspect/.code={\pgfmathparse{#1}\let\pgfdecorationsegmentaspect\pgfmathresult},
57 start radius/.initial=2.5pt,
58 end radius/.initial=2.5pt,
59 radius/.style={start radius={#1},end radius={#1}},
60 path has corners/.is if=pgfdecoratepathhascorners,
61 reverse path/.is if=pgf@decorate@inputsegmentobjects@reverse,
62 }%
63 \newif\ifpgfdecoratepathhascorners
64 \newif\ifpgf@decorate@inputsegmentobjects@reverse
65
66 % Declare a decoration
67 %
68 % #1 = name of the decoration
69 % #2 = initial state
70 % #3 = states
71 %
72 % This command declares a new decoration for later use.
73 % Inside the code of #3 the command \state may be used. This command
74 % will only be defined while #3 is executed.
75 %
76 % Example:
77 %
78 % \pgfdeclaredecoration{zigzag}{q}
79 % {
80 % \state{q}[width=10pt]
81 % {
82 % \pgfpathlineto{\pgfpoint{2.5pt}{2.5pt}}
83 % \pgfpathlineto{\pgfpoint{7.5pt}{-2.5pt}}
84 % \pgfpathlineto{\pgfpoint{10pt}{0pt}}
85 % }
86 % \state{final}
87 % {
88 % \pgfpathlineto{\pgfpointdecoratedpathlast}
89 % }
90 % }
91
92 \long\def\pgfdeclaredecoration#1#2#3{%
93 \let\pgf@mod@dec@next=\pgf@mod@dec@firstofone%
94 \pgfifmetadecoration{#1}{%
95 \pgferror{You cannot declare a decoration of the same
96 name as a meta-decoration}%
97 \let\pgf@mod@dec@next=\pgfutil@gobble%
98 }{}%
99 \pgf@mod@dec@next
100 {%
101 \def\pgf@decorate@name{#1}%
102 \pgfutil@namedef{pgf@decorate@@#1@initial}{#2}%
103 \let\pgf@orig@state\state%
104 \let\state\pgf@decorate@state
105 #3%
106 \let\state\pgf@orig@state%
107 }%
108 }%
109
110 \def\pgf@decorate@state#1{\pgfutil@ifnextchar[{\pgf@decorate@@start#1}{\pgf@decorate@@start#1[]}}%}%
111 \def\pgf@decorate@@start#1[#2]#3{%
112 \pgfutil@namedef{pgf@decorate@@\pgf@decorate@name @#1@options}{#2}%
113 \pgfutil@namedef{pgf@decorate@@\pgf@decorate@name @#1@code}{#3}%
114 }%
115 \long\def\pgf@mod@dec@firstofone#1{#1}%
116
117
118 % Test whether something is a decoration
119 %
120 % #1 = name
121 % #2 = if-code
122 % #3 = else-code
123 %
124 % Example:
125 %
126 % \pgfifdecoration{zigzag}{Exists}{Does not exist}
127
128 \def\pgfifdecoration#1#2#3{\pgfutil@ifundefined{pgf@decorate@@#1@initial}{#3}{#2}}%
129
130
131
132 % Declare a meta decoration
133 %
134 % #1 = name of the meta decoration
135 % #2 = initial state
136 % #3 = states
137 %
138 % This command declares a new meta decoration for later use.
139 % Inside the code of #3 the command \state may be used.
140
141 \long\def\pgfdeclaremetadecoration#1#2#3{%
142 \let\pgf@mod@dec@next=\pgf@mod@dec@firstofone%
143 \pgfifdecoration{#1}{%
144 \pgferror{You cannot declare a meta-decoration of the
145 same name as a decoration}%
146 \let\pgf@mod@dec@next=\pgfutil@gobble%
147 }{}%
148 \pgf@mod@dec@next{%
149 \def\pgf@metadecoration@name{#1}%
150 \pgfutil@namedef{pgf@metadecoration@@#1@initial}{#2}%
151 \let\pgf@orig@state\state%
152 \let\state\pgf@metadecoration@state
153 #3%
154 \let\state\pgf@orig@state%
155 }%
156 }%
157
158 \def\pgf@metadecoration@state#1{\pgfutil@ifnextchar[{\pgf@metadecoration@@state#1}{\pgf@metadecoration@@state#1[]}}%}%
159 \def\pgf@metadecoration@@state#1[#2]#3{%
160 \pgfutil@namedef{pgf@metadecoration@@\pgf@metadecoration@name @#1@options}{#2}%
161 \pgfutil@namedef{pgf@metadecoration@@\pgf@metadecoration@name @#1@code}{#3}%
162 }%
163
164
165 % Test whether something is a meta-decoration
166 %
167 % #1 = name
168 % #2 = if-code
169 % #3 = else-code
170 %
171 % Example:
172 %
173 % \pgfifmetadecoration{zigzag}{Exists}{Does not exist}
174
175 \def\pgfifmetadecoration#1#2#3{\pgfutil@ifundefined{pgf@metadecoration@@#1@initial}{#3}{#2}}%
176
177
178
179
180
181 \let\pgfdecoratebeforecode\pgfutil@empty
182 \let\pgfdecorateaftercode\pgfutil@empty
183
184 % \pgfdecoratepath
185 %
186 % Decorate a path.
187 %
188 % \pgfdecoratebeforecode and \pgfdecorateaftercode can be used to
189 % execute code before and after the decoration.
190 %
191 % #1 - the name of the decoration.
192 % #2 - a (non-empty) path specification.
193 %
194 % Example:
195 %
196 % \pgfdeclaredecoration{circles}{red circles}{
197 % \state{red circles}[width=10pt, repeat state=2, next state=blue circles]
198 % {
199 % \pgfmathparse{round(rnd*100)}
200 % \pgfsetstrokecolor{red!\pgfmathresult!brown}
201 % \pgfsetfillcolor{orange!\pgfmathresult!yellow}
202 % \pgfpathcircle{\pgfpointorigin}{2.5pt}
203 % \pgfusepath{stroke,fill}
204 % }
205 % \state{blue circles}[width=10pt, repeat state=1, next state=red circles]
206 % {
207 % \pgfmathparse{round(rnd*100)}
208 % \pgfsetstrokecolor{blue!\pgfmathresult!gray}
209 % \pgfsetfillcolor{blue!\pgfmathresult!white}
210 % \pgfpathcircle{\pgfpointorigin}{2.5pt}
211 % \pgfusepath{stroke,fill}
212 % }
213 % \state{final}{}
214 % }
215 %
216 % \pgfpicture
217 % \pgfdecoratepath{circles}
218 % {
219 % \pgfpathmoveto{\pgfpointorigin}
220 % \pgfpathcurveto{\pgfpoint{0cm}{3cm}}{\pgfpoint{4cm}{0cm}}{\pgfpoint{4cm}{3cm}}
221 % }
222 % \endpgfpicture
223 %
224 \long\def\pgfdecoratepath#1#2{%
225 \pgfdecoration{{#1}{\pgfdecoratedpathlength}{\pgfdecoratebeforecode}{\pgfdecorateaftercode}}%
226 #2%
227 \endpgfdecoration}%
228
229
230
231
232 % \pgfdecoratecurrentpath
233 %
234 % Decorate the current/existing path, but (unavoidably) destroys it.
235 %
236 % \pgfdecoratebeforecode and \pgfdecorateaftercode can be used to
237 % execute code before and after the decoration.
238 %
239 % #1 - the name of the decoration.
240 %
241 % Example:
242 %
243 % \pgfdeclaredecoration{stars}{move}{
244 % \state{move}[width=7.5pt, next state=star]{}
245 % \state{star}[width=7.5pt, next state=move]
246 % {
247 % \pgfmathparse{round(rnd*100)}
248 % \pgfsetfillcolor{yellow!\pgfmathresult!orange}
249 % \pgfsetstrokecolor{yellow!\pgfmathresult!red}
250 % \pgfmathparse{rnd*.75+.25}
251 % \pgftransformscale{\pgfmathresult}
252 % \pgfnode{star}{center}{}{}{\pgfusepath{stroke,fill}}
253 % }
254 % \state{final}
255 % {
256 % \pgfpathmoveto{\pgfpointdecoratedpathlast}
257 % }
258 % }
259 %
260 % \pgfpicture
261 % \pgfpathmoveto{\pgfpointorigin}
262 % \pgfpathcurveto{\pgfqpoint{0cm}{2cm}}{\pgfqpoint{3cm}{2cm}}{\pgfqpoint{3cm}{0cm}}
263 % \pgfpathcurveto{\pgfqpoint{3cm}{-3cm}}{\pgfqpoint{0cm}{0cm}}{\pgfqpoint{0cm}{-3cm}}
264 % \pgfpathcurveto{\pgfqpoint{0cm}{-5cm}}{\pgfqpoint{3cm}{-5cm}}{\pgfqpoint{3cm}{-3cm}}
265 % \pgfdecoratecurrentpath{stars}
266 % \endpgfpicture
267 %
268 \def\pgfdecoratecurrentpath#1{%
269 \pgfgetpath\pgf@decorate@currentpath%
270 \pgfsetpath\pgfutil@empty%
271 \pgfdecoration{{#1}{\pgfdecoratedpathlength}{\pgfdecoratebeforecode}{\pgfdecorateaftercode}}%
272 \pgfsetpath\pgf@decorate@currentpath%
273 \endpgfdecoration}%
274
275
276
277
278 % Environment \pgfdecoration \endpgfdecoration
279 %
280 % Decorates a path with multiple decorations.
281 %
282 % Definitions:
283 %
284 % `existing path'
285 % - any unused path existing prior to the environment.
286 %
287 % `decorated path'
288 % - the path that is being decorated.
289 %
290 % `decoration path'
291 % - any unused path left by the decoration automaton.
292 %
293 % The action of the environment is as follows:
294 %
295 % 1. Any existing path is saved.
296 % 2. Construction commands are executed forming the decorated path.
297 % 3. If the first command in the decorated path is not a `move to',
298 % the last known position from the existing path is inserted.
299 % 4. The saved existing path is reinstalled.
300 % 5. The decoration automaton is executed along the decorated path.
301 %
302 % Parameters:
303 %
304 % #1 - a comma separated list of decoration specifications.
305 %
306 % A decoration specification takes the format:
307 %
308 % {<name>}{<distance>}{<before code>}{<after code>}
309 %
310 % The decoration <name> is applied to a section of the decorated
311 % path from the last point on the decorated path the decoration
312 % automaton reached to <distance> from that point.
313 %
314 % When <distance>} is parsed, the dimension
315 % \pgfdecoratedreminingdistance holds the distance remaining on the
316 % entire decorated path, and the macro \pgfdecoratedpathlength holds
317 % the total length of the entire decorated path.
318 % After <distance> is parsed, both are set to to the value of
319 % <distance> for the automaton to decorate current section of the
320 % decorated path.
321 %
322 % <before code> is executed just before the decoration automaton
323 % starts and <after code> is executed just after the automaton stops.
324 % If <before code> or <after code> are empty, they can be omitted.
325 % The macros \pgfdecoratedpathfirst and \pgfdecoratedpathlast
326 % will be set up as the first and last points on the current section
327 % of the decorated path.
328 %
329 % When the environment exits, the following macros will be set up:
330 %
331 % \pgfdecorateexistingpath
332 % - the existing path.
333 %
334 % \pgfdecoratedpath
335 % - the decorated path.
336 %
337 % \pgfdecorationpath
338 % - any unused decoration path.
339 %
340 % \pgfpointdecoratedpathlast
341 % - the last point on the decorated path.
342 %
343 % Examples (require pgfdecorations library):
344 %
345 % \pgfpicture
346 % \pgfdecoration
347 % {
348 % {lineto}{\pgfdecoratedpathlength/3},
349 % {zigzag}{\pgfdecoratedpathlength/3},
350 % {lineto}{\pgfdecoratedpathlength/3}
351 % }
352 % \pgfpathmoveto{\pgfpointorigin}
353 % \pgfpathcurveto{\pgfpoint{0cm}{4cm}}{\pgfpoint{5cm}{0cm}}{\pgfpoint{5cm}{4cm}}
354 % \endpgfdecoration
355 % \pgfusepath{stroke}
356 % \endpgfpicture
357 %
358 %
359 % \pgfpicture
360 % \pgfdecoration
361 % {
362 % {lineto}{\pgfdecoratedpathlength/5}{}{\pgfusepath{stroke}},
363 % {zigzag}{\pgfdecoratedpathlength/5}
364 % {
365 % \pgfpathmoveto{\pgfpointdecoratedpathfirst}
366 % }
367 % {
368 % \pgfsetstrokecolor{red}
369 % \pgfusepath{stroke}
370 % },
371 % {lineto}{\pgfdecoratedpathlength/5}
372 % {
373 % \pgfpathmoveto{\pgfpointdecoratedpathfirst}
374 % }
375 % {
376 % \pgfsetstrokecolor{black}
377 % \pgfusepath{stroke}
378 % },
379 % {zigzag}{\pgfdecoratedpathlength/5}
380 % {
381 % \pgfpathmoveto{\pgfpointdecoratedpathfirst}
382 % }
383 % {
384 % \pgfsetstrokecolor{red}
385 % \pgfusepath{stroke}
386 % },
387 % {lineto}{\pgfdecoratedpathlength/5}
388 % {
389 % \pgfpathmoveto{\pgfpointdecoratedpathfirst}
390 % }
391 % {
392 % \pgfsetstrokecolor{black}
393 % \pgfusepath{stroke}
394 % }
395 % }
396 % \pgfpathmoveto{\pgfpointorigin}
397 % \pgfpathcurveto{\pgfpoint{0cm}{4cm}}{\pgfpoint{5cm}{0cm}}{\pgfpoint{5cm}{4cm}}
398 % \endpgfdecoration
399 %
400 % \endpgfpicture
401 %
402 %
403 %
404 % \pgfdeclaredecoration{polygons}{move}{
405 % \state{move}[width=7.5pt, next state=polygon]{}
406 % \state{polygon}[width=7.5pt, next state=move]
407 % {
408 % \pgfmathparse{round(rnd*100)}
409 % \pgfsetfillcolor{green!\pgfmathresult!yellow}
410 % \pgfsetstrokecolor{green!\pgfmathresult!brown}
411 % \pgfnode{regular polygon}{center}{}{}{\pgfusepath{stroke,fill}}
412 % }
413 % \state{final}
414 % {
415 % \pgfpathmoveto{\pgfpointdecoratedpathlast}
416 % }
417 % }
418 %
419 % \pgfpicture
420 % \pgfdecoration
421 % {
422 % {polygons}{45pt},
423 % {lineto}{30pt}
424 % {\pgfpathmoveto{\pgfpointdecoratedpathfirst}}
425 % {
426 % \pgfsetstrokecolor{yellow!50!orange}
427 % \pgfusepath{stroke}
428 % },
429 % {polygons}{45pt},
430 % {lineto}{30pt}
431 % {\pgfpathmoveto{\pgfpointdecoratedpathfirst}}
432 % {
433 % \pgfsetstrokecolor{green!50!blue}
434 % \pgfusepath{stroke}
435 % },
436 % {polygons}{\pgfdecoratedremainingdistance}
437 % }
438 % \pgfpathmoveto{\pgfpointorigin}
439 % \pgfpathcurveto{\pgfpoint{0cm}{4cm}}{\pgfpoint{5cm}{0cm}}{\pgfpoint{5cm}{4cm}}
440 % \endpgfdecoration
441 % \endpgfpicture
442 %
443 %
444 % \pgfpicture
445 % \pgfpathmoveto{\pgfpointorigin}
446 % \pgfpathcurveto{\pgfpoint{0cm}{4cm}}{\pgfpoint{5cm}{0cm}}{\pgfpoint{5cm}{4cm}}
447 % \pgfgetpath\temppath
448 % \pgfsetstrokecolor{red}
449 % \pgfusepath{stroke}
450 %
451 % \pgfset{decoration text={Here is some text all the way along this curve!}}
452 % \pgfdecoration{{text}{\pgfdecoratedremainingdistance}}
453 % \pgfsetpath\temppath
454 % \endpgfdecoration
455 % \endpgfpicture
456 %
457 \def\pgfdecoration#1{%
458 \begingroup%
459 \def\pgf@decorate@decorationlist{#1}%
460 \pgf@decoration@env%
461 }%
462
463 \def\endpgfdecoration{%
464 \pgf@decoration@endenv%
465 \ifx\pgfdecoratedpath\pgfutil@empty%
466 \else%
467 %
468 % Perform the decoration(s).
469 %
470 \pgf@decorate@for\pgf@temp:=\pgf@decorate@decorationlist\do{%
471 \ifx\pgf@temp\pgfutil@empty%
472 \else%
473 \expandafter\pgf@decorate@invoke\expandafter{\pgf@temp}%
474 \fi%
475 }%
476 \fi%
477 \pgfgetpath\pgfdecorationpath%
478 %
479 % Take stuff outside the group.
480 %
481 \global\let\pgf@decorate@decorationpathtemp\pgfdecorationpath%
482 \global\let\pgf@decorate@decoratedpathtemp\pgfdecoratedpath%
483 \global\let\pgf@decorate@existingpathtemp\pgfdecorateexistingpath%
484 \global\let\pgfpoint@decorated@pathlasttemp\pgfpoint@decorated@pathlast%
485 \endgroup%
486 %
487 % Are we in LaTeX?
488 %
489 \pgfutil@ifnextchar\@checkend{\aftergroup\pgf@decorate@installmacrosatend}%
490 {\pgf@decorate@installmacrosatend}%
491 }%
492
493
494
495 % Environment \pgfmetadecoration \endpgfmetadecoration
496 %
497 % Decorate a path with decoration automatons!
498 %
499 % Example:
500 %
501 % \pgfdeclaremetadecoration{fancy line}{line to}{
502 % \state{line to}[width=1cm, next state=zigzag]
503 % {
504 % \decoration{lineto}
505 % \beforedecoration{\pgfpathmoveto{\pgfpointdecoratedpathfirst}}
506 % \afterdecoration
507 % {
508 % \pgfsetstrokecolor{black}
509 % \pgfusepath{stroke}
510 % }
511 % }
512 % \state{zigzag}[width=2cm, next state=line to]
513 % {
514 % \decoration{zigzag}
515 % \beforedecoration{\pgfpathmoveto{\pgfpointdecoratedpathfirst}}
516 % \afterdecoration
517 % {
518 % \pgfsetstrokecolor{red}
519 % \pgfusepath{stroke}
520 % }
521 % }
522 % \state{final}
523 % {
524 % \decoration{lineto}
525 % \beforedecoration{\pgfpathmoveto{\pgfpointdecoratedpathfirst}}
526 % \afterdecoration
527 % {
528 % \pgfsetstrokecolor{black}
529 % \pgfusepath{stroke}
530 % }
531 % }
532 % }
533 %
534 % \pgfpicture
535 % \pgfmetadecoration{fancy line}
536 % \pgfpathmoveto{\pgfpointorigin}
537 % \pgfpathcurveto{\pgfqpoint{0cm}{2cm}}{\pgfqpoint{3cm}{2cm}}{\pgfqpoint{3cm}{0cm}}
538 % \pgfpathcurveto{\pgfqpoint{3cm}{-3cm}}{\pgfqpoint{0cm}{0cm}}{\pgfqpoint{0cm}{-3cm}}
539 % \pgfpathcurveto{\pgfqpoint{0cm}{-5cm}}{\pgfqpoint{3cm}{-5cm}}{\pgfqpoint{3cm}{-3cm}}
540 % \endpgfmetadecoration
541 % \endpgfpicture
542 %
543 \def\pgfmetadecoration#1{%
544 \begingroup%
545 \let\decoration\pgf@metadecoration@decoration%
546 \let\beforedecoration\pgf@metadecoration@beforedecoration%
547 \let\afterdecoration\pgf@metadecoration@afterdecoration%
548 \def\pgf@metadecoration@name{#1}%
549 \pgf@decoration@env%
550 }%
551
552 \def\endpgfmetadecoration{%
553 \pgf@decoration@endenv%
554 \ifx\pgfdecoratedpath\pgfutil@empty%
555 \else%
556 \let\pgfmetadecoratedpathlength\pgf@decorate@totalpathlength%
557 \def\pgfmetadecoratedinputsegmentremainingdistance{\pgfdecoratedremainingdistance}%
558 \def\pgfmetadecoratedinputsegmentcompleteddistance{\pgfdecoratedcompleteddistance}%
559 %
560 % Perform the meta decoration...
561 %
562 \expandafter\let\expandafter\pgf@metadecoration@current@state%
563 \csname pgf@metadecoration@@\pgf@metadecoration@name @initial\endcsname%
564 \pgf@metadecoration@run%
565 %
566 % ..until the final state.
567 %
568 \let\pgf@decorate@tempname\pgfutil@empty%
569 \let\pgf@decorate@tempbefore\pgfutil@empty%
570 \let\pgf@decorate@tempafter\pgfutil@empty%
571 \csname pgf@metadecoration@@\pgf@metadecoration@name @\pgf@metadecoration@current@state @code\endcsname%
572 \ifx\pgf@decorate@tempname\pgfutil@empty%
573 \def\pgf@decorate@tempname{moveto}
574 \fi%
575 \pgf@decorate@invoke{%
576 {\pgf@decorate@tempname}{\pgfdecoratedremainingdistance}%
577 {\pgf@decorate@tempbefore}{\pgf@decorate@tempafter}%
578 }%
579 \fi%
580 \pgfgetpath\pgfdecorationpath%
581 %
582 % Take stuff outside the group.
583 %
584 \global\let\pgf@decorate@decorationpathtemp\pgfdecorationpath%
585 \global\let\pgf@decorate@decoratedpathtemp\pgfdecoratedpath%
586 \global\let\pgf@decorate@existingpathtemp\pgfdecorateexistingpath%
587 \global\let\pgfpoint@decorated@pathlasttemp\pgfpoint@decorated@pathlast%
588 \endgroup%
589 %
590 % Are we in LaTeX?
591 %
592 \pgfutil@ifnextchar\@checkend{\aftergroup\pgf@decorate@installmacrosatend}%
593 {\pgf@decorate@installmacrosatend}%
594 }%
595
596
597
598
599
600
601 % Internal macro for the decoration environment.
602 %
603 \def\pgf@decoration@env{%
604 \pgfgetpath\pgfdecorateexistingpath%
605 \pgfsetpath\pgfutil@empty%
606 \let\pgfdecorationpath\pgfutil@empty%
607 \let\pgfdecoratedpath\pgfutil@empty%
608 \let\pgfpoint@decorated@pathlast\pgfpointorigin%
609 \edef\pgfpoint@decorate@existingpathlast{\pgf@x\the\pgf@path@lastx\pgf@y\the\pgf@path@lasty}%
610 %
611 % Begin a group so transformations don't mess things up.
612 %
613 \bgroup%
614 }%
615
616 \def\pgf@decorate@path@check@moveto#1{%
617 \expandafter\pgf@decorate@path@@check@moveto#1\pgf@decorate@stop\pgf@decorate@@stop}%
618
619 \def\pgf@decorate@token@stop{\pgf@decorate@stop}%
620 \def\pgf@decorate@path@@check@moveto#1#2#3#4\pgf@decorate@@stop#5#6{%
621 \def\pgf@decorate@temp{#4}%
622 \pgf@x=#2\relax%
623 \pgf@y=#3\relax%
624 \ifx\pgf@decorate@temp\pgf@decorate@token@stop%
625 #5%
626 \else%
627 #6%
628 \fi%
629 }%
630
631 \def\pgf@decoration@endenv{%
632 \egroup%
633 \pgftransformreset%
634 %
635 % Save the existing soft path and restore the existing path.
636 %
637 \pgfgetpath\pgfdecoratedpath%
638 \pgfsetpath\pgfdecorateexistingpath%
639 %
640 \ifx\pgfdecoratedpath\pgfutil@empty%
641 \pgferror{I cannot decorate an empty path}%
642 \else%
643 %
644 % If the path consists of a single moveto token, make it
645 % a very small horizontal line.
646 %
647 \pgf@decorate@path@check@moveto\pgfdecoratedpath{%
648 \advance\pgf@x by0.0001pt\relax%
649 \edef\pgfdecoratedpath{%
650 \expandafter\noexpand\pgfdecoratedpath%
651 \noexpand\pgfsyssoftpath@linetotoken{\the\pgf@x}{\the\pgf@y}%
652 }%
653 }%
654 {}%
655 %
656 % Remove special round tokens and get points.
657 %
658 \pgfprocessround{\pgfdecoratedpath}{\pgfdecoratedpath}%
659 %
660 % Parse the soft path into a series of decorated input segment objects.
661 %
662 \pgf@decorate@parsesoftpath{\pgfdecoratedpath}{\pgf@decorate@inputsegmentobjects}%
663 %
664 % Setup further options
665 %
666 \pgfkeys{/pgf/every decoration/.try}%
667 %
668 % Reverse objects if necessary.
669 %
670 \ifpgf@decorate@inputsegmentobjects@reverse%
671 \pgf@decorate@inputsegmentobjects@reverse{\pgf@decorate@inputsegmentobjects}{\pgf@decorate@inputsegmentobjects}%
672 \fi%
673 %
674 \let\pgf@decorated@remainingdistance\pgf@decorate@totalpathlength%
675 %
676 \let\pgfpoint@decorated@totalpathfirst\pgfpoint@decorated@firstparsed%
677 \let\pgfpoint@decorated@totalpathlast\pgfpoint@decorate@lastnonmovetoparsed%
678 %
679 \let\pgfpoint@decorated@pathfirst\pgfpoint@decorated@totalpathfirst
680 \let\pgfpoint@decorated@pathlast\pgfpoint@decorated@totalpathlast%
681 %
682 % Set up the first input segment.
683 %
684 \let\pgf@decorate@currentinputsegmentobjects\pgf@decorate@inputsegmentobjects%
685 \let\pgf@decorate@transformtoinputsegment\pgfutil@empty%
686 \pgf@decorate@getnextinputsegmentobject\pgf@decorate@nextinputsegmentobject%
687 \pgf@decorate@processnextinputsegmentobject%
688 \pgf@decorate@distancetomove0pt\relax%
689 \fi%
690 }%
691
692
693
694
695 \def\pgf@decorate@installmacrosatend{%
696 \let\pgfdecorationpath\pgf@decorate@decorationpathtemp%
697 \let\pgfdecoratedpath\pgf@decorate@decoratedpathtemp%
698 \let\pgfdecorateexistingpath\pgf@decorate@existingpathtemp%
699 \let\pgfpoint@decorated@pathlast\pgfpoint@decorated@pathlasttemp%
700 }%
701
702 \let\pgfdecorationpath\pgfutil@empty
703 \let\pgfdecoratedpath\pgfutil@empty
704 \let\pgfdecorateexisitingpath\pgfutil@empty
705
706 \let\pgfpoint@decorated@pathlast\pgfpointorigin
707
708
709
710 % A version of \pgfutil@for which doesn't expand each value in #3.
711 %
712 \def\pgf@decorate@for#1:=#2\do#3{%
713 \def\pgf@decorate@for@var{#1}%
714 \def\pgf@decorate@for@action{#3}%
715 \expandafter\pgf@decorate@@for#2,\pgf@stop,}%
716
717 \def\pgf@decorate@@for#1,{%
718 \ifx#1\pgf@stop%
719 \expandafter\let\pgf@decorate@for@var\pgfutil@empty%
720 \else%
721 \expandafter\def\pgf@decorate@for@var{#1}%
722 \pgf@decorate@for@action%
723 \expandafter\pgf@decorate@@for%
724 \fi%
725 }%
726
727
728 % Invoke a decoration.
729 %
730 % #1 - {<name>}{<distance>}{<before code>}{<after code>}
731 %
732 \def\pgf@decorate@invoke#1{%
733 \pgf@decorate@@invoke#1\pgf@decorate@invoke\pgf@decorate@invoke\pgf@decorate@invoke\pgf@stop}%
734
735 \def\pgf@decorate@@invoke#1#2#3#4#5\pgf@stop{%
736 \pgfutil@ifundefined{pgf@decorate@@#1@initial}%
737 {%
738 \pgferror{Unknown decoration `#1'}%
739 }%
740 {%
741 \def\pgf@decorate@name{#1}%
742 \ifx\pgf@decorate@invoke#3%
743 \let\pgf@decorate@beforecode\pgfutil@empty%
744 \else%
745 \def\pgf@decorate@beforecode{#3}%
746 \fi%
747 \ifx\pgf@decorate@invoke#4%
748 \let\pgf@decorate@aftercode\pgfutil@empty%
749 \else%
750 \def\pgf@decorate@aftercode{#4}%
751 \fi%
752 %
753 % Make remaining distance and the decorated path length `public'.
754 %
755 \pgfdecoratedremainingdistance\pgf@decorated@remainingdistance\relax%
756 \let\pgfdecoratedpathlength\pgf@decorate@totalpathlength%
757 %
758 \pgfmathsetlength\pgf@xa{#2}%
759 \ifdim\pgf@xa>\pgf@decorated@remainingdistance\relax%
760 \pgf@xa\pgf@decorated@remainingdistance\relax%
761 \fi%
762 \edef\pgf@decorate@currentpathlength{\the\pgf@xa}%
763 %
764 % Calculate the distance remaining to the end of the entire path.
765 %
766 \pgf@xa-\pgf@decorate@currentpathlength\relax%
767 \advance\pgf@xa\pgf@decorated@remainingdistance\relax%
768 \edef\pgf@decorated@remainingdistance{\the\pgf@xa}%
769 %
770 % Set up the macros and distances for the current section
771 % of the decorated path.
772 %
773 \let\pgfdecoratedpathlength\pgf@decorate@currentpathlength%
774 \pgfdecoratedremainingdistance\pgfdecoratedpathlength\relax%
775 \pgfdecoratedcompleteddistance0pt\relax%
776 %
777 % Execute user-defined code beore decoration.
778 %
779 \pgf@decorate@beforecode%
780 %
781 % Run the decoration...
782 %
783 \expandafter\let\expandafter\pgf@decorate@current@state%
784 \csname pgf@decorate@@\pgf@decorate@name @initial\endcsname%
785 \pgf@decorate@run%
786 %
787 % ...until the final state.
788 %
789 \ifdim\pgf@decorated@remainingdistance<1pt\relax% Should be =0pt, but need to control for inaccuracies.
790 \let\pgfpoint@decorated@pathlast\pgfpoint@decorated@totalpathlast%
791 \else%
792 %
793 % Set up \pgfpoint@decorated@pathlast if the end of
794 % the total decorated path has not been reached.
795 %
796 {%
797 \pgf@decorate@movealonginputsegment{\the\pgfdecoratedremainingdistance}%
798 \pgf@decorate@transformtoinputsegment%
799 \pgfpointorigin%
800 \pgf@pos@transform@glob%
801 \global\pgf@x\pgf@x%
802 \global\pgf@y\pgf@y%
803 }%
804 \edef\pgfpoint@decorated@pathlast{\pgf@x\the\pgf@x\pgf@y\the\pgf@y}%
805 \fi%
806 {%
807 \pgftransformreset%
808 \pgf@decorate@transformtoinputsegment%
809 \pgf@decorate@additionaltransform%
810 \csname pgf@decorate@@\pgf@decorate@name @final@code\endcsname%
811 }%
812 \pgf@decorate@movealonginputsegment{\the\pgfdecoratedremainingdistance}%
813 %
814 % Execute user-defined code after decoration.
815 %
816 \pgf@decorate@aftercode%
817 %
818 % Update the input segment objects.
819 %
820 \let\pgf@decorate@additionaltransform\pgfutil@empty%
821 \let\pgf@decorate@inputsegmentobjects\pgf@decorate@inputsegmentobjects@aftersplit%
822 \let\pgfpoint@decorated@pathfirst\pgfpoint@decorated@pathlast%
823 }%
824 }%
825
826
827
828 \let\pgf@decorate@transformtoinputsegment\pgfutil@empty%
829 \let\pgf@decorate@additionaltransform\pgfutil@empty%
830
831
832 % \pgfpointdecoratedpathfirst
833 %
834 \def\pgfpointdecoratedpathfirst{%
835 {%
836 \pgftransforminvert%
837 \pgfpoint@decorated@pathfirst%
838 \pgf@pos@transform@glob%
839 \global\pgf@x\pgf@x%
840 \global\pgf@y\pgf@y%
841 }%
842 }%
843
844 % \pgfpointdecoratedpathlast
845 %
846 \def\pgfpointdecoratedpathlast{%
847 {%
848 \pgftransforminvert%
849 \pgfpoint@decorated@pathlast%
850 \pgf@pos@transform@glob%
851 \global\pgf@x\pgf@x%
852 \global\pgf@y\pgf@y%
853 }%
854 }%
855
856 % \pgfpointdecoratedinputsegmentfirst
857 %
858 % The first point of the current sub-path.
859 %
860 \def\pgfpointdecoratedinputsegmentfirst{%
861 {%
862 \pgftransforminvert%
863 \pgf@decorate@inputsegment@first%
864 \pgf@pos@transform@glob%
865 \global\pgf@x\pgf@x%
866 \global\pgf@y\pgf@y%
867 }%
868 }%
869
870 % \pgfpointdecoratedinputsegmentlast
871 %
872 % The final point of the current sub-path.
873 %
874 \def\pgfpointdecoratedinputsegmentlast{%
875 {%
876 \pgftransforminvert%
877 \pgf@decorate@inputsegment@last%
878 \pgf@pos@transform@glob%
879 \global\pgf@x\pgf@x%
880 \global\pgf@y\pgf@y%
881 }%
882 }%
883
884
885 \def\pgf@final@text{final}%
886
887 % Run a normal decoration.
888 %
889 \def\pgf@decorate@run{%
890 \let\pgf@decorate@next\pgf@decorate@do@state%
891 \ifx\pgf@decorate@current@state\pgf@final@text%
892 \let\pgf@decorate@next\relax%
893 \fi%
894 \pgf@decorate@next%
895 }%
896
897 \def\pgf@decorate@do@state{%
898 \let\pgf@decorate@next\relax%
899 \let\pgf@decorate@next@state\pgf@decorate@current@state%
900 %
901 % Get the options.
902 %
903 \let\pgf@decorate@persistent@pre=\relax%
904 \let\pgf@decorate@persistent@post=\relax%
905 \expandafter\expandafter\expandafter\pgf@decorate@setter
906 \expandafter\expandafter\expandafter{\csname pgf@decorate@@\pgf@decorate@name @\pgf@decorate@current@state @options\endcsname}%
907 \ifx\pgf@decorate@next\relax%
908 \let\pgf@decorate@next\pgf@decorate@do@code%
909 \fi%
910 \pgf@decorate@next%
911 }%
912
913 \def\pgf@decorate@setter{\pgfqkeys{/pgf/decoration automaton}}%
914
915 \pgf@decorate@repeatstate-1\relax
916
917 \def\pgf@decorate@do@code{%
918 %
919 % Execute code.
920 %
921 \pgf@decorate@persistent@pre%
922 {%
923 \pgftransformreset%
924 \pgf@decorate@transformtoinputsegment%
925 \pgf@decorate@additionaltransform%
926 \csname pgf@decorate@@\pgf@decorate@name @\pgf@decorate@current@state @code\endcsname%
927 }%
928 \pgf@decorate@persistent@post%
929 \pgf@decorate@movealongpath{\pgf@decorate@width}%
930 %
931 % Next iteration.
932 %
933 \ifnum\pgf@decorate@repeatstate>0\relax%
934 \advance\pgf@decorate@repeatstate-1\relax%
935 \else%
936 \pgf@decorate@repeatstate-1\relax%
937 \let\pgf@decorate@current@state\pgf@decorate@next@state%
938 \fi%
939 \pgf@decorate@run%
940 }%
941
942 \pgfkeys{
943 /pgf/decoration automaton/width/.code=\def\pgf@decorate@width{#1}\pgf@decorate@switch@if#1 to final\pgf@stop,%
944 /pgf/decoration automaton/switch if less than/.code=\pgf@decorate@switch@if#1\pgf@stop,%
945 /pgf/decoration automaton/switch if input segment less than/.code=\pgf@decorate@switch@ifinputsegment#1\pgf@stop,%
946 /pgf/decoration automaton/next state/.store in=\pgf@decorate@next@state,%
947 /pgf/decoration automaton/persistent precomputation/.store in=\pgf@decorate@persistent@pre,%
948 /pgf/decoration automaton/persistent postcomputation/.store in=\pgf@decorate@persistent@post,%
949 /pgf/decoration automaton/repeat state/.code={%
950 \ifnum\pgf@decorate@repeatstate=-1\relax%
951 \pgfmathsetcount\pgf@decorate@repeatstate{#1}%
952 \fi%
953 },%
954 /pgf/decoration automaton/if input segment is closepath/.code={%
955 \ifpgf@decorate@is@closepath@%
956 \pgfkeysalso{#1}%
957 \fi%
958 },
959 /pgf/decoration automaton/auto end on length/.code=\pgf@decorate@auto@end{#1},
960 /pgf/decoration automaton/auto corner on length/.code=\pgf@decorate@auto@corner{#1},
961 }%
962
963 \def\pgf@decorate@auto@end#1{%
964 \ifx\pgf@decorate@next\relax%
965 \pgfmathsetlength\pgf@x{#1}%
966 \ifpgf@decorate@is@closepath@%
967 \ifdim\pgfdecoratedremainingdistance>\pgf@x%
968 \ifdim\pgfdecoratedinputsegmentremainingdistance>\pgf@x%
969 \else%
970 \pgfpathclose%
971 \pgf@decorate@movealongpath{\pgfdecoratedinputsegmentremainingdistance}%
972 \pgf@decorate@repeatstate-1\relax%
973 \let\pgf@decorate@next\pgf@decorate@run%
974 \fi%
975 \else%
976 \pgfpathclose%
977 \def\pgf@decorate@current@state{final}%
978 \def\pgf@decorate@width{\pgfdecoratedremainingdistance}
979 \pgf@decorate@repeatstate-1\relax%
980 \let\pgf@decorate@next\pgf@decorate@run%
981 \fi%
982 \else%
983 \ifdim\pgfdecoratedremainingdistance>\pgf@x%
984 \else%
985 {%
986 \pgftransformreset%
987 \pgf@decorate@transformtoinputsegment%
988 \pgf@decorate@additionaltransform%
989 \pgfpathlineto{\pgfpoint{\pgfdecoratedremainingdistance}{0pt}}
990 }%
991 \def\pgf@decorate@current@state{final}%
992 \def\pgf@decorate@width{\pgfdecoratedremainingdistance}
993 \pgf@decorate@repeatstate-1\relax%
994 \let\pgf@decorate@next\pgf@decorate@run%
995 \fi%
996 \fi%
997 \fi%
998 }%
999
1000 \def\pgf@decorate@auto@corner#1{%
1001 \ifpgfdecoratepathhascorners%
1002 \ifx\pgf@decorate@next\relax%
1003 \pgfmathsetlength\pgf@x{#1}%
1004 \ifdim\pgfdecoratedinputsegmentremainingdistance>\pgf@x%
1005 \else%
1006 {%
1007 \pgftransformreset%
1008 \pgf@decorate@transformtoinputsegment%
1009 \pgf@decorate@additionaltransform%
1010 \pgfpathlineto{\pgfqpoint{\pgfdecoratedinputsegmentremainingdistance}{0pt}}
1011 }%
1012 \pgf@decorate@movealongpath{\pgfdecoratedinputsegmentremainingdistance}%
1013 \pgf@decorate@repeatstate-1\relax%
1014 \let\pgf@decorate@next\pgf@decorate@run%
1015 \fi%
1016 \fi%
1017 \fi%
1018 }%
1019
1020 \def\pgf@decorate@switch@if#1to #2\pgf@stop{%
1021 \ifx\pgf@decorate@next\relax%
1022 \ifdim\pgfdecoratedremainingdistance=0pt\relax%
1023 \def\pgf@decorate@current@state{#2}%
1024 \pgf@decorate@repeatstate-1\relax%
1025 \let\pgf@decorate@next\pgf@decorate@run%
1026 \else%
1027 \pgfmathsetlength\pgf@x{#1}%
1028 \ifdim\pgfdecoratedremainingdistance<\pgf@x%
1029 \def\pgf@decorate@current@state{#2}%
1030 \pgf@decorate@repeatstate-1\relax%
1031 \let\pgf@decorate@next\pgf@decorate@run%
1032 \fi%
1033 \fi%
1034 \fi%
1035 }%
1036
1037 \def\pgf@decorate@switch@ifinputsegment#1to #2\pgf@stop{%
1038 \ifx\pgf@decorate@next\relax%
1039 \pgfmathsetlength\pgf@x{#1}%
1040 \ifdim\pgfdecoratedinputsegmentremainingdistance<\pgf@x%
1041 \def\pgf@decorate@current@state{#2}%
1042 \pgf@decorate@repeatstate-1\relax%
1043 \let\pgf@decorate@next\pgf@decorate@run%
1044 \fi%
1045 \fi%
1046 }%
1047
1048
1049
1050
1051 % \pgfsetdecorationsegmenttransformation
1052 %
1053 % Set the additional transform for each decoration state.
1054 %
1055 % Example:
1056 %
1057 % \pgfsetdecorationsegmenttransformation{\pgftransformyshift{5pt}}
1058 %
1059 \def\pgfsetdecorationsegmenttransformation#1{\def\pgf@decorate@additionaltransform{#1}}%
1060 \let\pgf@decorate@additionaltransform\pgfutil@empty%
1061
1062
1063
1064
1065 \def\pgf@metadecoration@decoration#1{%
1066 \edef\pgf@decorate@tempname{#1}%
1067 }%
1068 \def\pgf@metadecoration@beforedecoration#1{%
1069 \def\pgf@decorate@tempbefore{#1}%
1070 }%
1071 \def\pgf@metadecoration@afterdecoration#1{%
1072 \def\pgf@decorate@tempafter{#1}%
1073 }%
1074
1075
1076 \def\pgf@final@text{final}%
1077
1078 % Run a meta decoration.
1079 %
1080 \def\pgf@metadecoration@run{%
1081 \let\pgf@metadecoration@next\pgf@metadecoration@do@state%
1082 \ifx\pgf@metadecoration@current@state\pgf@final@text%
1083 \let\pgf@metadecoration@next\relax%
1084 \fi%
1085 \pgf@metadecoration@next%
1086 }%
1087
1088 \def\pgf@metadecoration@do@state{%
1089 \let\pgf@metadecoration@next\relax%
1090 \let\pgf@metadecoration@next@state\pgf@metadecoration@current@state%
1091 %
1092 % Set up some macros.
1093 %
1094 \let\pgfmetadecoratedremainingdistance\pgf@decorated@remainingdistance%
1095 \pgf@x-\pgfmetadecoratedremainingdistance\relax%
1096 \advance\pgf@x\pgf@decorate@totalpathlength\relax%
1097 \edef\pgfmetadecoratedcompleteddistance{\the\pgf@x}%
1098 %
1099 % Get the options.
1100 %
1101 \expandafter\expandafter\expandafter\pgf@metadecoration@setter
1102 \expandafter\expandafter\expandafter{\csname pgf@metadecoration@@\pgf@metadecoration@name @\pgf@metadecoration@current@state @options\endcsname}%
1103 \ifx\pgf@metadecoration@next\relax%
1104 \let\pgf@metadecoration@next\pgf@metadecoration@do@code%
1105 \fi%
1106 \pgf@metadecoration@next%
1107 }%
1108
1109 \def\pgf@metadecoration@do@code{%
1110 %
1111 % Execute code.
1112 %
1113 \let\pgf@decorate@tempname\pgfutil@empty%
1114 \let\pgf@decorate@tempbefore\pgfutil@empty%
1115 \let\pgf@decorate@tempafter\pgfutil@empty%
1116 \let\pgfpointmetadecoratedpathfirst\pgfpointdecoratedpathfirst%
1117 \let\pgfpointmetadecoratedpathlast\pgfpointdecoratedpathlast%
1118 \csname pgf@metadecoration@@\pgf@metadecoration@name @\pgf@metadecoration@current@state @code\endcsname%
1119 \ifx\pgf@decorate@tempname\pgfutil@empty%
1120 \def\pgf@decorate@tempname{moveto}
1121 \fi%
1122 \pgf@decorate@invoke{%
1123 {\pgf@decorate@tempname}{\pgf@metadecoration@width}%
1124 {\pgf@decorate@tempbefore}{\pgf@decorate@tempafter}%
1125 }%
1126 %
1127 % Next iteration.
1128 %
1129 \let\pgf@metadecoration@current@state\pgf@metadecoration@next@state%
1130 \pgf@metadecoration@run%
1131 }%
1132
1133 \def\pgf@metadecoration@setter{\pgfqkeys{/pgf/meta-decoration automaton}}%
1134
1135 \pgfkeys{
1136 /pgf/meta-decoration automaton/width/.code=\def\pgf@metadecoration@width{#1}\pgf@metadecoration@switch@if#1 to final\pgf@stop,%
1137 /pgf/meta-decoration automaton/switch if less than/.code=\pgf@metadecoration@switch@if#1\pgf@stop,%
1138 /pgf/meta-decoration automaton/switch if input segment less than/.code=\pgf@metadecoration@switch@ifinputsegment#1\pgf@stop,%
1139 /pgf/meta-decoration automaton/next state/.store in=\pgf@metadecoration@next@state,%
1140 }%
1141
1142 \def\pgf@metadecoration@switch@if#1to #2\pgf@stop{%
1143 \ifx\pgf@metadecoration@next\relax%
1144 \pgfmathsetlength\pgf@x{#1}%
1145 \ifdim\pgf@decorated@remainingdistance<\pgf@x%
1146 \def\pgf@metadecoration@current@state{#2}%
1147 \let\pgf@metadecoration@next\pgf@metadecoration@run%
1148 \fi%
1149 \fi%
1150 }%
1151
1152 \def\pgf@metadecoration@switch@ifinputsegment#1to #2\pgf@stop{%
1153 \ifx\pgf@metadecoration@next\relax%
1154 \pgfmathsetlength\pgf@x{#1}%
1155 \ifdim\pgfdecoratedinputsegmentremainingdistance<\pgf@x%
1156 \def\pgf@metadecoration@current@state{#2}%
1157 \let\pgf@metadecoration@next\pgf@metadecoration@run%
1158 \fi%
1159 \fi%
1160 }%
1161
1162
1163
1164 % Move along the path by a specified distance.
1165 %
1166 \def\pgf@decorate@movealongpath#1{%
1167 \pgfmathsetlength\pgf@decorate@distancetomove{#1}%
1168 \advance\pgfdecoratedcompleteddistance\pgf@decorate@distancetomove%
1169 \advance\pgfdecoratedremainingdistance-\pgf@decorate@distancetomove%
1170 \pgf@decorate@@movealongpath%
1171 }%
1172 \def\pgf@decorate@@movealongpath{%
1173 \advance\pgfdecoratedinputsegmentcompleteddistance\pgf@decorate@distancetomove%
1174 \advance\pgfdecoratedinputsegmentremainingdistance-\pgf@decorate@distancetomove%
1175 \ifdim\pgfdecoratedinputsegmentremainingdistance>0pt\relax%
1176 \let\pgf@next\pgf@decorate@@@movealongpath%
1177 \else%
1178 \pgf@decorate@distancetomove-\pgfdecoratedinputsegmentremainingdistance%
1179 \pgf@decorate@processnextinputsegmentobject%
1180 \ifx\pgf@decorate@currentinputsegmentobjects\pgfutil@empty%
1181 \pgfdecoratedremainingdistance0pt\relax%
1182 \let\pgf@next\relax%
1183 \else%
1184 \let\pgf@next\pgf@decorate@@movealongpath%
1185 \fi%
1186 \fi%
1187 \pgf@next%
1188 }%
1189
1190 \def\pgf@decorate@@@movealongpath{%
1191 %
1192 % Move along input segment for real.
1193 %
1194 \pgf@decorate@movealonginputsegment{\the\pgf@decorate@distancetomove}%
1195 \pgf@decorate@distancetomove0pt\relax%
1196 %
1197 % Grrr. Hacking to control some inaccuracies.
1198 %
1199 \ifdim\pgf@decorate@inputsegmenttime pt>1pt\relax%
1200 \let\pgf@decorate@inputsegmenttimetemp\pgf@decorate@inputsegmenttime%
1201 \pgf@decorate@processnextinputsegmentobject%
1202 \pgf@x\pgf@decorate@inputsegmenttimetemp pt\relax%
1203 \advance\pgf@x-1pt\relax%
1204 \edef\pgf@decorate@inputsegmenttime{\pgfmath@tonumber{\pgf@x}}%
1205 \ifx\pgf@decorate@currentinputsegmentobjects\pgfutil@empty%
1206 \pgfdecoratedremainingdistance0pt\relax%
1207 \fi%
1208 \fi%
1209 }%
1210
1211 % Return the next input segment object in a macro
1212 %
1213 \def\pgf@decorate@getnextinputsegmentobject#1{%
1214 \ifx\pgf@decorate@currentinputsegmentobjects\pgfutil@empty%
1215 \let\pgf@next\relax%
1216 \else%
1217 \def\pgf@decorate@temp{#1}%
1218 \let\pgf@next\pgf@decorate@@getnextinputsegmentobject%
1219 \fi%
1220 \pgf@next%
1221 }%
1222 \def\pgf@decorate@@getnextinputsegmentobject{%
1223 \expandafter\pgf@decorate@@@getnextinputsegmentobject\pgf@decorate@currentinputsegmentobjects\pgf@stop}%
1224 \def\pgf@decorate@@@getnextinputsegmentobject#1#2\pgf@stop{%
1225 \expandafter\def\pgf@decorate@temp{#1}%
1226 \def\pgf@decorate@currentinputsegmentobjects{#2}}%
1227
1228 % Process the next input segment object.
1229 %
1230 \def\pgf@decorate@processnextinputsegmentobject{%
1231 \let\pgfdecorationpreviousinputsegment\pgfdecoratecurrentinputsegment%
1232 \let\pgf@decorate@currentinputsegmentobject\pgf@decorate@nextinputsegmentobject%
1233 \pgf@decorate@getnextinputsegmentobject\pgf@decorate@nextinputsegmentobject%
1234 %
1235 % If the current input segment object is a moveto, execute the
1236 % object macro and get the next input segment object.
1237 %
1238 \pgf@decorate@is@closepath@false%
1239 \pgf@decorate@currentinputsegmentobject%
1240 \ifx\pgfdecorationcurrentinputsegment\pgfdecorationinputsegmentmoveto%
1241 \pgfpathmoveto{\pgf@decorate@inputsegment@first}%
1242 \let\pgfdecorationpreviousinputsegment\pgfdecorationcurrentinputsegment%
1243 \let\pgf@decorate@currentinputsegmentobject\pgf@decorate@nextinputsegmentobject%
1244 \pgf@decorate@getnextinputsegmentobject\pgf@decorate@nextinputsegmentobject%
1245 \pgf@decorate@is@closepath@false%
1246 \pgf@decorate@currentinputsegmentobject%
1247 \fi%
1248 %
1249 % Teensy hack in case a path goes nowhere.
1250 %
1251 \ifdim\pgfdecoratedinputsegmentlength=0pt\relax%
1252 \def\pgfdecoratedinputsegmentlength{0.05pt}% Arbitrary choice >0pt.
1253 \fi%
1254 \pgfdecoratedinputsegmentremainingdistance\pgfdecoratedinputsegmentlength\relax%
1255 \pgfdecoratedinputsegmentcompleteddistance0pt\relax%
1256 \def\pgf@decorate@inputsegmenttime{0}%
1257 %
1258 % Get the angle at the start of the input segment.
1259 %
1260 \ifx\pgfdecorationcurrentinputsegment\pgfdecorationinputsegmentcurveto%
1261 \pgfmathanglebetweenpoints{\pgf@decorate@inputsegment@first}{\pgf@decorate@inputsegment@supporta}%
1262 \let\pgfdecoratedangle\pgfmathresult%
1263 \let\pgfdecoratedinputsegmentstartangle\pgfmathresult%
1264 \pgfmathanglebetweenpoints{\pgf@decorate@inputsegment@supportb}{\pgf@decorate@inputsegment@last}%
1265 \let\pgfdecoratedinputsegmentendangle\pgfmathresult%
1266 \else%
1267 \pgfmathanglebetweenpoints{\pgf@decorate@inputsegment@first}{\pgf@decorate@inputsegment@last}%
1268 \let\pgfdecoratedangle\pgfmathresult%
1269 \let\pgfdecoratedinputsegmentstartangle\pgfmathresult%
1270 \let\pgfdecoratedinputsegmentendangle\pgfmathresult%
1271 \fi%
1272 %
1273 % Get the angle to the next input segment.
1274 %
1275 \begingroup%
1276 \pgf@decorate@nextinputsegmentobject%
1277 \global\let\pgf@decorate@temp\pgfdecorationcurrentinputsegment%
1278 \ifx\pgfdecorationcurrentinputsegment\pgfdecorationinputsegmentmoveto%
1279 \expandafter\pgf@decorate@currentinputsegmentobject%
1280 \fi%
1281 \ifx\pgfdecorationcurrentinputsegment\pgfdecorationinputsegmentcurveto%
1282 \pgfmathanglebetweenpoints{\pgf@decorate@inputsegment@first}{\pgf@decorate@inputsegment@supporta}%
1283 \else%
1284 \pgfmathanglebetweenpoints{\pgf@decorate@inputsegment@first}{\pgf@decorate@inputsegment@last}%
1285 \fi%
1286 \pgf@x-\pgfdecoratedangle pt\relax%
1287 \advance\pgf@x\pgfmathresult pt\relax%
1288 \edef\pgfdecoratedangletonextinputsegment{\the\pgf@x}%
1289 \pgfmath@smuggleone\pgfdecoratedangletonextinputsegment%
1290 \endgroup%
1291 \let\pgfdecorationnextinputsegmentobject\pgf@decorate@temp%
1292 }%
1293
1294
1295 %
1296 % Input segment objects
1297 %
1298
1299 \newif\ifpgf@decorate@is@closepath@%
1300
1301 % Input segment types.
1302 %
1303 % These allow comparison with \ifx using
1304 %
1305 % \pgfdecorationcurrentinputsegment
1306 % \pgfdecorationnextinputsegment
1307 % \pgfdecorationcurrentprevioussegment
1308 %
1309 \def\pgfdecorationinputsegmentmoveto{moveto}%
1310 \def\pgfdecorationinputsegmentlineto{lineto}%
1311 \def\pgfdecorationinputsegmentcurveto{curveto}%
1312 \def\pgfdecorationinputsegmentclosepath{closepath}%
1313 \def\pgfdecorationinputsegmentlast{last}%
1314
1315 % Input segment object moveto.
1316 %
1317 \def\pgf@decorate@inputsegmentobject@moveto#1{%
1318 \def\pgf@decorate@inputsegment@first{#1}%
1319 \def\pgf@decorate@inputsegment@supporta{#1}%
1320 \def\pgf@decorate@inputsegment@supportb{#1}%
1321 \def\pgf@decorate@inputsegment@last{#1}%
1322 \edef\pgf@decorate@lastmoveto{#1}%
1323 \def\pgfdecoratedinputsegmentlength{0pt}%
1324 \let\pgfdecorationcurrentinputsegment\pgfdecorationinputsegmentmoveto%
1325 }%
1326
1327 % Input segment object lineto.
1328 %
1329 \def\pgf@decorate@inputsegmentobject@lineto#1#2#3{%
1330 \def\pgfdecoratedinputsegmentlength{#1}%
1331 \def\pgf@decorate@inputsegment@first{#2}%
1332 \def\pgf@decorate@inputsegment@last{#3}%
1333 %
1334 % Supports should be defined like this, so if treated as a curve,
1335 % equal time steps will correspond to equal distances.
1336 %
1337 \pgfpointdiff{#2}{#3}%
1338 \pgf@xa\pgf@x%
1339 \pgf@ya\pgf@y%
1340 \pgfextract@process\pgf@decorate@inputsegment@supporta{%
1341 \pgf@process{#2}%
1342 \advance\[email protected]\pgf@xa%
1343 \advance\[email protected]\pgf@ya%
1344 }%
1345 \pgfextract@process\pgf@decorate@inputsegment@supportb{%
1346 \pgf@process{#2}%
1347 \advance\[email protected]\pgf@xa%
1348 \advance\[email protected]\pgf@ya%
1349 }%
1350 \let\pgf@decorate@movealonginputsegment\pgf@decorate@movealonginputsegment@line%
1351 \let\pgf@decorate@transformtoinputsegment\pgf@decorate@transformtoinputsegment@line%
1352 \let\pgfdecorationcurrentinputsegment\pgfdecorationinputsegmentlineto%
1353 }%
1354
1355 % Input segment object curveto.
1356 %
1357 \def\pgf@decorate@inputsegmentobject@curveto#1#2#3#4#5{%
1358 \def\pgfdecoratedinputsegmentlength{#1}%
1359 \def\pgf@decorate@inputsegment@first{#2}%
1360 \def\pgf@decorate@inputsegment@supporta{#3}%
1361 \def\pgf@decorate@inputsegment@supportb{#4}%
1362 \def\pgf@decorate@inputsegment@last{#5}%
1363 %
1364 \let\pgf@decorate@movealonginputsegment\pgf@decorate@movealonginputsegment@curve%
1365 \let\pgf@decorate@transformtoinputsegment\pgf@decorate@transformtoinputsegment@curve%
1366 \let\pgfdecorationcurrentinputsegment\pgfdecorationinputsegmentcurveto%
1367 }%
1368
1369 % Input segment object closepath.
1370 %
1371 % Treated like a lineto, but flag that it is a closepath.
1372 %
1373 \def\pgf@decorate@inputsegmentobject@closepath#1#2#3{%
1374 \pgf@decorate@is@closepath@true%
1375 %
1376 \def\pgfdecoratedinputsegmentlength{#1}%
1377 \def\pgf@decorate@inputsegment@first{#2}%
1378 \def\pgf@decorate@inputsegment@last{#3}%
1379 %
1380 \pgfpointdiff{#2}{#3}%
1381 \pgf@xa\pgf@x%
1382 \pgf@ya\pgf@y%
1383 \pgfextract@process\pgf@decorate@inputsegment@supporta{%
1384 \pgf@process{#2}%
1385 \advance\[email protected]\pgf@xa%
1386 \advance\[email protected]\pgf@ya%
1387 }%
1388 \pgfextract@process\pgf@decorate@inputsegment@supportb{%
1389 \pgf@process{#2}%
1390 \advance\[email protected]\pgf@xa%
1391 \advance\[email protected]\pgf@ya%
1392 }%
1393 %
1394 \let\pgf@decorate@movealonginputsegment\pgf@decorate@movealonginputsegment@line%
1395 \let\pgf@decorate@transformtoinputsegment\pgf@decorate@transformtoinputsegment@line%
1396 \let\pgfdecorationcurrentinputsegment\pgfdecorationinputsegmentclosepath%
1397 }%
1398
1399
1400 % Input segment object endofinputsegments.
1401 %
1402 \def\pgf@decorate@inputsegmentobject@endofinputsegments{%
1403 \let\pgfdecorationcurrentinputsegment\pgfdecorationinputsegmentlast%
1404 }%
1405
1406
1407
1408
1409 % This macro controls how the automaton moves along a line sub-path
1410 %
1411 \def\pgf@decorate@movealonginputsegment@line#1{}% Nothing special needed.
1412
1413 % This macro controls how the automaton moves along a curve sub-path.
1414 %
1415 \def\pgf@decorate@movealonginputsegment@curve#1{%
1416 \ifdim#1=0pt\relax%
1417 \else%
1418 \pgfpointcurveattime{\pgf@decorate@inputsegmenttime}%
1419 {\pgf@decorate@inputsegment@first}{\pgf@decorate@inputsegment@supporta}%
1420 {\pgf@decorate@inputsegment@supportb}{\pgf@decorate@inputsegment@last}%
1421 \pgf@xa\pgf@x%
1422 \pgf@ya\pgf@y%
1423 \pgf@xb\pgf@decorate@inputsegmenttime pt\relax%
1424 %
1425 % Reduce the initial time step, depending on the length
1426 % of the path. To do: Optimise this step (should also depend on #1).
1427 %
1428 \ifdim\pgf@decorate@currentpathlength<128pt\relax%
1429 \[email protected]\relax%
1430 \else%
1431 \ifdim\pgf@decorate@currentpathlength<512pt\relax%
1432 \[email protected]\relax%
1433 \else%
1434 \ifdim\pgf@decorate@currentpathlength<2048pt\relax%
1435 \[email protected]\relax%
1436 \else%
1437 \[email protected]\relax%
1438 \fi%
1439 \fi%
1440 \fi%
1441 \c@pgf@counta1\relax%
1442 \pgfutil@tempdima0pt\relax%
1443 \pgfmathloop%
1444 \advance\pgf@xb\c@pgf@counta\pgf@yb%
1445 %
1446 % We would like to use \pgfpointcurveattime. However, we must not
1447 % overuse \pgf@process or \pgfmath stuff within this loop,
1448 % otherwise we increase the chances of save stack overflow.
1449 %
1450 \edef\pgf@decorate@temp{%
1451 \pgf@xa\the\pgf@xa%
1452 \pgf@xb\the\pgf@xb%
1453 \pgf@ya\the\pgf@ya%
1454 \pgf@yb\the\pgf@yb%
1455 }%
1456 %
1457 \pgfpoint@decorate@curveattime{\pgfmath@tonumber{\pgf@xb}}%
1458 {\pgf@decorate@inputsegment@first}{\pgf@decorate@inputsegment@supporta}%
1459 {\pgf@decorate@inputsegment@supportb}{\pgf@decorate@inputsegment@last}%
1460 \pgf@decorate@temp%
1461 %
1462 \pgf@xc\pgf@xa%
1463 \pgf@yc\pgf@ya%
1464 \pgf@xa\pgf@x%
1465 \pgf@ya\pgf@y%
1466 \advance\pgf@x-\pgf@xc%
1467 \advance\pgf@y-\pgf@yc%
1468 \pgfmathveclen@{\pgfmath@tonumber{\pgf@x}}{\pgfmath@tonumber{\pgf@y}}%
1469 \pgfutil@tempdimb\pgfmathresult pt\relax%
1470 \advance\pgfutil@tempdima\c@pgf@counta\pgfutil@tempdimb%
1471 \ifnum\c@pgf@counta>0\relax%
1472 \ifdim\pgfutil@tempdima>#1\relax%
1473 \c@pgf@counta-\c@pgf@counta%
1474 \[email protected]\pgf@yb%
1475 \fi%
1476 \else%
1477 \ifdim\pgfutil@tempdima<#1\relax%
1478 \c@pgf@counta-\c@pgf@counta%
1479 \[email protected]\pgf@yb%
1480 \fi%
1481 \fi%
1482 \ifdim\pgf@yb=0pt\relax% *Should* be OK.
1483 \else%
1484 \repeatpgfmathloop%
1485 \edef\pgf@decorate@inputsegmenttime{\pgfmath@tonumber{\pgf@xb}}%
1486 %
1487 % Now calculate the angle at the new time on the curve.
1488 %
1489 % We can use \pgfpointcurveattime safely here.
1490 %
1491 \pgfpointcurveattime{\pgf@decorate@inputsegmenttime}%
1492 {\pgf@decorate@inputsegment@first}{\pgf@decorate@inputsegment@supporta}%
1493 {\pgf@decorate@inputsegment@supportb}{\pgf@decorate@inputsegment@last}%
1494 \edef\pgf@marshal{%
1495 \noexpand\pgfmathanglebetweenpoints%
1496 {\pgf@x\the\pgf@xb\pgf@y\the\pgf@yb}%
1497 {\pgf@x\the\pgf@xa\pgf@y\the\pgf@ya}%
1498 }%
1499 \pgf@marshal%
1500 \let\pgfdecoratedangle\pgfmathresult%
1501 \fi%
1502 }%
1503
1504 % \pgfpoint@decorate@curveattime
1505 %
1506 % A `quick' version of \pgfpointcurveattime
1507 %
1508 % No parsing and no use of \pgf@process.
1509 % This prevents save stack build up when used inside a loop.
1510 %
1511 \def\pgfpoint@decorate@curveattime#1#2#3#4#5{%
1512 \edef\pgf@time@s{#1}%
1513 \pgf@x-\pgf@time@s pt\relax%
1514 \advance\pgf@x1pt\relax%
1515 \edef\pgf@time@t{\pgf@sys@tonumber{\pgf@x}}%
1516 #5\relax%
1517 \pgf@xc=\pgf@x%
1518 \pgf@yc=\pgf@y%
1519 #4\relax%
1520 \pgf@xb=\pgf@x%
1521 \pgf@yb=\pgf@y%
1522 #3\relax%
1523 \pgf@xa=\pgf@x%
1524 \pgf@ya=\pgf@y%
1525 #2\relax%
1526 % First iteration:
1527 \pgf@x=\pgf@time@t\pgf@x\advance\pgf@x by\pgf@time@s\pgf@xa%
1528 \pgf@y=\pgf@time@t\pgf@y\advance\pgf@y by\pgf@time@s\pgf@ya%
1529 \pgf@xa=\pgf@time@t\pgf@xa\advance\pgf@xa by\pgf@time@s\pgf@xb%
1530 \pgf@ya=\pgf@time@t\pgf@ya\advance\pgf@ya by\pgf@time@s\pgf@yb%
1531 \pgf@xb=\pgf@time@t\pgf@xb\advance\pgf@xb by\pgf@time@s\pgf@xc%
1532 \pgf@yb=\pgf@time@t\pgf@yb\advance\pgf@yb by\pgf@time@s\pgf@yc%
1533 % Second iteration:
1534 \pgf@x=\pgf@time@t\pgf@x\advance\pgf@x by\pgf@time@s\pgf@xa%
1535 \pgf@y=\pgf@time@t\pgf@y\advance\pgf@y by\pgf@time@s\pgf@ya%
1536 \pgf@xa=\pgf@time@t\pgf@xa\advance\pgf@xa by\pgf@time@s\pgf@xb%
1537 \pgf@ya=\pgf@time@t\pgf@ya\advance\pgf@ya by\pgf@time@s\pgf@yb%
1538 % Save x/y
1539 \pgf@xb=\pgf@x%
1540 \pgf@yb=\pgf@y%
1541 % Third iteration:
1542 \pgf@x=\pgf@time@t\pgf@x\advance\pgf@x by\pgf@time@s\pgf@xa%
1543 \pgf@y=\pgf@time@t\pgf@y\advance\pgf@y by\pgf@time@s\pgf@ya%
1544 }%
1545
1546
1547 % Applies the necessary transform for a line sub-path.
1548 %
1549 \def\pgf@decorate@transformtoinputsegment@line{%
1550 \pgftransformshift{%
1551 \pgfpointlineatdistance{\pgfdecoratedinputsegmentcompleteddistance}{\pgf@decorate@inputsegment@first}{\pgf@decorate@inputsegment@last}
1552 }%
1553 \pgftransformrotate{\pgfdecoratedangle}%
1554 }%
1555
1556 % Applies the necessary transform for a curve sub-path.
1557 %
1558 \def\pgf@decorate@transformtoinputsegment@curve{%
1559 \pgfslopedattimetrue%
1560 \pgfallowupsidedownattimetrue%
1561 \pgftransformcurveattime{\pgf@decorate@inputsegmenttime}%
1562 {\pgf@decorate@inputsegment@first}{\pgf@decorate@inputsegment@supporta}%
1563 {\pgf@decorate@inputsegment@supportb}{\pgf@decorate@inputsegment@last}%
1564 }%
1565
1566
1567
1568
1569
1570 % \pgf@decorate@parsesoftpath
1571 %
1572 % Parses an instance of a soft path into intermediate line and curve
1573 % sub-path objects which the decoration automaton can use to traverse
1574 % the decorated path.
1575 %
1576 % The soft path should be well formed and only contain `primative'
1577 % soft path tokens, that is: moveto, lineto, curvetosupporta,
1578 % curvetosupportb, curveto, rectcorner, rectsize, and closepath.
1579 % (i.e., all specialround tokens should have removed using
1580 % \pgfprocessround)
1581 %
1582 % The overall length of the path is also calculated and returned
1583 % in the macro \pgfdecoratedpathlength.
1584 %
1585 % Parameters:
1586 %
1587 % #1 - a macro containing a well formed soft path.
1588 % #2 - a macro to store the intermediate sub-path representations.
1589 %
1590 % Example:
1591 %
1592 % \pgfpathmoveto{\pgfpointorigin}
1593 % \pgfpathlineto{\pgfpoint{0pt}{12pt}}
1594 % \pgfpathlineto{\pgfpoint{12pt}{0pt}}
1595 % \pgfgetpath\softpath
1596 %
1597 % \pgf@decorate@parsesoftpath{\softpath}{\parsedsoftpath}
1598 %
1599 % results in:
1600 %
1601 % \parsedsoftpath ->
1602 % {\pgf@decorate@inputsegmentobject@lineto{12pt}{\pgf@x 0pt\pgf@y 0pt}{\pgf@x 0pt\pgf@y 12pt}}
1603 % {\pgf@decorate@inputsegmentobject@lineto{12pt}{\pgf@x 0pt\pgf@y 12pt}{\pgf@x 12pt\pgf@y 12pt}}
1604 %
1605 % \pgfdecoratedpathlength ->
1606 % 24pt
1607 %
1608
1609 \def\pgf@decorate@parsesoftpath#1#2{%
1610 \def\pgf@decorate@inputsegmentobjectsmacro{#2}%
1611 \let\pgf@decorate@inputsegmentobjects\pgfutil@empty%
1612 \pgfutil@tempdima0pt\relax%
1613 \let\pgfpoint@decorate@lastparsed\pgfpoint@decorate@existingpathlast%
1614 \let\pgfpoint@decorate@lastnonmovetoparsed\pgfpoint@origin%
1615 \let\pgf@decorate@queueinputsegmentobject\pgfutil@empty%
1616 \let\pgfpoint@decorated@firstparsed\pgfutil@empty%
1617 \expandafter\pgf@decorate@@parsesoftpath#1\pgf@stop%
1618 }%
1619
1620 \def\pgf@decorate@@parsesoftpath#1{%
1621 \ifx#1\pgf@stop%
1622 \let\pgf@decorate@queueinputsegmentobject\pgfutil@empty% <- removes final moveto (may not be desirable).
1623 \pgf@decorate@addtoinputsegmentobjects{\pgf@decorate@inputsegmentobject@endofinputsegments}%
1624 \pgf@decorate@addtoinputsegmentobjects{\pgf@decorate@inputsegmentobject@endofinputsegments}%
1625 \expandafter\let\pgf@decorate@inputsegmentobjectsmacro\pgf@decorate@inputsegmentobjects%
1626 \edef\pgf@decorate@totalpathlength{\the\pgfutil@tempdima}%
1627 \let\pgf@next\relax%
1628 \else%
1629 \ifx#1\pgfsyssoftpath@movetotoken%
1630 \let\pgf@next\pgf@decorate@parsemoveto%
1631 \else%
1632 \ifx#1\pgfsyssoftpath@linetotoken%
1633 \let\pgf@next\pgf@decorate@parselineto%
1634 \else%
1635 \ifx#1\pgfsyssoftpath@curvetosupportatoken%
1636 \let\pgf@next\pgf@decorate@parsecurveto%
1637 \else%
1638 \ifx#1\pgfsyssoftpath@closepathtoken%
1639 \let\pgf@next\pgf@decorate@parseclosepath%
1640 \else%
1641 \ifx#1\pgfsyssoftpath@rectcornertoken%
1642 \let\pgf@next\pgf@decorate@parserect%
1643 \else%
1644 \pgferror{Unrecognised soft path token `#1'}%
1645 \fi%
1646 \fi%
1647 \fi%
1648 \fi%
1649 \fi%
1650 \fi%
1651 \pgf@next}%
1652
1653
1654 \def\pgf@decorate@addtoinputsegmentobjects#1{%
1655 %
1656 % If there is an input segment object waiting (i.e. a moveto), insert it here.
1657 %
1658 \ifx\pgf@decorate@queueinputsegmentobject\pgfutil@empty%
1659 \else%
1660 \let\pgf@decorate@temp\pgf@decorate@queueinputsegmentobject%
1661 \let\pgf@decorate@queueinputsegmentobject\pgfutil@empty%
1662 \expandafter\pgf@decorate@addtoinputsegmentobjects\expandafter{\pgf@decorate@temp}%
1663 \fi%
1664 \ifx\pgfpoint@decorated@firstparsed\pgfutil@empty%
1665 #1%
1666 \let\pgfpoint@decorated@firstparsed\pgf@decorate@inputsegment@first%
1667 \fi%
1668 \expandafter\def\expandafter\pgf@decorate@inputsegmentobjects\expandafter%
1669 {\pgf@decorate@inputsegmentobjects{#1}}%
1670 }%
1671
1672 % Convert \pgfsyssoftpath@movetotoken{<X>}{<Y>} into the following
1673 % representation:
1674 %
1675 % \pgf@decorate@inputsegmentobject@moveto{\pgf@x X\pgf@y Y}
1676 %
1677 % The moveto input segment object is not added immediately, so that
1678 % only the last of multiple movetos is inserted.
1679 %
1680 \def\pgf@decorate@parsemoveto#1#2{%
1681 \def\pgf@decorate@queueinputsegmentobject{\pgf@decorate@inputsegmentobject@moveto{\pgf@x#1\pgf@y#2}}%
1682 \def\pgfpoint@decorate@lastparsed{\pgf@x#1\pgf@y#2}%
1683 \pgf@decorate@@parsesoftpath%
1684 }%
1685
1686 % Convert \pgfsyssoftpath@linetotoken{<X>}{<Y>} into the following
1687 % representation:
1688 %
1689 % \pgf@decorate@inputsegmentobject@lineto{<length>}{\pgf@x <Last X> \pgf@y <Last Y}{\pgf@x <X> \pgf@y <Y>}
1690 %
1691 \def\pgf@decorate@parselineto#1#2{%
1692 \pgf@decorate@linelength{\pgfpoint@decorate@lastparsed}{\pgf@x#1\pgf@y#2}%
1693 \advance\pgfutil@tempdima\pgfmathresult pt\relax%
1694 \edef\pgf@decorate@temp{%
1695 \noexpand\pgf@decorate@inputsegmentobject@lineto{\pgfmathresult pt}{\pgfpoint@decorate@lastparsed}{\pgf@x#1\pgf@y#2}%
1696 }%
1697 \edef\pgfpoint@decorate@lastparsed{\pgf@x#1\pgf@y#2}%
1698 \let\pgfpoint@decorate@lastnonmovetoparsed\pgfpoint@decorate@lastparsed%
1699 \expandafter\pgf@decorate@addtoinputsegmentobjects\expandafter{\pgf@decorate@temp}%
1700 \pgf@decorate@@parsesoftpath%
1701 }%
1702
1703 % Convert \pgfsyssoftpath@curvetosupportatoken{<Xa>}{<Ya>}...etc
1704 % into the following representation:
1705 %
1706 % \pgf@decorate@inputsegmentobject@curveto{<length>}{\pgf@x <Last X> \pgf@y <Last Y}
1707 % {\pgf@x <Xa> \pgf@y <Ya>}{\pgf@x <Xb> \pgf@y <Yb>}{\pgf@x <X> \pgf@y <Y>}
1708 %
1709 \def\pgf@decorate@parsecurveto#1#2\pgfsyssoftpath@curvetosupportbtoken#3#4\pgfsyssoftpath@curvetotoken#5#6{%
1710 \pgf@decorate@curvelength{\pgfpoint@decorate@lastparsed}{\pgf@x#1\pgf@y#2}{\pgf@x#3\pgf@y#4}{\pgf@x#5\pgf@y#6}%
1711 \advance\pgfutil@tempdima\pgfmathresult pt\relax%
1712 \edef\pgf@decorate@temp{%
1713 \noexpand\pgf@decorate@inputsegmentobject@curveto{\pgfmathresult pt}{\pgfpoint@decorate@lastparsed}%
1714 {\pgf@x#1\pgf@y#2}{\pgf@x#3\pgf@y#4}{\pgf@x#5\pgf@y#6}%
1715 }%
1716 \expandafter\pgf@decorate@addtoinputsegmentobjects\expandafter{\pgf@decorate@temp}%
1717 \edef\pgfpoint@decorate@lastparsed{\pgf@x#5\pgf@y#6}%
1718 \let\pgfpoint@decorate@lastnonmovetoparsed\pgfpoint@decorate@lastparsed%
1719 \pgf@decorate@@parsesoftpath%
1720 }%
1721
1722
1723 \def\pgf@decorate@parseclosepath#1#2{%
1724 \pgf@decorate@linelength{\pgfpoint@decorate@lastparsed}{\pgf@x#1\pgf@y#2}%
1725 \advance\pgfutil@tempdima\pgfmathresult pt\relax%
1726 \edef\pgf@decorate@temp{%
1727 \noexpand\pgf@decorate@inputsegmentobject@closepath{\pgfmathresult pt}{\pgfpoint@decorate@lastparsed}{\pgf@x#1\pgf@y#2}%
1728 }%
1729 \expandafter\pgf@decorate@addtoinputsegmentobjects\expandafter{\pgf@decorate@temp}%
1730 \edef\pgfpoint@decorate@lastparsed{\pgf@x#1\pgf@y#2}%
1731 \let\pgfpoint@decorate@lastnonmovetoparsed\pgfpoint@decorate@lastparsed%
1732 \pgf@decorate@@parsesoftpath%
1733 }%
1734
1735 % Convert \pgfsyssoftpath@rectcornertoken{<X>}{<Y>}\pgfsyssoftpath@rectsizetoken{<Xa>}{<Ya>}
1736 % into either (clockwise)
1737 %
1738 % \pgf@decorate@inputsegmentobject@moveto{<X>}{<Y>}
1739 % \pgf@decorate@inputsegmentobject@lineto{<length 1>}{\pgf@x <X> \pgf@y <Y>}{\pgf@x <X> \pgf@y <Ya+Y>}
1740 % \pgf@decorate@inputsegmentobject@lineto{<length 2>}{\pgf@x <X> \pgf@y <Ya+Y>}{\pgf@x <Xa+X> \pgf@y <Ya+Y>}
1741 % \pgf@decorate@inputsegmentobject@lineto{<length 1>}{\pgf@x <Xa+X> \pgf@y <Ya+X>}{\pgf@x <Xa+X> \pgf@y <Y>}
1742 % \pgf@decorate@inputsegmentobject@lineto{<length 2>}{\pgf@x <Xa+X> \pgf@y <Y>}{\pgf@x <X> \pgf@y <Y>}
1743 % \pgf@decorate@inputsegmentobject@moveto{<Xa>}{<Ya>}
1744 %
1745 % ...or (anti-clockwise)
1746 %
1747 % \pgf@decorate@inputsegmentobject@moveto{<X>}{<Y>}
1748 % \pgf@decorate@inputsegmentobject@lineto{<length 2>}{\pgf@x <X> \pgf@y <Y>}{\pgf@x <Xa+X> \pgf@y <Y>}
1749 % \pgf@decorate@inputsegmentobject@lineto{<length 1>}{\pgf@x <Xa+X> \pgf@y <Y>}{\pgf@x <Xa+X> \pgf@y <Ya+Y>}
1750 % \pgf@decorate@inputsegmentobject@lineto{<length 2>}{\pgf@x <Xa+X> \pgf@y <Ya+Y>}{\pgf@x <X> \pgf@y <Ya+Y>}
1751 % \pgf@decorate@inputsegmentobject@lineto{<length 1>}{\pgf@x <X> \pgf@y <Ya+Y>}{\pgf@x <X> \pgf@y <Y>}
1752 % \pgf@decorate@inputsegmentobject@moveto{<Xa>}{<Ya>}
1753 %
1754 \newif\ifpgfdecoraterectangleclockwise
1755 \def\pgf@decorate@parserect#1#2\pgfsyssoftpath@rectsizetoken#3#4{%
1756 %
1757 % Subvert \pgf@decorate@parsesoftpath so parsing macros will
1758 % return here instead of continuing to parse the soft path.
1759 %
1760 \let\pgf@decorate@orig@@parsesoftpath\pgf@decorate@@parsesoftpath%
1761 \let\pgf@decorate@@parsesoftpath\relax%
1762 \pgf@decorate@parsemoveto{#1}{#2}%
1763 \pgf@xa#1\relax%
1764 \pgf@ya#2\relax%
1765 \ifpgfdecoraterectangleclockwise%
1766 \advance\pgf@ya#4%
1767 \pgf@yb\pgf@ya%
1768 \edef\pgf@temp{{\the\pgf@xa}{\the\pgf@ya}}%
1769 \expandafter\pgf@decorate@parselineto\pgf@temp%
1770 \advance\pgf@xa#3%
1771 \pgf@xb\pgf@xa%
1772 \edef\pgf@temp{{\the\pgf@xa}{\the\pgf@ya}}%
1773 \expandafter\pgf@decorate@parselineto\pgf@temp%
1774 \advance\pgf@ya-#4%
1775 \edef\pgf@temp{{\the\pgf@xa}{\the\pgf@ya}}%
1776 \expandafter\pgf@decorate@parselineto\pgf@temp%
1777 \advance\pgf@xa-#3%
1778 \edef\pgf@temp{{\the\pgf@xa}{\the\pgf@ya}}%
1779 \expandafter\pgf@decorate@parseclosepath\pgf@temp%
1780 \else%
1781 \advance\pgf@xa#3%
1782 \edef\pgf@temp{{\the\pgf@xa}{\the\pgf@ya}}%
1783 \pgf@xb\pgf@xa%
1784 \expandafter\pgf@decorate@parselineto\pgf@temp%
1785 \advance\pgf@ya#4%
1786 \pgf@yb\pgf@ya%
1787 \edef\pgf@temp{{\the\pgf@xa}{\the\pgf@ya}}%
1788 \expandafter\pgf@decorate@parselineto\pgf@temp%
1789 \advance\pgf@xa-#3%
1790 \edef\pgf@temp{{\the\pgf@xa}{\the\pgf@ya}}%
1791 \expandafter\pgf@decorate@parselineto\pgf@temp%
1792 \advance\pgf@ya-#4%
1793 \edef\pgf@temp{{\the\pgf@xa}{\the\pgf@ya}}%
1794 \expandafter\pgf@decorate@parseclosepath\pgf@temp%
1795 \fi%
1796 %
1797 % Restore the parsing.
1798 %
1799 \let\pgf@decorate@@parsesoftpath\pgf@decorate@orig@@parsesoftpath%
1800 \edef\pgf@marshal{\noexpand\pgf@decorate@parsemoveto{\the\pgf@xb}{\the\pgf@yb}}%
1801 \pgf@marshal%
1802 }%
1803
1804
1805
1806
1807 % \pgf@decorate@linelength
1808 %
1809 % Define \pgfmathresult as the distance between #1 and #2 (without units).
1810 %
1811 \def\pgf@decorate@linelength#1#2{%
1812 \pgf@process{\pgfpointdiff{#1}{#2}}%
1813 \pgfmathveclen@{\pgfmath@tonumber{\pgf@x}}{\pgfmath@tonumber{\pgf@y}}%
1814 }%
1815
1816 % \pgf@decorate@curvelength
1817 %
1818 % Define \pgfmathresult as the length (without units) of the cubic
1819 % bezier described by #1,#2,#3 and #4.
1820 %
1821 % To approximate the length of the curve P (sort of) use:
1822 %
1823 % curveLength(P,q)
1824 % Q = subdivideLeft(P);
1825 % R = subdivideRight(P);
1826 % return curveLength'(Q,q) + curveLength'(R,q);
1827 %
1828 % curveLength'(P,q)
1829 % <P1,P2,P3,P4> <- P;
1830 % P' = P4 - P1;
1831 % x = P'.x();
1832 % y = P'.y();
1833 % if (x < q) && (y < q)
1834 % return |P'|;
1835 % else%
1836 % Q = subdivideLeft(P);
1837 % R = subdivideRight(P);
1838 % return curveLength'(Q,q) + curveLength'(R,q);
1839 %
1840 % Where q is some small value (`tolerance').
1841 %
1842 \newif\ifpgf@decorate@subdivide
1843 \def\pgf@decorate@curvelength#1#2#3#4{%
1844 %
1845 % Always begin with a subdivision in case #1 = #4.
1846 %
1847 \begingroup%
1848 \pgf@decorate@recursive@subdividecurve@left{#1}{#2}{#3}{#4}%
1849 \pgfutil@tempdimb\pgfmathresult pt\relax%
1850 \pgf@decorate@recursive@subdividecurve@right{#1}{#2}{#3}{#4}%
1851 \advance\pgfutil@tempdimb\pgfmathresult pt\relax%
1852 \pgfmath@returnone\pgfutil@tempdimb%
1853 \endgroup%
1854 }%
1855
1856 \def\pgf@decorate@@curvelength#1#2#3#4{%
1857 \begingroup%
1858 \pgf@decorate@curvecordlength{#1}{#2}{#3}{#4}%
1859 \ifpgf@decorate@subdivide%
1860 \pgf@decorate@recursive@subdividecurve@left{#1}{#2}{#3}{#4}%
1861 \pgfutil@tempdimb\pgfmathresult pt\relax%
1862 \pgf@decorate@recursive@subdividecurve@right{#1}{#2}{#3}{#4}%
1863 \advance\pgfutil@tempdimb\pgfmathresult pt\relax%
1864 \expandafter\pgfmath@returnone\expandafter\pgfutil@tempdimb%
1865 \else%
1866 \expandafter\pgfmath@returnone\expandafter\pgfmathresult\expandafter p\expandafter t\expandafter%
1867 \fi%
1868 \endgroup%
1869 }%
1870
1871 \def\pgf@decorate@curvelength@tolerance{1pt}%
1872
1873 \def\pgf@decorate@curvecordlength#1#2#3#4{%
1874 %
1875 % Calculate the curve cord vector.
1876 %
1877 #4\relax%
1878 \pgf@xa\pgf@x\pgf@ya\pgf@y%
1879 #1\relax%
1880 \advance\pgf@xa-\pgf@x%
1881 \advance\pgf@ya-\pgf@y%
1882 \ifdim\pgf@xa<0pt\relax\pgf@xa-\pgf@xa\fi%
1883 \ifdim\pgf@ya<0pt\relax\pgf@ya-\pgf@ya\fi%
1884 %
1885 % Always subdivide, unless...
1886 %
1887 \pgf@decorate@subdividetrue%
1888 %
1889 % The cord vector is small.
1890 %
1891 \ifdim\pgf@xa<\pgf@decorate@curvelength@tolerance\relax%
1892 \ifdim\pgf@ya<\pgf@decorate@curvelength@tolerance\relax%
1893 \pgfmathveclen@{\pgfmath@tonumber{\pgf@xa}}{\pgfmath@tonumber{\pgf@ya}}%
1894 \pgf@decorate@subdividefalse%
1895 \fi%
1896 \fi%
1897 }%
1898
1899 \def\pgf@decorate@recursive@subdividecurve@left#1#2#3#4{%
1900 {%
1901 %
1902 % The left curve (from t=0 to t=.5)
1903 %
1904 #1\relax%
1905 \pgfutil@tempdima\pgf@x%
1906 \pgfutil@tempdimb\pgf@y%
1907 \[email protected]\pgf@x\[email protected]\pgf@y%
1908 \[email protected]\pgf@x\[email protected]\pgf@y%
1909 \[email protected]\pgf@x\[email protected]\pgf@y%
1910 #2\relax%
1911 \advance\[email protected]\pgf@x\advance\[email protected]\pgf@y%
1912 \advance\[email protected]\pgf@x\advance\[email protected]\pgf@y%
1913 \advance\[email protected]\pgf@x\advance\[email protected]\pgf@y%
1914 #3\relax%
1915 \advance\[email protected]\pgf@x\advance\[email protected]\pgf@y%
1916 \advance\[email protected]\pgf@x\advance\[email protected]\pgf@y%
1917 #4\relax%
1918 \advance\[email protected]\pgf@x\advance\[email protected]\pgf@y%
1919 \xdef\pgf@marshal{%
1920 \noexpand\pgf@decorate@@curvelength%
1921 {\pgf@x\the\pgfutil@tempdima\pgf@y\the\pgfutil@tempdimb}%
1922 {\pgf@x\the\pgf@xa\pgf@y\the\pgf@ya}{\pgf@x\the\pgf@xb\pgf@y\the\pgf@yb}
1923 {\pgf@x\the\pgf@xc\pgf@y\the\pgf@yc}%
1924 }%
1925 }%
1926 \pgf@marshal%
1927 }%
1928
1929 \def\pgf@decorate@recursive@subdividecurve@right#1#2#3#4{%
1930 {%
1931 %
1932 % The right curve (from t=0.5 to t=1)
1933 %
1934 #1\relax%
1935 \[email protected]\pgf@x\[email protected]\pgf@y%
1936 #2\relax%
1937 \advance\[email protected]\pgf@x\advance\[email protected]\pgf@y%
1938 \[email protected]\pgf@x\[email protected]\pgf@y%
1939 #3\relax%
1940 \advance\[email protected]\pgf@x\advance\[email protected]\pgf@y%
1941 \advance\[email protected]\pgf@x\advance\[email protected]\pgf@y%
1942 \[email protected]\pgf@x\[email protected]\pgf@y%
1943 #4\relax%
1944 \advance\[email protected]\pgf@x\advance\[email protected]\pgf@y%
1945 \advance\[email protected]\pgf@x\advance\[email protected]\pgf@y%
1946 \advance\[email protected]\pgf@x\advance\[email protected]\pgf@y%
1947 \pgf@xc\pgf@x\pgf@yc\pgf@y%
1948 \xdef\pgf@marshal{%
1949 \noexpand\pgf@decorate@@curvelength%
1950 {\pgf@x\the\pgfutil@tempdima\pgf@y\the\pgfutil@tempdimb}%
1951 {\pgf@x\the\pgf@xa\pgf@y\the\pgf@ya}{\pgf@x\the\pgf@xb\pgf@y\the\pgf@yb}
1952 {\pgf@x\the\pgf@xc\pgf@y\the\pgf@yc}%
1953 }%
1954 }%
1955 \pgf@marshal%
1956 }%
1957
1958
1959 % Macro to reverse a set of input segment objects.
1960 %
1961 % #1 - a macro holding the input segment objects.
1962 % #2 - a macro holding the reversed input segment objects.
1963 %
1964 \def\pgf@decorate@inputsegmentobjects@reverse#1#2{%
1965 \def\pgf@decorate@path@storein{#2}%
1966 \def\pgf@decorate@inputsegments@@temp{}%
1967 \expandafter\pgf@decorate@inputsegments@@reverse@pass@first#1\pgf@stop}%
1968
1969 \def\pgf@decorate@inputsegments@@reverse@pass@first#1#2\pgf@stop{%
1970 \def\pgf@decorate@temp{#1}%
1971 \expandafter\expandafter\expandafter\def\expandafter\expandafter\expandafter%
1972 \pgf@decorate@inputsegments@@temp\expandafter\expandafter\expandafter%
1973 {\expandafter\pgf@decorate@temp\pgf@decorate@inputsegments@@temp}%
1974 \def\pgf@decorate@test{#2}
1975 \ifx\pgf@decorate@test\pgfutil@empty%
1976 \def\pgf@decorate@next{%
1977 \expandafter\pgf@decorate@inputsegmentobjects@reverse@pass@second\pgf@decorate@inputsegments@@temp\pgf@stop%
1978 }%
1979 \else%
1980 \def\pgf@decorate@next{\pgf@decorate@inputsegments@@reverse@pass@first#2\pgf@stop}%
1981 \fi%
1982 \pgf@decorate@next%
1983 }%
1984 \def\pgf@decorate@inputsegmentobjects@reverse@pass@second#1#2#3\pgf@stop{%
1985 \def\pgf@decorate@inputsegments@temp{#3}%
1986 \def\pgf@decorate@inputsegments@@temp{}%
1987 \let\pgf@decorate@current@inputsegmentobject=\pgfutil@empty
1988 \let\pgf@decorate@last@object=\pgfutil@empty
1989 \pgf@decorate@inputsegmentobjects@reverse@moveto@waitingtrue%
1990 \pgf@decorate@inputsegmentobjects@reverse@closepath@waitingfalse%
1991 \expandafter\pgf@decorate@path@@reverse@pass@second\pgf@decorate@inputsegments@temp\pgf@stop}%
1992
1993
1994 \def\pgf@decorate@path@@reverse@pass@second#1{%
1995 \ifx#1\pgf@stop%
1996 \expandafter\def\expandafter\pgf@decorate@inputsegments@@temp\expandafter{%
1997 \pgf@decorate@inputsegments@@temp%
1998 {\pgf@decorate@inputsegmentobject@endofinputsegments}%
1999 {\pgf@decorate@inputsegmentobject@endofinputsegments}
2000 }%
2001 \expandafter\let\pgf@decorate@path@storein=\pgf@decorate@inputsegments@@temp%
2002 \let\pgf@decorate@next=\relax%
2003 \else%
2004 \ifx#1\pgf@decorate@inputsegmentobject@moveto%
2005 \let\pgf@decorate@next=\pgf@decorate@inputsegmentobjects@reverse@moveto%
2006 \else%
2007 \ifx#1\pgf@decorate@inputsegmentobject@lineto%
2008 \let\pgf@decorate@next=\pgf@decorate@inputsegmentobjects@reverse@lineto%
2009 \else%
2010 \ifx#1\pgf@decorate@inputsegmentobject@curveto%
2011 \let\pgf@decorate@next=\pgf@decorate@inputsegmentobjects@reverse@curveto%
2012 \else%
2013 \ifx#1\pgf@decorate@inputsegmentobject@closepath%
2014 \let\pgf@decorate@next=\pgf@decorate@inputsegmentobjects@reverse@closepath%
2015 \else%
2016 \fi%
2017 \fi%
2018 \fi%
2019 \fi%
2020 \fi%
2021 \pgf@decorate@next%
2022 }%
2023
2024 \newif\ifpgf@decorate@inputsegmentobjects@reverse@moveto@waiting
2025
2026 \def\pgf@decorate@inputsegmentobjects@reverse@moveto#1{%
2027 \ifpgf@decorate@inputsegmentobjects@reverse@closepath@waiting%
2028 \edef\pgf@decorate@current@inputsegmentobject{%
2029 {\noexpand\pgf@decorate@inputsegmentobject@closepath%
2030 {\pgf@decorate@reverse@closepath@length}%
2031 {\pgf@decorate@last}%
2032 {#1}%
2033 }%
2034 }%
2035 \pgf@decorate@inputsegmentobjects@reverse@closepath@waitingfalse%
2036 \else%
2037 \let\pgf@decorate@current@inputsegmentobject=\pgfutil@empty%
2038 \fi%
2039 \pgf@decorate@inputsegmentobjects@reverse@moveto@waitingtrue%
2040 \pgf@decorate@path@@@reverse@pass@second%
2041 }%
2042
2043 \newif\ifpgf@decorate@inputsegmentobjects@reverse@closepath@waiting
2044
2045 \def\pgf@decorate@inputsegmentobjects@reverse@closepath#1#2#3{%
2046 \pgf@decorate@inputsegmentobjects@reverse@closepath@waitingtrue%
2047 \def\pgf@decorate@reverse@closepath@length{#1}%
2048 \def\pgf@decorate@current@inputsegmentobject{}%
2049 \pgf@decorate@inputsegmentobjects@reverse@lineto{#1}{#2}{#3}%
2050 }%
2051
2052 \def\pgf@decorate@inputsegmentobjects@reverse@lineto#1#2#3#4{%
2053 \ifpgf@decorate@inputsegmentobjects@reverse@moveto@waiting%
2054 \def\pgf@decorate@current@inputsegmentobject{{\pgf@decorate@inputsegmentobject@moveto{#3}}}%
2055 \pgf@decorate@inputsegmentobjects@reverse@moveto@waitingfalse%
2056 \else%
2057 \let\pgf@decorate@current@inputsegmentobject=\pgfutil@empty%
2058 \fi%
2059 \def\pgf@decorate@append@inputsegmentobject{{\pgf@decorate@inputsegmentobject@lineto{#1}{#3}{#2}}}%
2060 \ifx#4\pgf@decorate@inputsegmentobject@moveto%
2061 \ifpgf@decorate@inputsegmentobjects@reverse@closepath@waiting%
2062 \def\pgf@decorate@append@inputsegmentobject{{\pgf@decorate@inputsegmentobject@closepath{#1}{#3}{#2}}}%
2063 \pgf@decorate@inputsegmentobjects@reverse@closepath@waitingfalse%
2064 \else%
2065 \def\pgf@decorate@append@inputsegmentobject{{\pgf@decorate@inputsegmentobject@lineto{#1}{#3}{#2}}}%
2066 \fi%
2067 \fi%
2068 \expandafter\expandafter\expandafter\def\expandafter\expandafter\expandafter%
2069 \pgf@decorate@current@inputsegmentobject\expandafter\expandafter\expandafter%
2070 {\expandafter\pgf@decorate@current@inputsegmentobject\pgf@decorate@append@inputsegmentobject}
2071 \def\pgf@decorate@last{#2}%
2072 \pgf@decorate@path@@@reverse@pass@second#4%
2073 }%
2074
2075 \def\pgf@decorate@inputsegmentobjects@reverse@curveto#1#2#3#4#5{%
2076 \ifpgf@decorate@inputsegmentobjects@reverse@moveto@waiting%
2077 \def\pgf@decorate@current@inputsegmentobject{%
2078 {\pgf@decorate@inputsegmentobject@moveto{#5}}%
2079 {\pgf@decorate@inputsegmentobject@curveto{#1}{#5}{#4}{#3}{#2}}%
2080 }%
2081 \pgf@decorate@inputsegmentobjects@reverse@moveto@waitingfalse%
2082 \else%
2083 \def\pgf@decorate@current@inputsegmentobject{{\pgf@decorate@inputsegmentobject@curveto{#1}{#5}{#4}{#3}{#2}}}%
2084 \fi%
2085 \def\pgf@decorate@last{#2}%
2086 \pgf@decorate@path@@@reverse@pass@second%
2087 }%
2088
2089 \def\pgf@decorate@path@@@reverse@pass@second{%
2090 \ifx\pgf@decorate@current@inputsegmentobject\pgfutil@empty%
2091 \else%
2092 \expandafter\expandafter\expandafter\def\expandafter\expandafter\expandafter%
2093 \pgf@decorate@inputsegments@@temp\expandafter\expandafter\expandafter%
2094 {\expandafter\pgf@decorate@inputsegments@@temp\pgf@decorate@current@inputsegmentobject}%
2095 \fi%
2096 \pgf@decorate@path@@reverse@pass@second%
2097 }%
2098
2099
2100
2101
2102
2103 \let\startpgfdecoration=\pgfdecoration
2104 \let\stoppgfdecoration=\endpgfdecoration
2105
2106 \let\startpgfmetadecoration=\pgfmetadecoration
2107 \let\stoppgfmetadecoration=\endpgfmetadecoration
2108
2109
2110
2111 %
2112 % Predefined decorations
2113 %
2114
2115
2116 % Simple decorations.
2117
2118 \pgfdeclaredecoration{lineto}{initial}{%
2119 \state{initial}[switch if input segment less than=\pgfdecoratedremainingdistance to input segment,
2120 width=\pgfdecoratedremainingdistance]
2121 {
2122 }%
2123 \state{input segment}[width=\pgfdecoratedinputsegmentlength,next state=initial]
2124 {
2125 \pgfpathlineto{\pgfpointdecoratedinputsegmentlast}
2126 }%
2127
2128 \state{final}{\pgfpathlineto{\pgfpointdecoratedpathlast}}%
2129 }%
2130
2131 \pgfdeclaredecoration{moveto}{initial}{%
2132 \state{initial}[width=\pgfdecoratedremainingdistance]{}%
2133 \state{final}{\pgfpathmoveto{\pgfpointdecoratedpathlast}}%
2134 }%
2135
2136 % This decorations curves to the end along the line.
2137
2138 \pgfdeclaredecoration{curveto}{initial}{%
2139 \state{initial}[width=\pgfdecoratedinputsegmentlength/100]
2140 {
2141 \pgfpathlineto{\pgfpointorigin}
2142 }%
2143 \state{final}{\pgfpathlineto{\pgfpointdecoratedpathlast}}%
2144 }%
2145
2146
2147
2148
2149 % Compatibility with old "snakes":
2150
2151 \let\pgfsnakeremainingdistance=\pgfdecoratedremainingdistance
2152 \let\pgfsnakecompleteddistance=\pgfdecoratedcompleteddistance
2153 \def\pgfsnakeangle{\pgfdecoratedangle}%
2154 \let\pgfdeclaresnake=\pgfdeclaredecoration
2155 \let\pgfsetsnakesegmenttransformation=\pgfsetdecorationsegmenttransformation
2156 \def\pgfpathsnakesto#1#2{%
2157 \edef\pgf@temp{#1}%
2158 \expandafter\pgfdecoration\expandafter{\pgf@temp}%
2159 \pgfpathlineto{#2}%
2160 \endpgfdecoration%
2161 }%
2162 \def\pgfpathsnaketo#1#2{\pgfpathsnakesto{{#1}{\pgfsnakeremainingdistance}}{#2}}%
2163 \def\pgfpathsnakealongvector#1#2#3{%
2164 \pgf@process{#3}%
2165 \pgf@xa=\pgf@x%
2166 \pgf@ya=\pgf@y%
2167 \pgfmathparse{#2}%
2168 \pgf@xa=\pgfmathresult\pgf@xa%
2169 \pgf@ya=\pgfmathresult\pgf@ya%
2170 \advance\pgf@xa by\pgf@path@lastx%
2171 \advance\pgf@ya by\pgf@path@lasty%
2172 \edef\pgf@snake@lib@temp{\noexpand\pgfqpoint{\the\pgf@xa}{\the\pgf@ya}}%
2173 \pgfpathsnaketo{#1}{\pgf@snake@lib@temp}%
2174 }%
2175
2176 \let\pgfsnakesegmentamplitude=\pgfdecorationsegmentamplitude
2177 \let\pgfsnakesegmentlength=\pgfdecorationsegmentlength
2178 \def\pgfsnakesegmentangle{\pgfdecorationsegmentangle}%
2179 \def\pgfsnakesegmentobjectlength{\pgfkeysvalueof{/pgf/decoration/shape start width}}%
2180 \def\pgfsnakesegmentaspect{\pgfdecorationsegmentaspect}%
2181
2182 \pgfset{%
2183 /pgf/segment amplitude/.style={/pgf/decoration={amplitude={#1},shape height={2*(#1)}}},
2184 /pgf/segment length/.style={/pgf/decoration={segment length={#1}}},
2185 /pgf/segment angle/.style={/pgf/decoration={angle={#1}}},
2186 /pgf/segment aspect/.style={/pgf/decoration={aspect={#1}}},
2187 /pgf/segment object length/.style={/pgf/decoration={shape width={#1},radius={#1}}}}%
2188
2189
2190
2191 \endinput