Debian Codegraph @

texmf-dist/tex/generic/pgf/basiclayer/pgfcoretransformations.code.tex

raw
1 % Copyright 2018 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{pgfcoretransformations.code.tex}
11
12
13 % Position transformations
14
15 \newdimen\pgf@pt@x
16 \newdimen\pgf@pt@y
17
18 \newdimen\pgf@pt@temp
19
20 \newif\ifpgf@pt@identity
21 \pgf@pt@identitytrue
22
23 \def\pgf@pt@aa{1.0} \def\pgf@pt@ab{0.0}
24 \def\pgf@pt@ba{0.0} \def\pgf@pt@bb{1.0}
25
26
27
28 % Store the current transformation matrix in a macro.
29 %
30 % #1 = macro name
31 %
32 % Example:
33 %
34 % \pgfgettransform\mytransform
35
36 \def\pgfgettransform#1{%
37 \edef#1{{\pgf@pt@aa}{\pgf@pt@ab}{\pgf@pt@ba}{\pgf@pt@bb}{\the\pgf@pt@x}{\the\pgf@pt@y}}%
38 }
39
40 % Store the current transformation matrix in a set of macros, one for
41 % each single entry.
42 %
43 % #1-#4 are macro which store the matrix entries (0,0), (0,1), (1,0),
44 % (1,1) (in this order). It is the same order as for \pgftransformcm.
45 %
46 % #5 is a macro which will be filled with the x shift and
47 % #6 is a macro which will be filled with the y shift.
48 %
49 % Example:
50 % \pgfgettransformentries\aa\ab\ba\bb\shiftx\shifty
51 %
52 % ->
53 %
54 % \pgftransformcm\aa\ab\ba\bb{\pgfqpoint{\shiftx}{\shifty}}
55 %
56 % or
57 %
58 % \pgfsettransformentries\aa\ab\ba\bb\shiftx\shifty
59 \def\pgfgettransformentries#1#2#3#4#5#6{%
60 \edef#1{\pgf@pt@aa}%
61 \edef#2{\pgf@pt@ab}% attention: this is (1,0), i.e. the point which is usually labelled 'ba'!
62 \edef#3{\pgf@pt@ba}% attention: this is (0,1), i.e. the point which is usually labelled 'ab'!
63 \edef#4{\pgf@pt@bb}%
64 \edef#5{\the\pgf@pt@x}%
65 \edef#6{\the\pgf@pt@y}%
66 }%
67 \def\pgfsettransformentries#1#2#3#4#5#6{%
68 \pgfsettransform{{#1}{#2}{#3}{#4}{#5}{#6}}%
69 }%
70
71 % Restore the current transformation matrix from a macro.
72 %
73 % #1 = macro name, previously used with \pgfgettransform
74 %
75 % Example:
76 %
77 % \pgfsettransform\mytransform
78
79 \def\pgfsettransform#1{%
80 \edef\pgf@temp{#1}%
81 \expandafter\pgf@settransform\pgf@temp%
82 }
83 \def\pgf@settransform#1#2#3#4#5#6{%
84 \def\pgf@pt@aa{#1}%
85 \def\pgf@pt@ab{#2}%
86 \def\pgf@pt@ba{#3}%
87 \def\pgf@pt@bb{#4}%
88 \pgf@pt@x=#5%
89 \pgf@pt@y=#6%
90 \edef\pgf@idtest{#1,#2,#3,#4}%
91 \ifx\pgf@idtest\pgf@idmatrixtext%
92 \pgf@pt@identitytrue%
93 \else%
94 \pgf@pt@identityfalse%
95 \fi%
96 }
97
98 \def\pgf@idmatrixtext{1.0,0.0,0.0,1.0}
99 \def\pgf@zerozerotext{0.0,0.0}
100 \def\pgf@one@text{1.0}
101 \def\pgf@zero@text{0.0}
102
103 % Transformation command
104 %
105 % #1 = x dimension
106 % #2 = y dimension
107 %
108 % Description:
109 %
110 % Applies the pgfs transformation matrix to the point (#1,#2). The
111 % result is once more stored in the point.
112 %
113 %
114 % Example:
115 %
116 % \pgf@pos@transform{\pgf@x}{\pgf@y}
117
118 \def\pgf@pos@transform#1#2{%
119 \ifpgf@pt@identity%
120 \else%
121 \pgf@pt@temp=#1%
122 #1=\pgf@pt@aa#1%
123 \advance#1 by\pgf@pt@ba#2%
124 #2=\pgf@pt@bb#2%
125 \advance#2 by\pgf@pt@ab\pgf@pt@temp%
126 \fi%
127 \advance#1 by\pgf@pt@x%
128 \advance#2 by\pgf@pt@y%
129 }
130 \def\pgf@pos@transform@glob{%
131 \ifpgf@pt@identity%
132 \else%
133 \pgf@pt@temp=\pgf@x%
134 \global\pgf@x=\pgf@pt@aa\pgf@x%
135 \global\advance\pgf@x by\pgf@pt@ba\pgf@y%
136 \global\pgf@y=\pgf@pt@bb\pgf@y%
137 \global\advance\pgf@y by\pgf@pt@ab\pgf@pt@temp%
138 \fi%
139 \global\advance\pgf@x by\pgf@pt@x%
140 \global\advance\pgf@y by\pgf@pt@y%
141 }
142
143
144 % Invert the current transformation matrix
145 %
146 % Description:
147 %
148 % This command replaces the current transformation matrix by its
149 % inverse. The inversion is not very exact if the matrix is nearly
150 % singular.
151 %
152 % Example:
153 %
154 % \pgftransforminvert
155
156 \def\pgftransforminvert{%
157 % First, invert the shift. That's easy
158 \pgf@pt@x=-\pgf@pt@x
159 \pgf@pt@y=-\pgf@pt@y
160 \ifpgf@pt@identity%
161 \else%
162 % Sigh. Have to calculate the inverse of the matrix.
163 % Perhaps we are lucky and ba and bb are zero?
164 \edef\pgf@zerotest{\pgf@pt@ab,\pgf@pt@ba}%
165 \ifx\pgf@zerotest\pgf@zerozerotext%
166 % Ha! Just invert aa and bb
167 \pgfmathreciprocal@{\pgf@pt@aa}%
168 \let\pgf@pt@aa\pgfmathresult%
169 \pgfmathreciprocal@{\pgf@pt@bb}%
170 \let\pgf@pt@bb\pgfmathresult%
171 \else%
172 % Start with determinant
173 % Matrix = (aa ab
174 % ba bb)
175 {%
176 \pgfutil@tempdima=\pgf@pt@aa pt%
177 \pgfutil@tempdima=\pgf@pt@bb\pgfutil@tempdima% aa * bb
178 \pgfutil@tempdimb=\pgf@pt@ba pt%
179 \pgfutil@tempdimb=\pgf@pt@ab\pgfutil@tempdimb% ba * ab
180 \advance\pgfutil@tempdima by -\pgfutil@tempdimb% aa*bb - ba*ab
181 % Invert
182 \pgfmathreciprocal@{\pgf@sys@tonumber{\pgfutil@tempdima}}%
183 \pgfutil@tempdima=\pgfmathresult pt%
184 \pgf@x=\pgf@pt@bb\pgfutil@tempdima% bb/(det A)
185 \xdef\pgf@new@pt@aa{\pgf@sys@tonumber{\pgf@x}}%
186 \pgf@x=\pgf@pt@aa\pgfutil@tempdima% aa/(det A)
187 \xdef\pgf@new@pt@bb{\pgf@sys@tonumber{\pgf@x}}%
188 \pgfutil@tempdima=-\pgfutil@tempdima%
189 \pgf@x=\pgf@pt@ba\pgfutil@tempdima% -ba/(det A)
190 \xdef\pgf@new@pt@ba{\pgf@sys@tonumber{\pgf@x}}%
191 \pgf@x=\pgf@pt@ab\pgfutil@tempdima% -ab/(det A)
192 \xdef\pgf@new@pt@ab{\pgf@sys@tonumber{\pgf@x}}%
193 }%
194 \let\pgf@pt@aa\pgf@new@pt@aa%
195 \let\pgf@pt@ab\pgf@new@pt@ab%
196 \let\pgf@pt@ba\pgf@new@pt@ba%
197 \let\pgf@pt@bb\pgf@new@pt@bb%
198 \fi%
199 \pgf@pt@temp=\pgf@pt@x%
200 \pgf@pt@x=\pgf@pt@aa\pgf@pt@x%
201 \advance\pgf@pt@x by\pgf@pt@ba\pgf@pt@y%
202 \pgf@pt@y=\pgf@pt@bb\pgf@pt@y%
203 \advance\pgf@pt@y by\pgf@pt@ab\pgf@pt@temp%
204 \fi%
205 }
206
207
208
209
210 % PGF-Level concatenation of the transformation matrix with a given
211 % matrix.
212 %
213 % #1 - #5 = a concatenation matrix (see pdf spec). Entry #5 is a
214 % translation point.
215 %
216 % Description:
217 %
218 % All coordinates given to subsequent path construction commands will
219 % be transformed additionally by the given transformation matrix. If
220 % the command is followed by a 6th argument, the transformation is
221 % only applied to this argument.
222 %
223 %
224 % Example:
225 %
226 % \pgftransformcm{1}{0}{0}{1}{\pgfpoint{100pt}{0pt}} % 100pt to the right.
227 %
228 % \pgftransformcm{2}{0}{0}{2}{\pgfpointorigin} % double in size
229 % \pgfpathmoveto{\pgfpoint{0cm}{0cm}}
230 % \pgfpathlineto{\pgflineto{1cm}{1cm}} % actually 2cm/2cm
231
232 \def\pgftransformcm#1#2#3#4#5{%
233 \edef\pgf@marshal{\noexpand\pgf@transformcm{#1}{#2}{#3}{#4}}%
234 \pgf@marshal{#5}%
235 }
236 \def\pgf@transformcm#1#2#3#4#5{%
237 {%
238 \pgf@process{#5}%
239 \pgf@xc=\pgf@x%
240 \pgf@yc=\pgf@y%
241 %
242 \pgfmathsetlength\pgf@x{#1}%
243 \pgfmathsetlength\pgf@y{#2}%
244 %
245 \pgf@xa=\pgf@pt@aa\pgf@x%
246 \advance\pgf@xa by \pgf@pt@ba\pgf@y%
247 %
248 \pgf@ya=\pgf@pt@ab\pgf@x%
249 \advance\pgf@ya by \pgf@pt@bb\pgf@y%
250 %
251 \pgfmathsetlength\pgf@x{#3}%
252 \pgfmathsetlength\pgf@y{#4}%
253 %
254 \pgf@xb=\pgf@pt@aa\pgf@x%
255 \advance\pgf@xb by \pgf@pt@ba\pgf@y%
256 %
257 \pgf@yb=\pgf@pt@ab\pgf@x%
258 \advance\pgf@yb by \pgf@pt@bb\pgf@y%
259 %
260 \pgf@x=\pgf@pt@aa\pgf@xc%
261 \advance\pgf@x by\pgf@pt@ba\pgf@yc%
262 \advance\pgf@x by\pgf@pt@x%
263 %
264 \pgf@y=\pgf@pt@ab\pgf@xc%
265 \advance\pgf@y by\pgf@pt@bb\pgf@yc%
266 \advance\pgf@y by\pgf@pt@y%
267 %
268 \global\pgf@x=\pgf@x%
269 \global\pgf@y=\pgf@y%
270 \xdef\pgf@tempaa{\pgf@sys@tonumber{\pgf@xa}}%
271 \xdef\pgf@tempab{\pgf@sys@tonumber{\pgf@ya}}%
272 \xdef\pgf@tempba{\pgf@sys@tonumber{\pgf@xb}}%
273 \xdef\pgf@tempbb{\pgf@sys@tonumber{\pgf@yb}}%
274 }%
275 \pgf@pt@x=\pgf@x%
276 \pgf@pt@y=\pgf@y%
277 \let\pgf@pt@aa=\pgf@tempaa%
278 \let\pgf@pt@ba=\pgf@tempba%
279 \let\pgf@pt@ab=\pgf@tempab%
280 \let\pgf@pt@bb=\pgf@tempbb%
281 \edef\pgf@idtest{\pgf@pt@aa,\pgf@pt@ba,\pgf@pt@ab,\pgf@pt@bb}%
282 \ifx\pgf@idtest\pgf@idmatrixtext%
283 \pgf@pt@identitytrue%
284 \else%
285 \pgf@pt@identityfalse%
286 \fi%
287 }
288
289
290
291 % Transformation into a given triangle. The three corners of the
292 % triangle are called "origin", "x" and "y" are given. After this
293 % transformation has been applied, the canvas origin is at "origin",
294 % the vector (1pt,0pt) lies at "x" and the vector (0pt,1pt) lies at
295 % "y".
296 %
297 % #1 = origin
298 % #2 = x
299 % #3 = y
300 %
301 % Example:
302 %
303 % \pgftransformtriangle{\pgfpointorigin}{\pgfpoint{1cm}{1cm}}{\pgfpoint{-1cm}{1cm}}
304
305 \def\pgftransformtriangle#1#2#3{%
306 \pgf@process{#2}%
307 \pgf@xa=\pgf@x%
308 \pgf@ya=\pgf@y%
309 \pgf@process{#3}%
310 \pgf@xb=\pgf@x%
311 \pgf@yb=\pgf@y%
312 \pgf@process{#1}%
313 \advance\pgf@xa by-\pgf@x%
314 \advance\pgf@ya by-\pgf@y%
315 \advance\pgf@xb by-\pgf@x%
316 \advance\pgf@yb by-\pgf@y%
317 \pgftransformcm%
318 {\pgf@sys@tonumber\pgf@xa}{\pgf@sys@tonumber\pgf@ya}%
319 {\pgf@sys@tonumber\pgf@xb}{\pgf@sys@tonumber\pgf@yb}%
320 {\pgfpoint{\pgf@x}{\pgf@y}}%
321 }
322
323
324
325 % Undo all transformations
326 %
327 % Example:
328 %
329 % \pgftansformreset
330
331 \def\pgftransformreset{%
332 \pgf@pt@x=0pt%
333 \pgf@pt@y=0pt%
334 \let\pgf@pt@aa\pgf@one@text%
335 \let\pgf@pt@ba\pgf@zero@text%
336 \let\pgf@pt@ab\pgf@zero@text%
337 \let\pgf@pt@bb\pgf@one@text%
338 \pgf@pt@identitytrue%
339 }
340
341
342 % Undo all slanting/rotation, but not translations
343 %
344 % Example:
345 %
346 % \pgftransformresetnontranslations
347
348 \def\pgftransformresetnontranslations{%
349 \let\pgf@pt@aa\pgf@one@text%
350 \let\pgf@pt@ba\pgf@zero@text%
351 \let\pgf@pt@ab\pgf@zero@text%
352 \let\pgf@pt@bb\pgf@one@text%
353 \pgf@pt@identitytrue%
354 }
355
356
357
358
359 % Shifting command and environment
360 %
361 % #1 = vector by which all subsequent points should be moved.
362 %
363 % Example:
364 %
365 % \pgftansformshift{\pgfpoint{1cm}{1cm}}
366
367 \def\pgftransformshift#1{\pgftransformcm{1}{0}{0}{1}{#1}}
368 \def\pgftransformxshift#1{\pgftransformcm{1}{0}{0}{1}{\pgfpoint{#1}{+0pt}}}
369 \def\pgftransformyshift#1{\pgftransformcm{1}{0}{0}{1}{\pgfpoint{+0pt}{#1}}}
370
371
372
373
374 % Scaling commands
375 %
376 % #1 = scaling for all subsequent points.
377 %
378 % Example:
379 %
380 % \pgftransformscale{2}
381 % \pgftransformxscale{2}
382 % \pgftransformyscale{2}
383
384 \def\pgftransformscale#1{\pgftransformcm{#1}{0}{0}{#1}{\pgfpointorigin}}
385 \def\pgftransformxscale#1{\pgftransformcm{#1}{0}{0}{1.0}{\pgfpointorigin}}
386 \def\pgftransformyscale#1{\pgftransformcm{1.0}{0}{0}{#1}{\pgfpointorigin}}
387
388
389
390 % Slanting commands
391 %
392 % #1 = slanting in x-direction. 1 means 45 degrees.
393 %
394 % Example:
395 %
396 % \pgftransformxslant{2}
397 % \pgftransformyslant{2}
398
399 \def\pgftransformxslant#1{\pgftransformcm{1.0}{0}{#1}{1.0}{\pgfpointorigin}}
400 \def\pgftransformyslant#1{\pgftransformcm{1.0}{#1}{0}{1.0}{\pgfpointorigin}}
401
402
403
404 % Rotation commands
405 %
406 % #1 = degrees for the rotation
407 %
408 % Example:
409 %
410 % \pgftransformrotate{30}
411
412 \def\pgftransformrotate#1{%
413 \pgfmathparse{#1}%
414 \let\pgftransform@angle=\pgfmathresult%
415 \pgfmathsin@{\pgftransform@angle}%
416 \let\pgftransform@sin=\pgfmathresult%
417 \pgfmathcos@{\pgftransform@angle}%
418 \let\pgftransform@cos=\pgfmathresult%
419 \pgf@x=\pgftransform@sin pt%
420 \pgf@xa=-\pgf@x%
421 \pgftransformcm{\pgftransform@cos}{\pgftransform@sin}{\pgf@sys@tonumber{\pgf@xa}}{\pgftransform@cos}{\pgfpointorigin}%
422 }
423
424
425
426 % The following if's have the following effect:
427 %
428 % \ifpgfslopedattime decides whether the coordinate system of an
429 % xxxattime transformation command should be rotated such that text
430 % drawn on the line should be tangent to the line
431 %
432 % \ifpgfallowupsidedowattime decides whether the transformation should
433 % be done in such a way that the text is always ``upright,'' that is,
434 % text drawn in this coordinate system is never upside-down.
435 %
436 % \ifpgfresetnontranslationattime decides whether the coordinate
437 % system of an xxxattime transformation command should be reset
438 % (concerning the non-translations) before a possible rotation is
439 % applied. This is useful, for example, if the main coordinate system
440 % is scaled by, say, a factor of 2 and you do not want that to apply
441 % to the text, but you do want the rotation to apply.
442
443 \newif\ifpgfslopedattime
444 \newif\ifpgfallowupsidedownattime
445 \newif\ifpgfresetnontranslationattime
446
447
448 % Transform to the coordinate system of a point on a line
449 %
450 % #1 = a time fraction of line where to put the label, where 0 means start,
451 % 1 means end, and for example 0.5 means the middle.
452 % #2 = start of line
453 % #3 = end of line
454 %
455 % Example:
456 %
457 % {
458 % \pgftransformlineattime{.5}{\pgfxy(0,0)}{\pgfxy(3,2)}
459 % \pgftext{Hi!}
460 % }
461 %
462 % {
463 % \pgftransformlineattime{.75}{\pgfxy(0,0)}{\pgfxy(3,2)}
464 % \pgftransformresetnontranslations
465 % \pgftext{Hi!}
466 % }
467 %
468 \def\pgftransformlineattime#1#2#3{%
469 \pgf@process{#2}%
470 \pgf@xb=\pgf@x% xb/yb = start point
471 \pgf@yb=\pgf@y%
472 \pgf@process{#3}%
473 \pgf@xc=\pgf@x% xc/yc = end point
474 \pgf@yc=\pgf@y%
475 \pgftransformshift{\pgfpointlineattime{#1}{\pgfqpoint{\pgf@xb}{\pgf@yb}}{\pgfqpoint{\pgf@xc}{\pgf@yc}}}%
476 \ifpgfresetnontranslationattime%
477 \pgftransformresetnontranslations%
478 \fi%
479 \ifpgfslopedattime%
480 \advance\pgf@xc by-\pgf@xb%
481 \advance\pgf@yc by-\pgf@yb%
482 \ifpgfallowupsidedownattime%
483 \else%
484 \ifdim\pgf@xc<0pt%
485 \pgf@xc=-\pgf@xc%
486 \pgf@yc=-\pgf@yc%
487 \fi%
488 \fi%
489 \pgf@x=\pgf@xc%
490 \pgf@y=\pgf@yc%
491 \pgfpointnormalised{}% x/y = normalised vector
492 \pgf@ya=-\pgf@y%
493 \pgftransformcm%
494 {\pgf@sys@tonumber{\pgf@x}}{\pgf@sys@tonumber{\pgf@y}}%
495 {\pgf@sys@tonumber{\pgf@ya}}{\pgf@sys@tonumber{\pgf@x}}{\pgfpointorigin}%
496 \fi%
497 }
498
499
500 % Transform to the coordinate system of a point on an arc
501 %
502 % #1 = a time fraction of line where to put the label, where 0 means start,
503 % 1 means end, and for example 0.5 means the middle.
504 % #2 = center of an ellipse
505 % #3 = 0-degree axis of the ellipse
506 % #4 = 90-degree axis of the ellipse
507 % #4 = start angle of the arc on this ellipse
508 % #5 = end angle of the arc on this ellipse
509 %
510 % Example:
511 %
512 % {
513 % \pgftransformlineattime{.5}{\pgfpoint{1cm}{1cm}}{\pgfpoint{1cm}{0cm}}{\pgfpoint{0cm}{1cm}}{30}{40}
514 % \pgftext{Hi!}
515 % }
516
517 \def\pgftransformarcaxesattime#1#2#3#4#5#6{%
518 \pgfpointarcaxesattime{#1}{#2}{#3}{#4}{#5}{#6}%
519 \pgftransformshift{\pgfqpoint{\pgf@x}{\pgf@y}}%
520 \ifpgfresetnontranslationattime%
521 \pgftransformresetnontranslations%
522 \fi%
523 \ifpgfslopedattime%
524 \pgf@x=\pgf@xa%
525 \pgf@y=\pgf@ya%
526 \pgf@process{\pgfpointnormalised{}}%
527 \ifpgfallowupsidedownattime%
528 \else%
529 \ifdim\pgf@x<0pt%
530 \pgf@x=-\pgf@x%
531 \pgf@y=-\pgf@y%
532 \fi%
533 \fi%
534 \pgf@ya=-\pgf@y%
535 \pgftransformcm%
536 {\pgf@sys@tonumber{\pgf@x}}{\pgf@sys@tonumber{\pgf@y}}%
537 {\pgf@sys@tonumber{\pgf@ya}}{\pgf@sys@tonumber{\pgf@x}}{\pgfpointorigin}%
538 \fi%
539 }
540
541
542
543
544 % Transform to the coordinate system of a point on a curve
545 %
546 % #1 = a time fraction of line where to put the label, where 0 means start,
547 % 1 means end, and for example 0.5 means the middle.
548 % #2 = start of line
549 % #3 = first control
550 % #4 = second control
551 % #5 = end of line
552 %
553 % Example:
554 %
555 % {
556 % \pgftransformcurveattime{.5}{\pgfxy(0,0)}{\pgfxy(3,2)}
557 % \pgftext{Hi!}
558 % }
559 %
560 % {
561 % \pgftransformcurveattime{.75}{\pgfxy(0,0)}{\pgfxy(3,2)}
562 % \pgftransformresetnontranslations
563 % \pgftext{Hi!}
564 % }
565 %
566 \def\pgftransformcurveattime#1#2#3#4#5{%
567 \pgfpointcurveattime{#1}{#2}{#3}{#4}{#5}%
568 \pgftransformshift{\pgfqpoint{\pgf@x}{\pgf@y}}%
569 \ifpgfresetnontranslationattime%
570 \pgftransformresetnontranslations%
571 \fi%
572 \ifpgfslopedattime%
573 \pgf@x=\pgf@xa%
574 \pgf@y=\pgf@ya%
575 \advance\pgf@x by-\pgf@xb%
576 \advance\pgf@y by-\pgf@yb%
577 \ifpgfallowupsidedownattime%
578 \else%
579 \ifdim\pgf@x<0pt%
580 \pgf@x=-\pgf@x%
581 \pgf@y=-\pgf@y%
582 \fi%
583 \fi%
584 \pgfpointnormalised{}% x/y = normalised vector
585 \pgf@ya=-\pgf@y%
586 \pgftransformcm%
587 {\pgf@sys@tonumber{\pgf@x}}{\pgf@sys@tonumber{\pgf@y}}%
588 {\pgf@sys@tonumber{\pgf@ya}}{\pgf@sys@tonumber{\pgf@x}}{\pgfpointorigin}%
589 \fi%
590 }
591
592
593
594
595
596 % Transform to the coordinate system of an arrow at the end of the
597 % line going from point #1 to point #2 with the correct rotation.
598 %
599 % #1 = a start point an (invisible) line
600 % #2 = an end point an (invisible) line
601 %
602 % Example:
603 %
604 % \pgftransformarrow{\pgfpointorigin}{\pgfpoint{1cm}{0cm}}
605
606 \def\pgftransformarrow#1#2{%
607 \pgf@process{#2}%
608 \pgftransformshift{}%
609 \pgf@xa=\pgf@x%
610 \pgf@ya=\pgf@y%
611 \pgf@process{#1}%
612 \advance\pgf@xa by-\pgf@x%
613 \advance\pgf@ya by-\pgf@y%
614 \pgf@x=\pgf@xa%
615 \pgf@y=\pgf@ya%
616 \pgfpointnormalised{}%
617 \pgf@ya=-\pgf@y%
618 \pgftransformcm%
619 {\pgf@sys@tonumber{\pgf@x}}{\pgf@sys@tonumber{\pgf@y}}%
620 {\pgf@sys@tonumber{\pgf@ya}}{\pgf@sys@tonumber{\pgf@x}}{\pgfqpoint{0pt}{0pt}}%
621 }
622
623
624
625
626 % Computes transformations adjustments for the current transformation
627 % matrix
628 %
629 % Description:
630 %
631 % This command is used when you install a transformation matrix that
632 % scales everything by a certain factor, but you still wish to draw
633 % something with "an absolute size". Suppose for instance that you
634 % install a transformation matrix that scales everything by a factor
635 % of 4 and you now wish to draw a horizontal line of length 1cm. Then,
636 % if you do not reset the transformation matrix, you can draw a line
637 % of logical length 2.5mm, which will then get scaled to a line of
638 % 1cm.
639 %
640 % Things get more difficult in case you scale things only, say,
641 % vertically. In this case, the adjustment necessary for horizontal
642 % lines is different from the one needed for vertical lines.
643 %
644 % This function computes the necessary scaling factors and puts them
645 % in the macros \pgfhorizontaltransformationadjustment and
646 % \pgfverticaltransformationadjustment.
647 %
648 % Note that the "right" way to draw a line of absolute length 1cm in a
649 % transformed coordinate system is to first compute the start point
650 % and to then reset the transformation matrix. The transformation
651 % adjustments computed here are important only in situations where you
652 % cannot do this, for instance when an "outer xsep" must be set.
653
654 \def\pgftransformationadjustments{%
655 \ifpgf@pt@identity%
656 \let\pgfhorizontaltransformationadjustment\pgf@one@text%
657 \let\pgfverticaltransformationadjustment\pgf@one@text%
658 \else%
659 {%
660 \pgf@pt@x0pt%
661 \pgf@pt@y0pt%
662 \pgfpointtransformed{\pgfqpoint{1pt}{0pt}}%
663 \pgfmathveclen@{\pgf@sys@tonumber\pgf@x}{\pgf@sys@tonumber\pgf@y}%
664 \pgfmathreciprocal@{\pgfmathresult}%
665 \global\let\pgf@temp@hori\pgfmathresult
666 \pgfpointtransformed{\pgfqpoint{0pt}{1pt}}%
667 \pgfmathveclen@{\pgf@sys@tonumber\pgf@x}{\pgf@sys@tonumber\pgf@y}%
668 \pgfmathreciprocal@{\pgfmathresult}%
669 \global\let\pgf@temp@vert\pgfmathresult
670 \xdef\pgf@marshal@b{\def\noexpand\pgfverticaltransformationadjustment{\pgfmathresult}}
671 }%
672 \let\pgfhorizontaltransformationadjustment\pgf@temp@hori%
673 \let\pgfverticaltransformationadjustment\pgf@temp@vert%
674 \fi%
675 }
676
677 \let\pgfhorizontaltransformationadjustment\pgf@one@text
678 \let\pgfverticaltransformationadjustment\pgf@one@text
679
680
681 % Low-level transformations
682
683 % Causes the current high-level transformation command to be applied
684 % to the low-level.
685 %
686 % Description:
687 %
688 % All subsequent drawing will be transformed additionally by the
689 % current high-level transformation. Thus, the high-level
690 % transformation becomes the low-level transformation. The high-level
691 % transformation is reset at this point.
692
693 \def\pgflowlevelsynccm{%
694 \pgfsys@transformcm%
695 {\pgf@pt@aa}{\pgf@pt@ab}%
696 {\pgf@pt@ba}{\pgf@pt@bb}%
697 {\pgf@pt@x}{\pgf@pt@y}%
698 \pgftransformreset%
699 \pgf@relevantforpicturesizefalse%
700 }
701
702
703
704 % Causes a transformation command to be applied to the ``lowlevel''
705 % transformation matrix.
706 %
707 % #1 - a high-level transformation command
708 %
709 % Description:
710 %
711 % All subsequent drawing will be transformed additionally by the given
712 % transformation matrix. Note that PGF will no longer be able to
713 % ``keep track'' of the coordinates. Also, transformations are applied
714 % to *everything*, including line thickness and line endings. Most
715 % often, this is not desirable.
716 %
717 % Example:
718 %
719 % \pgflowlevel{\pgftransformcm{1}{0}{0}{1}{\pgfpoint{100pt}{0pt}}} % 100bp to the right.
720 %
721 % \begin{pgflowlevelscope}{\pgftransformcm{2}{0}{0}{2}{\pgfpointorigin}} % double in size
722 % \pgfmoveto{\pgfpoint{0cm}{0cm}}
723 % \pgflineto{\pgflineto{1cm}{1cm}} % actually 2cm/2cm
724 % \end{pgflowlevelscope}
725
726 \def\pgflowlevel#1{%
727 {%
728 \pgftransformreset%
729 #1%
730 \pgflowlevelsynccm%
731 }%
732 \pgf@relevantforpicturesizefalse%
733 }
734
735 \def\pgflowlevelscope#1{\pgfscope\pgflowlevel{#1}}
736 \def\endpgflowlevelscope{\endpgfscope}
737
738 \long\def\pgflowlevelobj#1#2{\pgfscope{\pgflowlevel{#1}#2}\endpgfscope}
739
740
741
742 % View boxes
743
744 % Establishes a view box scope
745 %
746 % #1 and #2 = two opposite corners of the source rectangle
747 % #3 and #4 = two opposite corners of the target rectangle
748 % #5 = "meet" or "slice"
749 %
750 % Description:
751 %
752 % Inside the viewbox scope, the source rectangle will be translated
753 % and scaled so that it becomes centered on the target rectangle and
754 % will, for "meet", be as large as possible so that it fits inside the
755 % target and, for "slice", be as small as possible so that it
756 % encompasses the target.
757
758 \def\pgfviewboxscope#1#2#3#4#5{%
759 {% Compute rectangle corners
760 \pgf@process{#1}%
761 \pgf@pos@transform@glob
762 \pgf@xa=\pgf@x%
763 \pgf@ya=\pgf@y%
764 \pgf@process{#2}%
765 \pgf@pos@transform@glob
766 \ifdim\pgf@x<\pgf@xa%
767 \pgf@xb\pgf@x%
768 \pgf@xc\pgf@xa%
769 \else%
770 \pgf@xb\pgf@xa%
771 \pgf@xc\pgf@x%
772 \fi%
773 \ifdim\pgf@y<\pgf@ya%
774 \pgf@yb\pgf@y%
775 \pgf@yc\pgf@ya%
776 \else%
777 \pgf@yb\pgf@ya%
778 \pgf@yc\pgf@y%
779 \fi%
780 \pgf@process{#3}%
781 \pgf@pos@transform@glob
782 \pgf@xa=\pgf@x%
783 \pgf@ya=\pgf@y%
784 \pgf@process{#4}%
785 \pgf@pos@transform@glob
786 \ifdim\pgf@x<\pgf@xa%
787 \else%
788 \pgfutil@tempdima\pgf@x
789 \pgf@x\pgf@xa%
790 \pgf@xa\pgfutil@tempdima%
791 \fi%
792 \ifdim\pgf@y<\pgf@ya%
793 \else%
794 \pgfutil@tempdima\pgf@y
795 \pgf@y\pgf@ya%
796 \pgf@ya\pgfutil@tempdima%
797 \fi%
798 \pgfusetype{.view}%
799 \edef\pgf@marshal{\expandafter\noexpand\csname pgfsys@viewbox#5\endcsname{\the\pgf@x}{\the\pgf@y}{\the\pgf@xa}{\the\pgf@ya}{\the\pgf@xb}{\the\pgf@yb}{\the\pgf@xc}{\the\pgf@yc}}%
800 \pgf@marshal%
801 }%
802 \pgf@relevantforpicturesizefalse%
803 }
804
805 \def\endpgfviewboxscope{\pgfsys@endviewbox}
806
807 \let\startpgfviewboxscope=\pgfviewboxscope
808 \let\stoppgfviewboxscope=\endpgfviewboxscope
809
810 % Forward declarations for nonlinear stuff (have no effect till module
811 % nonlineartransformations is loaded)
812
813 \let\pgfapproximatenonlineartranslation\relax
814 \let\pgfapproximatenonlineartransformation\relax
815 \def\pgftransformnonlinear#1{\pgferror{You need to say
816 \string\usepgfmodule{nonlineartransformations} to use nonlinear transformations}}
817
818
819 \endinput