Debian Codegraph @

texmf-dist/tex/generic/tikz-ext/tikzlibraryext.paths.arcto.code.tex

raw
1 % Copyright 2022 by Qrrbrbirlbel
2 %
3 % This file may be distributed and/or modified
4 %
5 % 1. under the LaTeX Project Public License and/or
6 % 2. under the GNU Free Documentation License.
7 %
8 \unless\ifcsname tikzextset\endcsname
9 \input tikzext-util.tex
10 \fi
11
12 \tikzextset{
13 arc to/.code=\pgfqkeys{/tikz/ext/arc to}{#1},
14 arc to={
15 counter clockwise/.code=\pgfkeyssetvalue{/tikz/ext/arc to/ccw flag}{1},
16 clockwise/.code=\pgfkeyssetvalue{/tikz/ext/arc to/ccw flag}{0},
17 x radius/.code=\pgfkeyssetvalue{/tikz/x radius}{#1},
18 y radius/.code=\pgfkeyssetvalue{/tikz/y radius}{#1},
19 radius/.code=\pgfkeyssetvalue{/tikz/x radius}{#1}\pgfkeyssetvalue{/tikz/y radius}{#1},
20 large/.code=\pgfkeyssetvalue{/tikz/ext/arc to/large flag}{1},
21 small/.code=\pgfkeyssetvalue{/tikz/ext/arc to/large flag}{0},
22 % defaults
23 rotate/.initial=0, counter clockwise, small,
24 counter clockwise/.value forbidden,
25 clockwise/.value forbidden,
26 large/.value forbidden,
27 small/.value forbidden}}
28 \let\tikzext@orig@tikz@arcA\tikz@arcA
29 \def\tikz@arcA rc{\pgfutil@ifnextchar t%
30 {\tikz@flush@moveto\expandafter\tikzext@arcto@cont\pgfutil@gobbletwo}
31 {\tikzext@orig@tikz@arcA rc}}
32 \def\tikzext@arcto@cont{%\tikzext@arcto@do
33 \pgfutil@ifnextchar[\tikzext@arcto@options{
34 \advance\tikz@expandcount by -10\relax% go down quickly
35 \ifnum\tikz@expandcount<0\relax%
36 \def\tikzext@next{\tikzext@arcto@options[]}%
37 \else%
38 \def\tikzext@next{\expandafter\tikzext@arcto@cont}%
39 \fi%
40 \tikzext@next}}%
41 \def\tikzext@arcto@options[#1]{%
42 \def\tikzext@arcto@options@{#1}%
43 \tikzext@arcto@collect}
44 \def\tikzext@arcto@collect{%
45 \pgfutil@ifnextchar n{\tikz@collect@label@onpath\tikzext@arcto@collect}
46 {\pgfutil@ifnextchar c{\tikz@collect@coordinate@onpath\tikzext@arcto@collect}
47 {\pgfutil@ifnextchar p{\tikz@collect@pic@onpath\tikzext@arcto@collect}
48 {\tikz@scan@one@point\tikzext@arcto@do}}}}
49
50 \def\tikzext@arcto@do#1{%
51 \edef\tikz@timer@start{\noexpand\pgfqpoint{\the\tikz@lastx}{\the\tikz@lasty}}
52 \tikz@make@last@position{#1}%
53 \edef\tikz@timer@end{\noexpand\pgfqpoint{\the\tikz@lastx}{\the\tikz@lasty}}%
54 \iftikz@shapeborder
55 \edef\tikz@moveto@waiting{\tikz@shapeborder@name}%
56 \fi
57 \begingroup
58 \tikzset{every arc/.try,ext/every arc to/.try,ext/arc to/.expand once=\tikzext@arcto@options@}%
59 \pgfmathsetmacro\tikz@arc@x{\pgfkeysvalueof{/tikz/x radius}}%
60 \ifpgfmathunitsdeclared
61 \pgfmathsetmacro\tikz@arc@y{\pgfkeysvalueof{/tikz/y radius}}%
62 \ifpgfmathunitsdeclared
63 \tikzext@pgfpatharcto{\tikz@arc@x pt}{\tikz@arc@y pt}
64 {\pgfkeysvalueof{/tikz/ext/arc to/rotate}}{\pgfkeysvalueof{/tikz/arc to/large flag}}
65 {\pgfkeysvalueof{/tikz/ext/arc to/ccw flag}}{#1}%
66 \else
67 \tikzerror{You cannot mix dimensions and dimension values in an arc}%
68 \fi
69 \else
70 \pgfmathsetmacro\tikz@arc@y{\pgfkeysvalueof{/tikz/y radius}}%
71 \ifpgfmathunitsdeclared
72 \tikzerror{You cannot mix dimensions and dimension values in an arc}%
73 \else
74 \pgf@process{\pgfpointxy{\tikz@arc@x}{0}}%
75 \pgfmathveclen@{\pgf@sys@tonumber\pgf@x}{\pgf@sys@tonumber\pgf@y}%
76 \let\tikz@arc@x\pgfmathresult
77 \pgf@process{\pgfpointxy{0}{\tikz@arc@y}}%
78 \pgfmathveclen@{\pgf@sys@tonumber\pgf@x}{\pgf@sys@tonumber\pgf@y}%
79 \let\tikz@arc@y\pgfmathresult
80 \tikzext@pgfpatharcto{+\tikz@arc@x pt}{+\tikz@arc@y pt}
81 {\pgfkeysvalueof{/tikz/ext/arc to/rotate}}{\pgfkeysvalueof{/tikz/ext/arc to/large flag}}
82 {\pgfkeysvalueof{/tikz/ext/arc to/ccw flag}}{#1}%
83 \fi
84 \fi
85 \endgroup
86 % check whether \pgf@marshall starts with \pgfpathlineto
87 \pgfutil@ifxempty\pgf@marshal{}{%
88 \edef\tikz@temp{\expandafter\expandafter\expandafter\noexpand\expandafter\tikzextutil@firstgobblerest\pgf@marshal\relax}%
89 \expandafter\let\expandafter\tikz@temp\tikz@temp
90 \pgfutil@ifx\tikz@temp\pgfpathlineto{}{%
91 % getting rid of \pgfpatharcaxes inside \pgf@marshal
92 \expandafter\expandafter\expandafter\def\expandafter\expandafter\expandafter\pgf@marshal
93 \expandafter\expandafter\expandafter{\expandafter\pgfutil@gobble\pgf@marshal}%
94 % extracting the other four values needed for the timer
95 \edef\tikz@timer@start@angle{\expandafter\tikzextutil@firstoffour\pgf@marshal}%
96 \edef\tikz@timer@end@angle{\expandafter\tikzextutil@secondoffour\pgf@marshal}%
97 \pgfextract@process\tikz@timer@zero@axis{\expandafter\tikzextutil@thirdoffour\pgf@marshal}%
98 \pgfextract@process\tikz@timer@ninety@axis{\expandafter\tikzextutil@fourthoffour\pgf@marshal}%
99 %
100 \let\tikz@timer=\tikz@timer@arc
101 }%
102 }%
103 \tikz@scan@next@command
104 }
105 \def\tikzextutil@firstoffour#1#2#3#4{#1}
106 \def\tikzextutil@secondoffour#1#2#3#4{#2}
107 \def\tikzextutil@thirdoffour#1#2#3#4{#3}
108 \def\tikzextutil@fourthoffour#1#2#3#4{#4}
109 \def\tikzextutil@firstgobblerest#1#2\relax{#1}
110
111 % original from pgfcorepathconstruct.code.tex
112 \def\tikzext@pgfpatharcto#1#2#3#4#5#6{%
113 {%
114 % The following code is based on the transformation described in svg
115 % 1.1 specification Section F.6.5
116 %
117 % Step 1: store the simple parameters (xa=x1 since TeX does not
118 % allow numbers in names)
119 %
120 \pgfmathsetmacro\pgf@arcto@rx{abs(#1)}%
121 \pgfmathsetmacro\pgf@arcto@ry{abs(#2)}%
122 \ifdim\pgf@arcto@rx pt=0pt% special rule: zero radius=straight line
123 \gdef\pgf@marshal{\pgfpathlineto{#6}}%
124 \else
125 \ifdim\pgf@arcto@ry pt=0pt% special rule: zero radius=straight line
126 \gdef\pgf@marshal{\pgfpathlineto{#6}}%
127 \else
128 \pgfmathsetmacro\pgf@arcto@phi{#3}%
129 \pgfmathsetmacro\pgf@arcto@fA{#4}%
130 \ifdim\pgf@arcto@fA pt=0pt
131 \else
132 \pgfmathsetmacro\pgf@arcto@fA{0.6}% Special rule: every non-zero value is 1.
133 \fi
134 \pgfmathsetmacro\pgf@arcto@fS{#5}%
135 \ifdim\pgf@arcto@fS pt=0pt
136 \else
137 \pgfmathsetmacro\pgf@arcto@fS{0.6}% Special rule: every non-zero value is 1.
138 \fi
139 \pgf@process{#6}%
140 \edef\pgf@arcto@xb{\the\pgf@x}%
141 \edef\pgf@arcto@yb{\the\pgf@y}%
142 %
143 % Step 2: x1,y1 is more complicated to compute: It is given by lastx
144 % and lasty, but these are transformed coordinates, we need the
145 % untransformed ones. So, we inverse the transformation (arghh...)
146 %
147 \pgftransforminvert%
148 \pgf@process{\pgfpointtransformed{\pgfqpoint{\pgf@path@lastx}{\pgf@path@lasty}}}%
149 \edef\pgf@arcto@xa{\the\pgf@x}%
150 \edef\pgf@arcto@ya{\the\pgf@y}%
151 \edef\pgf@temp@a{\pgf@arcto@xa,\pgf@arcto@ya}%
152 \edef\pgf@temp@b{\pgf@arcto@xb,\pgf@arcto@yb}%
153 \ifx\pgf@temp@a\pgf@temp@b% special rule: skip!
154 \global\let\pgf@marshal\pgfutil@empty
155 \else
156 %
157 % Ok, now we got all the parameters setup. Now comes the
158 % computation...
159 %
160 %
161 % Step 3: Start with a new coordinate system and rotate everything
162 % by the negated phi.
163 %
164 \pgftransformreset
165 \pgftransformrotate{-\pgf@arcto@phi}%
166 % Ok, using \pgfpointtransformed we now get transformed points...
167 %
168 % Step 4: Compute x1' and y1' (xaprime and yaprime)
169 %
170 \pgf@process{%
171 \pgfpointtransformed{\pgfpointscale{.5}{\pgfpointdiff
172 {\pgfqpoint{\pgf@arcto@xb}{\pgf@arcto@yb}}
173 {\pgfqpoint{\pgf@arcto@xa}{\pgf@arcto@ya}}%
174 }%
175 }%
176 }%
177 \edef\pgf@arcto@xaprime{\pgf@sys@tonumber\pgf@x}%
178 \edef\pgf@arcto@yaprime{\pgf@sys@tonumber\pgf@y}%
179 %
180 % Compute Lambda
181 %
182 \pgfmathsetmacro\pgf@arcto@frac@x{\pgf@arcto@xaprime/\pgf@arcto@rx}%
183 \pgfmathsetmacro\pgf@arcto@frac@y{\pgf@arcto@yaprime/\pgf@arcto@ry}%
184 \pgfmathsetmacro\pgf@arcto@lambda{
185 \pgf@arcto@frac@x*\pgf@arcto@frac@x+\pgf@arcto@frac@y*\pgf@arcto@frac@y
186 }%
187 \ifdim\pgf@arcto@lambda pt>1pt
188 \pgfmathsetmacro\pgf@arcto@sqrt@lambda{sqrt(\pgf@arcto@lambda)}%
189 \pgfmathsetmacro\pgf@arcto@rx{\pgf@arcto@sqrt@lambda*\pgf@arcto@rx}%
190 \pgfmathsetmacro\pgf@arcto@ry{\pgf@arcto@sqrt@lambda*\pgf@arcto@ry}%
191 \fi
192 %
193 % Do some scaling
194 %
195 \pgfmathsetmacro\pgf@arcto@xaprime@abs{abs(\pgf@arcto@xaprime)}%
196 \pgfmathsetmacro\pgf@arcto@yaprime@abs{abs(\pgf@arcto@yaprime)}%
197 \pgfmathmax@{\pgf@arcto@rx,\pgf@arcto@ry,\pgf@arcto@xaprime@abs,\pgf@arcto@yaprime@abs}%
198 \pgfmathsetmacro\pgf@arcto@scaling{20/\pgfmathresult}%
199 \pgfmathsetmacro\pgf@arcto@rx@scaled{\pgf@arcto@scaling*\pgf@arcto@rx}%
200 \pgfmathsetmacro\pgf@arcto@ry@scaled{\pgf@arcto@scaling*\pgf@arcto@ry}%
201 \pgfmathsetmacro\pgf@arcto@xaprime@scaled{\pgf@arcto@scaling*\pgf@arcto@xaprime}%
202 \pgfmathsetmacro\pgf@arcto@yaprime@scaled{\pgf@arcto@scaling*\pgf@arcto@yaprime}%
203 %
204 % Step 5: Now comes the messy computation of c1' and c2'.
205 %
206 \ifdim\pgf@arcto@rx pt>\pgf@arcto@ry pt
207 \pgfmathsetmacro\pgf@arcto@rx@over@ry{\pgf@arcto@rx/\pgf@arcto@ry}%
208 \pgfmathsetmacro\pgf@arcto@ry@over@rx{\pgf@arcto@ry/\pgf@arcto@rx}%
209 \pgfmathsetmacro\pgf@arcto@temp{\pgf@arcto@ry@over@rx*\pgf@arcto@xaprime@scaled}%
210 \pgfmathsetmacro\pgf@arcto@numerator{
211 \pgf@arcto@ry@scaled*\pgf@arcto@ry@scaled-
212 \pgf@arcto@yaprime@scaled*\pgf@arcto@yaprime@scaled-
213 \pgf@arcto@temp*\pgf@arcto@temp
214 }%
215 \pgfmathsetmacro\pgf@arcto@denominator{
216 \pgf@arcto@yaprime@scaled*\pgf@arcto@yaprime@scaled+
217 \pgf@arcto@temp*\pgf@arcto@temp
218 }%
219 \else
220 \pgfmathsetmacro\pgf@arcto@rx@over@ry{\pgf@arcto@rx/\pgf@arcto@ry}%
221 \pgfmathsetmacro\pgf@arcto@ry@over@rx{\pgf@arcto@ry/\pgf@arcto@rx}%
222 \pgfmathsetmacro\pgf@arcto@temp{\pgf@arcto@rx@over@ry*\pgf@arcto@yaprime@scaled}%
223 \pgfmathsetmacro\pgf@arcto@numerator{
224 \pgf@arcto@rx@scaled*\pgf@arcto@rx@scaled-
225 \pgf@arcto@xaprime@scaled*\pgf@arcto@xaprime@scaled-
226 \pgf@arcto@temp*\pgf@arcto@temp
227 }%
228 \pgfmathsetmacro\pgf@arcto@denominator{
229 \pgf@arcto@xaprime@scaled*\pgf@arcto@xaprime@scaled+
230 \pgf@arcto@temp*\pgf@arcto@temp
231 }%
232 \fi
233 \pgfmathsetmacro\pgf@arcto@frac{
234 \pgf@arcto@numerator/\pgf@arcto@denominator
235 }%
236 \ifdim\pgf@arcto@frac pt<0pt
237 \pgfmathsetmacro\pgf@arcto@factor{0}%
238 \else
239 \pgfmathsetmacro\pgf@arcto@factor{sqrt(\pgf@arcto@frac)}%
240 \fi
241 \ifx\pgf@arcto@fA\pgf@arcto@fS
242 \pgfmathsetmacro\pgf@arcto@factor{-\pgf@arcto@factor}%
243 \fi
244 \pgfmathsetmacro\pgf@arcto@cxprime{
245 \pgf@arcto@factor*\pgf@arcto@rx@over@ry*\pgf@arcto@yaprime
246 }%
247 \pgfmathsetmacro\pgf@arcto@cyprime{
248 -\pgf@arcto@factor*\pgf@arcto@ry@over@rx*\pgf@arcto@xaprime
249 }%
250 %
251 % Step 6: Ok, now compute cx,cy
252 %
253 \pgftransformreset
254 \pgftransformrotate{\pgf@arcto@phi}%
255 \pgf@process{%
256 \pgfpointtransformed{\pgfqpoint{\pgf@arcto@cxprime pt}{\pgf@arcto@cyprime pt}}%
257 }%
258 \edef\pgf@arcto@temp{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}%
259 \pgf@process{\pgfpointadd{\pgf@arcto@temp}{%
260 \pgfpointscale{.5}{%
261 \pgfpointadd
262 {\pgfqpoint{\pgf@arcto@xa}{\pgf@arcto@ya}}
263 {\pgfqpoint{\pgf@arcto@xb}{\pgf@arcto@yb}}}%
264 }%
265 }%
266 \edef\pgf@arcto@cx{\the\pgf@x}%
267 \edef\pgf@arcto@cy{\the\pgf@y}%
268 %
269 % Step 7: Compute start angle:
270 %
271 \pgfmathsetmacro\pgf@arcto@vec@x{(\pgf@arcto@xaprime-\pgf@arcto@cxprime)/\pgf@arcto@rx}%
272 \pgfmathsetmacro\pgf@arcto@vec@y{(\pgf@arcto@yaprime-\pgf@arcto@cyprime)/\pgf@arcto@ry}%
273 \pgfmathsetmacro\pgf@arcto@denominator{veclen(\pgf@arcto@vec@x,\pgf@arcto@vec@y)}%
274 \pgfmathsetmacro\pgf@arcto@frac{\pgf@arcto@vec@x/\pgf@arcto@denominator}%
275 \pgfmathsetmacro\pgf@arcto@theta@start{acos(\pgf@arcto@frac)}%
276 \ifdim\pgf@arcto@vec@y pt<0pt
277 \pgfmathsetmacro\pgf@arcto@theta@start{-\pgf@arcto@theta@start}%
278 \fi
279 %
280 % Step 8: Compute end angle:
281 %
282 \pgfmathsetmacro\pgf@arcto@vec@x{(-\pgf@arcto@xaprime-\pgf@arcto@cxprime)/\pgf@arcto@rx}%
283 \pgfmathsetmacro\pgf@arcto@vec@y{(-\pgf@arcto@yaprime-\pgf@arcto@cyprime)/\pgf@arcto@ry}%
284 \pgfmathsetmacro\pgf@arcto@denominator{veclen(\pgf@arcto@vec@x,\pgf@arcto@vec@y)}%
285 \pgfmathsetmacro\pgf@arcto@frac{\pgf@arcto@vec@x/\pgf@arcto@denominator}%
286 \pgfmathsetmacro\pgf@arcto@theta@end{acos(\pgf@arcto@frac)}%
287 \ifdim\pgf@arcto@vec@y pt<0pt
288 \pgfmathsetmacro\pgf@arcto@theta@end{-\pgf@arcto@theta@end}%
289 \fi
290 \pgfmathsetmacro\pgf@arcto@delta@theta{abs(\pgf@arcto@theta@start-\pgf@arcto@theta@end)}%
291 \ifdim\pgf@arcto@fA pt=0pt
292 \ifdim\pgf@arcto@delta@theta pt>180pt
293 % Ok, we need to adjust the angle!
294 \ifdim\pgf@arcto@theta@end pt>\pgf@arcto@theta@start pt
295 \pgfmathsetmacro\pgf@arcto@theta@end{\pgf@arcto@theta@end-360}%
296 \else
297 \pgfmathsetmacro\pgf@arcto@theta@end{\pgf@arcto@theta@end+360}%
298 \fi
299 \fi
300 \else
301 \ifdim\pgf@arcto@delta@theta pt<180pt
302 % Ok, we need to adjust the angle!
303 \ifdim\pgf@arcto@theta@end pt>\pgf@arcto@theta@start pt
304 \pgfmathsetmacro\pgf@arcto@theta@end{\pgf@arcto@theta@end-360}%
305 \else
306 \pgfmathsetmacro\pgf@arcto@theta@end{\pgf@arcto@theta@end+360}%
307 \fi
308 \fi
309 \fi
310 % Qrr:
311 % make sure direction is properly followed
312 \ifdim\pgf@arcto@fS pt=1pt
313 % counter clockwise
314 \ifdim\pgf@arcto@theta@end pt<\pgf@arcto@theta@start pt
315 \pgfmathsetmacro\pgf@arcto@theta@end{\pgf@arcto@theta@end+360}%
316 \fi
317 \else
318 % clockwise
319 \ifdim\pgf@arcto@theta@end pt>\pgf@arcto@theta@start pt
320 \pgfmathsetmacro\pgf@arcto@theta@end{\pgf@arcto@theta@end-360}%
321 \fi
322 \fi
323 \xdef\pgf@marshal{\noexpand
324 \pgfpatharcaxes{\pgf@arcto@theta@start}{\pgf@arcto@theta@end}
325 {\noexpand\pgfpointpolar{\pgf@arcto@phi}{\pgf@arcto@rx}}
326 {\noexpand\pgfpointpolar{\pgf@arcto@phi+90}{\pgf@arcto@ry}}%
327 }%
328 \fi\fi\fi
329 }%
330 \pgf@marshal
331 }
332
333 %%% Compatibility
334 \tikzextset{
335 /tikz-ext/compat/add library={paths.arcto}{pre 0.6},
336 compat/paths.arcto/warn/.append code=%
337 \tikzextutil@compatwarning@key {paths.arcto}{pre 0.6}{/tikz/arc to/clockwise} {/tikz/ext/arc to/clockwise}%
338 \tikzextutil@compatwarning@key {paths.arcto}{pre 0.6}{/tikz/arc to/counter clockwise}{/tikz/ext/arc to/counter clockwise}%
339 \tikzextutil@compatwarning@key {paths.arcto}{pre 0.6}{/tikz/arc to/large} {/tikz/ext/arc to/large}%
340 \tikzextutil@compatwarning@key {paths.arcto}{pre 0.6}{/tikz/arc to/small} {/tikz/ext/arc to/small}%
341 \tikzextutil@compatwarning@key {paths.arcto}{pre 0.6}{/tikz/arc to/radius} {/tikz/ext/arc to/radius}%
342 \tikzextutil@compatwarning@key {paths.arcto}{pre 0.6}{/tikz/arc to/x radius} {/tikz/ext/arc to/x radius}%
343 \tikzextutil@compatwarning@key {paths.arcto}{pre 0.6}{/tikz/arc to/y radius} {/tikz/ext/arc to/y radius}%
344 \tikzextutil@compatwarning@valuekey{paths.arcto}{pre 0.6}{/tikz/arc to/rotate} {/tikz/ext/arc to/rotate},
345 compat/paths.arcto/pre 0.6/.append code=%
346 \pgfkeysdef{/tikz/arc to/clockwise} {\pgfkeysvalueof{/tikz/ext/arc to/clockwise/.@cmd}##1\pgfeov}%
347 \pgfkeysdef{/tikz/arc to/counter clockwise}{\pgfkeysvalueof{/tikz/ext/arc to/counter clockwise/.@cmd}##1\pgfeov}%
348 \pgfkeysdef{/tikz/arc to/large} {\pgfkeysvalueof{/tikz/ext/arc to/large/.@cmd}##1\pgfeov}%
349 \pgfkeysdef{/tikz/arc to/small} {\pgfkeysvalueof{/tikz/ext/arc to/small/.@cmd}##1\pgfeov}%
350 \pgfkeysdef{/tikz/arc to/rotate} {\pgfkeyssetvalue{/tikz/ext/arc to/rotate}{##1}\pgfkeyssetvalue{/tikz/arc to/rotate}{##1}}%
351 \pgfkeysdef{/tikz/arc to/radius} {\pgfkeysvalueof{/tikz/ext/arc to/radius/.@cmd}##1\pgfeov}%
352 \pgfkeysdef{/tikz/arc to/x radius} {\pgfkeysvalueof{/tikz/ext/arc to/x radius/.@cmd}##1\pgfeov}%
353 \pgfkeysdef{/tikz/arc to/y radius} {\pgfkeysvalueof{/tikz/ext/arc to/y radius/.@cmd}##1\pgfeov},
354 compat/paths.arcto/\pgfkeysvalueof{/tikz/ext/compat/paths.arcto}%
355 }