Debian Codegraph @

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

raw
1 % Copyright 2019 by 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 \ProvidesFileRCS{pgfmodulebending.code.tex}
11
12
13 %
14 % This file defines commands for drawing bending arrows and lines.
15 %
16
17 \usepgfmodule{nonlineartransformations}%
18 \usepgflibrary{curvilinear}%
19
20
21 % Configuration options for arrow tips:
22
23 \pgfkeys{
24 /pgf/arrow keys/flex/.code=\pgfarrowsaddtooptions{\pgf@arrows@the@rigidity#1pt\let\pgf@arrow@flex@mode\pgf@arrow@mode@is@flex},
25 /pgf/arrow keys/flex/.default=1,
26 /pgf/arrow keys/flex'/.code=\pgfarrowsaddtooptions{\pgf@arrows@the@rigidity#1pt\let\pgf@arrow@flex@mode\pgf@arrow@mode@is@flex@prime},
27 /pgf/arrow keys/flex'/.default=1,
28 /pgf/arrow
29 keys/bend/.code=\pgfarrowsaddtooptions{\let\pgf@arrow@flex@mode\pgf@arrow@mode@is@bend},
30 }%
31
32
33 \def\pgf@arrow@mode@is@flex{1}%
34 \def\pgf@arrow@mode@is@flex@prime{2}%
35 \def\pgf@arrow@mode@is@bend{3}%
36
37 \newdimen\pgf@arrows@the@rigidity
38
39 %
40 %
41 % Handle the end of a curve
42 %
43 %
44
45 % First, the preparation. This is, essentially, setting up the
46 % nonlinear transformation
47
48 \def\pgf@prep@curveend{
49 \pgftransformreset%
50 \pgfsetcurvilinearbeziercurve{\pgfpointlastonpath}{\pgfpointsecondlastonpath}{\pgfpointthirdlastonpath}{\pgfpointfourthlastonpath}
51 }%
52
53 % Second, the shortening.
54
55 \def\pgf@do@shorten@curvedend{%
56 \expandafter\expandafter\expandafter\pgf@do@shorten@curvedend@unpack\expandafter\pgfpointfourthlastonpath\pgfpointthirdlastonpath%
57 }%
58 \def\pgf@do@shorten@curvedend@unpack\pgfqpoint#1#2\pgfqpoint#3#4{%
59 \pgf@process{\pgfcurvilineardistancetotime{\pgf@path@shortening@distance}}%
60 % Compute new curve:
61 \pgfpointcurveattime{\pgf@x}{\pgfpointlastonpath}{\pgfpointsecondlastonpath}{\pgfpointthirdlastonpath}{\pgfpointfourthlastonpath}%
62 % \pgfx/y and \pgf xa/xb already correct. Need to setup remaining vector...
63 \pgf@xb#3%
64 \pgf@yb#4%
65 \pgf@xb\pgf@time@t\pgf@xb%
66 \pgf@yb\pgf@time@t\pgf@yb%
67 \advance\pgf@xb by\pgf@time@s\pgf@xc%
68 \advance\pgf@yb by\pgf@time@s\pgf@yc%
69 \edef\pgfprocessresultsubpathsuffix{%
70 \expandafter\noexpand\pgfsubpathfourthlasttoken{#1}{#2}%
71 \noexpand\pgfsyssoftpath@curvetosupportatoken{\the\pgf@xb}{\the\pgf@yb}%
72 \noexpand\pgfsyssoftpath@curvetosupportbtoken{\the\pgf@xa}{\the\pgf@ya}%
73 \noexpand\pgfsyssoftpath@curvetotoken{\the\pgf@x}{\the\pgf@y}}%
74 \expandafter\expandafter\expandafter\def%
75 \expandafter\expandafter\expandafter\pgfprocessresultpathsuffix%
76 \expandafter\expandafter\expandafter{\expandafter\pgfprocessresultsubpathprefix\pgfprocessresultsubpathsuffix}%
77 }%
78
79 % Third, the drawing
80
81 \def\pgf@do@draw@curvedend{%
82 \pgf@do@draw@curved\pgf@end@tip@sequence%
83 }%
84
85 \def\pgf@do@draw@curved#1{%
86 {%
87 \pgftransformreset%
88 \pgf@xb\pgf@arrow@tip@total@length% xb will keep track of the total length
89 \let\pgf@arrow@handle\pgf@draw@curved%
90 \let\pgf@arrow@handle@dot\relax%
91 #1%
92 }%
93 }%
94
95 \def\pgf@draw@curved#1#2{%
96 % Prepare:
97 {%
98 \pgfarrows@getid{#1}{#2}%
99 % Do shift:
100 \expandafter\expandafter\expandafter\pgf@arrow@drawer@rigid@shift\csname pgf@ar@ends@\pgf@arrow@id\endcsname%
101 \expandafter\let\expandafter\pgf@arrow@bending@mode\csname pgf@ar@bending@mode@#1\endcsname%
102 \ifx\pgf@arrow@bending@mode\pgfutil@empty\let\pgf@arrow@flex@mode\pgf@arrow@mode@is@flex\fi%
103 % do swap:
104 {%
105 \csname pgf@ar@saves@\pgf@arrow@id\endcsname%
106 \ifcase\pgf@arrow@flex@mode\relax%
107 \expandafter\expandafter\expandafter\pgf@arrow@drawer@rigid\csname pgf@ar@visual@\pgf@arrow@id\endcsname% like flex
108 \or%
109 \expandafter\expandafter\expandafter\pgf@arrow@drawer@rigid\csname pgf@ar@visual@\pgf@arrow@id\endcsname%
110 \or%
111 \expandafter\expandafter\expandafter\pgf@arrow@drawer@rigid\csname pgf@ar@ends@\pgf@arrow@id\endcsname%
112 \or%
113 \pgf@arrow@drawer@bend%
114 \fi%
115 % hull points inside the above
116 }%
117 \expandafter}%
118 % Transform to next tip:
119 \expandafter\pgf@xb\the\pgf@xb%
120 }%
121 \def\pgf@falsetext{false}%
122
123 \def\pgf@arrow@drawer@rigid@shift#1#2#3{% tip end, back end, line end, sep
124 % Let xa be the actual back end of the current arrow plus the back end:
125 \advance\pgf@xb by#2%
126 \pgf@xa\pgf@xb%
127 % Update the xb:
128 \pgf@x#1%
129 \advance\pgf@x by\pgfarrowsep%
130 \advance\pgf@xb by-\pgf@x%
131 }%
132
133
134 \def\pgf@arrow@drawer@bend{%
135 \pgftransformnonlinear{\pgf@arrow@bending@mode{\pgf@x}{\pgf@y}}
136 \pgftransformscale{-1}%
137 \pgftransformxshift{-\pgf@xa}%
138 % Do slant:
139 \ifdim\pgfarrows@slant pt=0pt%
140 \else%
141 \pgftransformxslant{\pgfarrows@slant}%
142 \fi%
143 \ifpgfarrowswap%
144 \pgftransformyscale{-1}%
145 \fi%
146 {%
147 \pgf@relevantforpicturesizefalse%
148 \pgfscope%
149 \pgf@arrows@color@setup%
150 \csname pgf@ar@inst@code@\pgf@arrow@id\endcsname%
151 \endpgfscope%
152 }%
153 \pgf@arrows@bending@hull%
154 }%
155
156 \def\pgf@arrow@drawer@rigid#1#2#3{% (rigid) start, (rigid) end, dummy
157 % Compute the rigid positions:
158 \pgf@x#1% start
159 \pgf@y#2% flexibility*(end-start) + start
160 \advance\pgf@y by-\pgf@x%
161 \pgf@y\pgf@sys@tonumber\pgf@arrows@the@rigidity\pgf@y%
162 \advance\pgf@y by\pgf@x%
163 % Are they equal?
164 \ifdim\pgf@x=\pgf@y%
165 % Yes, do tangent:
166 \pgf@bending@do@tangent%
167 \else%
168 \pgf@bending@do@flex%
169 \fi%
170 \pgf@xc#1%
171 \pgf@xc-\pgf@xc%
172 \pgftransformxshift{+\pgf@xc}%
173 % Do slant:
174 \ifdim\pgfarrows@slant pt=0pt%
175 \else%
176 \pgftransformxslant{\pgfarrows@slant}%
177 \fi%
178 % do swap:
179 \ifpgfarrowswap%
180 \pgftransformyscale{-1}%
181 \fi%
182 \pgfscope%
183 \pgf@arrows@color@setup%
184 \pgflowlevelsynccm\csname pgf@ar@cache@\pgf@arrow@id\endcsname%
185 \endpgfscope%
186 \pgf@arrows@rigid@hull%
187 }%
188
189 \def\pgf@bending@do@tangent{%
190 \pgf@xb\pgf@xa%
191 \advance\pgf@xb by-\pgf@x%
192 \pgfcurvilineardistancetotime{\pgf@xb}%
193 \pgf@xb\pgf@x%
194 % Compute points:
195 \ifdim\pgf@xb=0pt%
196 \pgf@bending@possible@degenerate%
197 \else%
198 \pgf@bending@do@tangent@normal%
199 \fi%
200 \pgf@ya-\pgf@y%
201 \pgfsettransformentries%
202 {\pgf@sys@tonumber\pgf@x}{\pgf@sys@tonumber\pgf@y}%
203 {\pgf@sys@tonumber\pgf@ya}{\pgf@sys@tonumber\pgf@x}{\pgf@xc}{\pgf@yc}%
204 }%
205
206 \def\pgf@bending@do@tangent@normal{%
207 \pgfpointcurveattime{\pgf@xb}{\pgf@curvilinear@line@a}{\pgf@curvilinear@line@b}{\pgf@curvilinear@line@c}{\pgf@curvilinear@line@d}%
208 \pgf@xc\pgf@x% save
209 \pgf@yc\pgf@y% save
210 % compute normal:
211 \advance\pgf@xb by-\pgf@xa%
212 \advance\pgf@yb by-\pgf@ya%
213 \pgf@process{\pgfpointnormalised{\pgf@x=\pgf@xb\pgf@y=\pgf@yb}}
214 }%
215
216 \def\pgf@bending@possible@degenerate{%
217 \ifx\pgf@curvilinear@line@a\pgf@curvilinear@line@b% degenerate!
218 \ifx\pgf@curvilinear@line@a\pgf@curvilinear@line@c% double degenerate!
219 \let\pgf@ref\pgf@curvilinear@line@d%
220 \else
221 \let\pgf@ref\pgf@curvilinear@line@c%
222 \fi%
223 \pgf@process{\pgf@curvilinear@line@a}%
224 \pgf@xc\pgf@x% save
225 \pgf@yc\pgf@y% save
226 \pgf@process{\pgf@ref}%
227 \advance\pgf@x by-\pgf@xc
228 \advance\pgf@y by-\pgf@yc
229 \pgf@process{\pgfpointnormalised{}}
230 \pgf@x-\pgf@x
231 \pgf@y-\pgf@y
232 \else%
233 \pgf@bending@do@tangent@normal%
234 \fi%
235 }%
236
237 \def\pgf@bending@do@flex{
238 \pgf@xb\pgf@xa%
239 \pgf@xc\pgf@xa%
240 \advance\pgf@xc by-\pgf@x%
241 \advance\pgf@xb by-\pgf@y%
242 \pgfcurvilineardistancetotime{\pgf@xc}%
243 \pgf@xc\pgf@x%
244 \pgfcurvilineardistancetotime{\pgf@xb}%
245 \pgf@xb\pgf@x%
246 % Compute points:
247 \pgf@process{\pgfpointcurveattime{\pgf@xc}{\pgf@curvilinear@line@a}{\pgf@curvilinear@line@b}{\pgf@curvilinear@line@c}{\pgf@curvilinear@line@d}}%
248 \pgf@xc\pgf@x\pgf@yc\pgf@y%
249 \pgf@process{\pgfpointcurveattime{\pgf@xb}{\pgf@curvilinear@line@a}{\pgf@curvilinear@line@b}{\pgf@curvilinear@line@c}{\pgf@curvilinear@line@d}}%
250 \pgf@xb\pgf@x\pgf@yb\pgf@y%
251 \pgftransformarrow{\pgfqpoint{\pgf@xb}{\pgf@yb}}{\pgfqpoint{\pgf@xc}{\pgf@yc}}%
252 }%
253
254
255
256
257
258
259 % Convex hull stuff:
260
261 \def\pgf@arrows@bending@hull{%
262 \ifpgf@relevantforpicturesize%
263 % Do bb update:
264 \expandafter\let\expandafter\pgf@temp\csname pgf@ar@hull@\pgf@arrow@id\endcsname%
265 \ifx\pgf@temp\pgfutil@empty\else%
266 \let\pgf@arrow@hull@point\pgf@arrow@bending@hull@point@first%
267 \pgf@temp%
268 \pgf@arrow@bending@update@bb%
269 \fi%
270 \fi%
271 }%
272
273 \def\pgf@arrow@bending@hull@point@first#1#2{%
274 \pgfpointtransformednonlinear{\pgfqpoint{#1}{#2}}%
275 \pgf@xa\pgf@x\pgf@xb\pgf@x%
276 \pgf@ya\pgf@y\pgf@yb\pgf@y%
277 \let\pgf@arrow@hull@point\pgf@arrow@bending@hull@point@other%
278 }%
279 \def\pgf@arrow@bending@hull@point@other#1#2{%
280 \pgfpointtransformednonlinear{\pgfqpoint{#1}{#2}}%
281 \ifdim\pgf@x<\pgf@xa\pgf@xa\pgf@x\else\ifdim\pgf@x>\pgf@xb\pgf@xb\pgf@x\fi\fi%
282 \ifdim\pgf@y<\pgf@ya\pgf@ya\pgf@y\else\ifdim\pgf@y>\pgf@yb\pgf@yb\pgf@y\fi\fi%
283 }%
284
285 \def\pgf@arrow@bending@update@bb{%
286 \ifdim\pgf@picmaxx=-16000pt\relax%
287 \global\pgf@picminx\pgf@xa%
288 \global\pgf@picmaxx\pgf@xb%
289 \global\pgf@picminy\pgf@ya%
290 \global\pgf@picmaxy\pgf@yb%
291 \else%
292 \ifdim\pgf@xa<\pgf@picminx\global\pgf@picminx\pgf@xa\fi%
293 \ifdim\pgf@ya<\pgf@picminy\global\pgf@picminy\pgf@ya\fi%
294 \ifdim\pgf@xb>\pgf@picmaxx\global\pgf@picmaxx\pgf@xb\fi%
295 \ifdim\pgf@yb>\pgf@picmaxy\global\pgf@picmaxy\pgf@yb\fi%
296 \fi%
297 }%
298
299
300
301
302 %
303 %
304 % Handle the start of a curve
305 %
306 %
307
308
309 % First, the preparation.
310
311 \def\pgf@prep@curvedstart{
312 \pgftransformreset%
313 \pgfsetcurvilinearbeziercurve{\pgfpointfirstonpath}{\pgfpointsecondonpath}{\pgfpointthirdonpath}{\pgfpointfourthonpath}%
314 }%
315
316 % Second, the shortening.
317
318 \def\pgf@do@shorten@curvedstart{%
319 \expandafter\expandafter\expandafter\pgf@do@shorten@curvedstart@unpack\expandafter\pgfpointthirdonpath\pgfpointfourthonpath%
320 }%
321 \def\pgf@do@shorten@curvedstart@unpack\pgfqpoint#1#2\pgfqpoint#3#4{%
322 \pgf@process{\pgfcurvilineardistancetotime{\pgf@path@shortening@distance}}%
323 % Compute new curve:
324 \pgfpointcurveattime{\pgf@x}{\pgfpointfirstonpath}{\pgfpointsecondonpath}{\pgfpointthirdonpath}{\pgfpointfourthonpath}%
325 % \pgfx/y and \pgf xa/xb already correct. Need to setup remaining vector...
326 \pgf@xb#1%
327 \pgf@yb#2%
328 \pgf@xb\pgf@time@t\pgf@xb%
329 \pgf@yb\pgf@time@t\pgf@yb%
330 \advance\pgf@xb by\pgf@time@s\pgf@xc%
331 \advance\pgf@yb by\pgf@time@s\pgf@yc%
332 \edef\pgfpointfirstonpath{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}%
333 \edef\pgfpointsecondonpath{\noexpand\pgfqpoint{\the\pgf@xa}{\the\pgf@ya}}%
334 \edef\pgfprocessresultpathsuffix{%
335 \noexpand\pgfsyssoftpath@movetotoken{\the\pgf@x}{\the\pgf@y}%
336 \noexpand\pgfsyssoftpath@curvetosupportatoken{\the\pgf@xa}{\the\pgf@ya}%
337 \noexpand\pgfsyssoftpath@curvetosupportbtoken{\the\pgf@xb}{\the\pgf@yb}%
338 \noexpand\pgfsyssoftpath@curvetotoken{#3}{#4}%
339 }
340 \expandafter\expandafter\expandafter\def%
341 \expandafter\expandafter\expandafter\pgfprocessresultpathsuffix%
342 \expandafter\expandafter\expandafter{\expandafter\pgfprocessresultpathsuffix\pgfsubpathend}%
343 }%
344
345
346 % Third, the drawing
347
348 \def\pgf@do@draw@curvedstart{%
349 \pgf@do@draw@curved\pgf@start@tip@sequence%
350 }%
351
352
353
354
355
356 \endinput