Debian Codegraph @

texmf-dist/tex/generic/pgfplots/oldpgfcompatib/pgfplotsoldpgfsupp_trig_format.code.tex

raw
1 % This file contains patches to support 'trig format'
2 %
3 %%% This file is a copy of some part of PGF/Tikz.
4 %%% It has been copied here to provide :
5 %%% - compatibility with older PGF versions
6 %%% - availability of PGF contributions by Christian Feuersaenger
7 %%% which are necessary or helpful for pgfplots.
8 %%%
9 %%% This file contains just the functionality for trig format (written by Christian Feuersaenger).
10 %%%
11 % Support for the contents of this file will NOT be done by the PGF/TikZ team.
12 % Please contact the author and/or maintainer of pgfplots (Christian Feuersaenger) if you need assistance in conjunction
13 % with the deployment of this patch or partial content of PGF. Note that the author and/or maintainer of pgfplots has no obligation to fix anything:
14 % This file comes without any warranty as the rest of pgfplots; there is no obligation for help.
15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16
17 \pgfkeys{
18 /pgf/trig format/.is choice,
19 /pgf/trig format/deg/.code={\def\pgfmath@trig@format@choice{0}},
20 /pgf/trig format/rad/.code={\def\pgfmath@trig@format@choice{1}},
21 /pgf/trig format/deg,
22 }
23
24 % Executes #1 if 'trig format=deg' and #2 otherwise.
25 \def\pgfmathiftrigonometricusesdeg#1#2{%
26 \if0\pgfmath@trig@format@choice
27 #1%
28 \else
29 #2%
30 \fi
31 }%
32
33 \pgfutil@ifundefined{pgfmath@multiply@thousand}{%
34 % Oh - we are working against PGF 2.10 . Apply more patches:
35 %
36 \def\pgfmath@multiply@thousand#1.#2#3#4#5\relax{%
37 \edef\pgfmathresult{#1#2#3#4.#5}%
38 }%
39 % Defines \pgfmath@x to be the result of the table lookup for value
40 % '#1' in table '#2'
41 %
42 % #1: a value for which lookup should be performed
43 % #2: the table's prefix name
44 % #3: the table's size
45 \def\pgfmath@table@lookup#1#2#3{%
46 \pgfmath@x=#1\relax
47 \expandafter\pgfmath@table@lookup@\the\pgfmath@x\relax{#2}{#3}%
48 }
49 \def\pgfmath@table@lookup@#1.#2\relax#3#4{%
50 \edef\pgf@temp{\Pgf@geT#2}% strip 'pt' suffix.
51 %
52 % prepare constant interpolant (i.e. the value at node '#1'):
53 \pgfmath@x=\csname #3#1\endcsname pt %
54 %
55 \c@pgfmath@countc=#1 %
56 \advance\c@pgfmath@countc by1 %
57 \ifnum\c@pgfmath@countc<#4 %
58 % Ah - we have enough elements in the table.
59 %
60 % perform linear interpolation:
61 \pgfmath@ya=\csname #3\the\c@pgfmath@countc\endcsname pt %
62 \advance\pgfmath@ya by-\pgfmath@x %
63 \advance\pgfmath@x by0.\pgf@temp\pgfmath@ya
64 \fi
65 }%
66 }{}%
67
68
69
70 \def\pgfmath@scale@rad@to@deg#1{%
71 #1=57.29577#1\relax% 57.29577 = 360/(2*pi)
72 }%
73 \def\pgfmath@scale@deg@to@rad#1{%
74 #1=3.14159#1%
75 \divide#1180\relax%
76 }%
77
78 \def\pgfmathsin@#1{%
79 % Let #1 = a.b
80 % Then sin(#1) \approx (1-b)*sin(a) + b*sin(a+1)
81 %
82 \begingroup%
83 \expandafter\pgfmath@x#1pt\relax%
84 \if1\pgfmath@trig@format@choice
85 % trig format=rad
86 \pgfmath@scale@rad@to@deg\pgfmath@x
87 \fi
88 \advance\pgfmath@x-90pt\relax%
89 \afterassignment\pgfmath@gobbletilpgfmath@
90 \expandafter\c@pgfmath@counta\the\pgfmath@x\relax\pgfmath@
91 \divide\c@pgfmath@counta360\relax%
92 \multiply\c@pgfmath@counta-360\relax%
93 \advance\pgfmath@x\c@pgfmath@counta pt\relax%
94 \ifdim\pgfmath@x<0pt\relax\pgfmath@x-\pgfmath@x\fi%
95 \ifdim\pgfmath@x<180pt\relax%
96 \else
97 \pgfmath@x-\pgfmath@x%
98 \advance\pgfmath@x360pt\relax%
99 \fi%
100 % Now 0 <= x < 179. So split x into integer and decimal...
101 %
102 \afterassignment\pgfmath@xa%
103 \expandafter\c@pgfmath@counta\the\pgfmath@x\relax%
104 %
105 % ...if #1 is an integer, don't do anything fancy.
106 \ifdim\pgfmath@xa=0pt%
107 \expandafter\pgfmath@x\csname pgfmath@cos@\the\c@pgfmath@counta\endcsname pt\relax%
108 \else%
109 \pgfmath@x-\pgfmath@xa%
110 \advance\pgfmath@x1pt\relax%
111 \expandafter\pgfmath@x\csname pgfmath@cos@\the\c@pgfmath@counta\endcsname\pgfmath@x%
112 \advance\c@pgfmath@counta1\relax%
113 \ifnum\c@pgfmath@counta=181\relax\c@pgfmath@counta179\relax\fi%
114 \expandafter\advance\expandafter\pgfmath@x\csname pgfmath@cos@\the\c@pgfmath@counta\endcsname\pgfmath@xa%
115 \fi%
116 \pgfmath@returnone\pgfmath@x%
117 \endgroup
118 }
119
120 % \pgfmathcos
121 %
122 % Calculate the cosine of #1 (in degrees).
123 %
124 \def\pgfmathcos@#1{%
125 % Let x = a.b
126 % Then cos(x) \approx (1-b)*cos(a) + b*cos(a+1)
127 %
128 \begingroup%
129 \expandafter\pgfmath@x#1pt\relax%
130 \if1\pgfmath@trig@format@choice
131 % trig format=rad
132 \pgfmath@scale@rad@to@deg\pgfmath@x
133 \fi
134 \afterassignment\pgfmath@gobbletilpgfmath@%
135 \expandafter\c@pgfmath@counta\the\pgfmath@x\relax\pgfmath@%
136 \divide\c@pgfmath@counta360\relax%
137 \multiply\c@pgfmath@counta-360\relax%
138 \advance\pgfmath@x\c@pgfmath@counta pt\relax%
139 \ifdim\pgfmath@x<0pt\relax\pgfmath@x-\pgfmath@x\fi%
140 \ifdim\pgfmath@x<180pt\relax%
141 \else%
142 \pgfmath@x-\pgfmath@x%
143 \advance\pgfmath@x360pt\relax%
144 \fi%
145 % Now 0 <= x < 179. So split x into integer and decimal...
146 %
147 \afterassignment\pgfmath@xa%
148 \expandafter\c@pgfmath@counta\the\pgfmath@x\relax%
149 %
150 % ...if #1 is an integer, don't do anything fancy.
151 \ifdim\pgfmath@xa=0pt%
152 \expandafter\pgfmath@x\csname pgfmath@cos@\the\c@pgfmath@counta\endcsname pt%
153 \else%
154 \pgfmath@x-\pgfmath@xa%
155 \advance\pgfmath@x1pt\relax%
156 \expandafter\pgfmath@x\csname pgfmath@cos@\the\c@pgfmath@counta\endcsname\pgfmath@x%
157 \advance\c@pgfmath@counta1\relax%
158 \ifnum\c@pgfmath@counta=181\relax\c@pgfmath@counta179\relax\fi%
159 \expandafter\advance\expandafter\pgfmath@x\csname pgfmath@cos@\the\c@pgfmath@counta\endcsname\pgfmath@xa%
160 \fi%
161 \pgfmath@returnone\pgfmath@x%
162 \endgroup%
163 }
164
165 \def\pgfmathasin@#1{%
166 \begingroup%
167 \pgfmath@x=#1pt %
168 \pgfmath@xa\pgfmath@x%
169 \edef\pgf@temp{\pgf@sys@tonumber\pgfmath@x}%
170 % compute lossless '*1000' operation:
171 \expandafter\pgfmath@multiply@thousand\pgf@temp 000\relax
172 \pgfmath@x=\pgfmathresult pt %
173 \ifdim\pgfmath@x<0pt\relax%
174 \pgfmath@x-\pgfmath@x%
175 \fi%
176 \pgfmath@table@lookup{\pgfmath@x}{pgfmath@acos@}{1001}%
177 \pgfmath@x=-\pgfmath@x
178 \advance\pgfmath@x90pt\relax%
179 \ifdim\pgfmath@xa<0pt\relax%
180 \pgfmath@x-\pgfmath@x%
181 \fi%
182 \if1\pgfmath@trig@format@choice
183 % trig format=rad
184 \pgfmath@scale@deg@to@rad\pgfmath@x
185 \fi
186 \pgfmath@returnone\pgfmath@x%
187 \endgroup%
188 }
189 \def\pgfmathacos@#1{%
190 \begingroup%
191 \pgfmath@x#1pt\relax%
192 \pgfmath@xa\pgfmath@x%
193 \edef\pgf@temp{\pgf@sys@tonumber\pgfmath@x}%
194 % compute lossless '*1000' operation:
195 \expandafter\pgfmath@multiply@thousand\pgf@temp 000\relax
196 \pgfmath@x=\pgfmathresult pt %
197 \ifdim\pgfmath@x<0pt\relax%
198 \pgfmath@x-\pgfmath@x%
199 \fi%
200 \pgfmath@table@lookup{\pgfmath@x}{pgfmath@acos@}{1001}%
201 \ifdim\pgfmath@xa<0pt\relax%
202 \pgfmath@x-\pgfmath@x%
203 \advance\pgfmath@x by180pt\relax%
204 \fi%
205 \if1\pgfmath@trig@format@choice
206 % trig format=rad
207 \pgfmath@scale@deg@to@rad\pgfmath@x
208 \fi
209 \pgfmath@returnone\pgfmath@x%
210 \endgroup%
211 }
212
213 \def\pgfmathatan@#1{%
214 \begingroup%
215 \expandafter\pgfmath@x#1pt\relax%
216 \pgfmath@xa\pgfmath@x%
217 \ifdim\pgfmath@x<0pt\relax%
218 \pgfmath@x-\pgfmath@x%
219 \fi%
220 \pgfmath@xb\pgfmath@x%
221 \ifdim\pgfmath@x>1pt\relax%
222 \edef\pgfmath@temp{\pgfmath@tonumber{\pgfmath@x}}%
223 \pgfmathreciprocal@{\pgfmath@temp}%
224 \pgfmath@x\pgfmathresult pt\relax%
225 \fi%
226 % compute lossless '*1000' operation:
227 \edef\pgf@temp{\pgf@sys@tonumber\pgfmath@x}%
228 \expandafter\pgfmath@multiply@thousand\pgf@temp 000\relax
229 \pgfmath@x=\pgfmathresult pt %
230 \pgfmath@table@lookup{\pgfmath@x}{pgfmath@atan@}{1001}%xxx
231 \ifdim\pgfmath@xb>1pt\relax%
232 \pgfmath@x=-\pgfmath@x%
233 \advance\pgfmath@x90pt%
234 \fi%
235 \ifdim\pgfmath@xa<0pt\relax%
236 \pgfmath@x-\pgfmath@x%
237 \fi%
238 \if1\pgfmath@trig@format@choice
239 % trig format=rad
240 \pgfmath@scale@deg@to@rad\pgfmath@x
241 \fi
242 \pgfmath@returnone\pgfmath@x%
243 \endgroup%
244 }
245
246 \expandafter\def\csname pgfmathatan2@\endcsname#1#2{%
247 % Note: first parameter is y (!), second is x (!)
248 \begingroup%
249 \pgfmath@y=#1pt\relax%
250 \ifdim\pgfmath@y<0pt\relax%
251 \pgfmath@y=-\pgfmath@y%
252 \fi%
253 \ifdim\pgfmath@y<0.001pt\relax%
254 \ifdim#2pt<0pt\relax%
255 \pgfmath@x=-180pt\relax%
256 \else%
257 \ifdim#2pt>0pt\relax%
258 \pgfmath@x=0pt\relax%
259 \else%
260 \ifdim#1pt<0pt%
261 \pgfmath@x=-90pt\relax%
262 \else%
263 \pgfmath@x=90pt\relax%
264 \fi%
265 \fi%
266 \fi%
267 \else%
268 \pgfmathabs@{#1}\let\pgfmath@tempa\pgfmathresult%
269 \pgfmathabs@{#2}\let\pgfmath@tempb\pgfmathresult%
270 \ifdim\pgfmath@tempa pt>\pgfmath@tempb pt%
271 \pgfmathdivide@{#2}{\pgfmath@tempa}%
272 \expandafter\pgfmathatan@\expandafter{\pgfmathresult}%
273 \pgfmath@x=90pt%
274 \advance\pgfmath@x by-\pgfmathresult pt\relax%
275 \else%
276 \pgfmathdivide@{\pgfmath@tempa}{#2}%
277 \expandafter\pgfmathatan@\expandafter{\pgfmathresult}%
278 \pgfmath@x=\pgfmathresult pt\relax%
279 \ifdim#2pt<0pt%
280 \advance\pgfmath@x by180pt\relax%
281 \fi%
282 \fi%
283 \ifdim#1pt<0pt\relax%
284 \pgfmath@x=-\pgfmath@x%
285 \fi%
286 \fi%
287 \if1\pgfmath@trig@format@choice
288 % trig format=rad
289 \pgfmath@scale@deg@to@rad\pgfmath@x
290 \fi
291 \pgfmath@returnone\pgfmath@x%
292 \endgroup%
293 }
294
295 % FPU:
296
297
298 \let\pgfmath@basic@sin@=\pgfmathsin@
299 \let\pgfmath@basic@cos@=\pgfmathcos@
300 \let\pgfmath@basic@tan@=\pgfmathtan@
301 \let\pgfmath@basic@atan@=\pgfmathatan@
302 \let\pgfmath@basic@asin@=\pgfmathasin@
303 \let\pgfmath@basic@acos@=\pgfmathacos@
304 \let\pgfmath@basic@cot@=\pgfmathcot@
305 \let\pgfmath@basic@sec@=\pgfmathsec@
306 \let\pgfmath@basic@cosec@=\pgfmathcosec@
307
308 % Computes #1(#2) where #1 is a trigonometric function, i.e.
309 % #1(#2) = #1( #2 + r*360 )
310 %
311 % #1 is a one-argument macro which assigns \pgfmathresult.
312 \def\pgfmathfloatTRIG@#1#2{%
313 \if0\pgfmath@trig@format@choice
314 % trig format=deg
315 \expandafter\ifx\csname pgfmathfloatTRIG@NUM\endcsname\relax%
316 % Lazy evaluation:
317 \pgfmathfloatcreate{1}{3.6}{2}%
318 \global\let\pgfmathfloatTRIG@NUM=\pgfmathresult
319 \pgfmathfloatcreate{1}{2.77777777777778}{-3}%
320 \global\let\pgfmathfloatTRIG@NUM@INV=\pgfmathresult
321 \fi
322 \pgfmathfloatmodknowsinverse@{#2}{\pgfmathfloatTRIG@NUM}{\pgfmathfloatTRIG@NUM@INV}%
323 \else
324 % trig format=rad
325 \expandafter\ifx\csname pgfmathfloatTRIG@rad@NUM\endcsname\relax%
326 % Lazy evaluation:
327 \pgfmathfloatcreate{1}{6.28318530717959}{0}%
328 \global\let\pgfmathfloatTRIG@rad@NUM=\pgfmathresult
329 \pgfmathfloatcreate{1}{1.59154943091895}{-1}%
330 \global\let\pgfmathfloatTRIG@rad@NUM@INV=\pgfmathresult
331 \fi
332 \pgfmathfloatmodknowsinverse@{#2}{\pgfmathfloatTRIG@rad@NUM}{\pgfmathfloatTRIG@rad@NUM@INV}%
333 \fi
334 \pgfmathfloattofixed@{\pgfmathresult}%
335 \expandafter#1\expandafter{\pgfmathresult}%
336 \pgfmathfloatparsenumber{\pgfmathresult}%
337 }%
338
339 \def\pgfmathfloatsin@#1{\pgfmathfloatTRIG@\pgfmath@basic@sin@{#1}}
340 \let\pgfmathfloatsin=\pgfmathfloatsin@
341 \def\pgfmathfloatcos@#1{\pgfmathfloatTRIG@\pgfmath@basic@cos@{#1}}
342 \let\pgfmathfloatcos=\pgfmathfloatcos@
343 \def\pgfmathfloatsec@#1{\pgfmathfloatTRIG@\pgfmath@basic@cos@{#1}\pgfmathfloatreciprocal@{\pgfmathresult}}
344 \let\pgfmathfloatsec=\pgfmathfloatsec@
345 \def\pgfmathfloatcosec@#1{\pgfmathfloatTRIG@\pgfmath@basic@sin@{#1}\pgfmathfloatreciprocal@{\pgfmathresult}}
346 \let\pgfmathfloatcosec=\pgfmathfloatcosec@
347
348 \def\pgfmathfloatatan@#1{%
349 \begingroup
350 \expandafter\ifx\csname pgfmathfloatatan@TMP\endcsname\relax%
351 \pgfmathfloatcreate{1}{1.6}{4}%
352 \global\let\pgfmathfloatatan@TMP=\pgfmathresult
353 \pgfmathfloatcreate{2}{1.6}{4}%
354 \global\let\pgfmathfloatatan@TMPB=\pgfmathresult
355 \fi
356 \pgfmathfloatgreaterthan@{#1}{\pgfmathfloatatan@TMP}%
357 \ifpgfmathfloatcomparison
358 \pgfmathiftrigonometricusesdeg{%
359 \pgfmathfloatcreate{1}{9.0}{1}%
360 }{%
361 \pgfmathfloatcreate{1}{1.570796326794}{0}%
362 }%
363 \else
364 \pgfmathfloatlessthan{#1}{\pgfmathfloatatan@TMPB}%
365 \ifpgfmathfloatcomparison
366 \pgfmathiftrigonometricusesdeg{%
367 \pgfmathfloatcreate{2}{9.0}{1}%
368 }{%
369 \pgfmathfloatcreate{2}{1.570796326794}{0}%
370 }%
371 \else
372 \pgfmathfloattofixed@{#1}%
373 \expandafter\pgfmath@basic@atan@\expandafter{\pgfmathresult}%
374 \pgfmathfloatparsenumber{\pgfmathresult}%
375 \fi
376 \fi
377 \pgfmath@smuggleone\pgfmathresult
378 \endgroup
379 }%
380 \endinput