summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/rulercompass/tikzlibraryrulercompass.code.tex
blob: 76cda67eb098072b31483aba03ff57fc7d99e59f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
%%
%% This is file `tikzlibraryrulercompass.code.tex',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% rulercompass.dtx  (with options: `tikzlibrary')
%% ---------------------------------------------------------------
%% rulercompass --- a TikZ/PGF library for drawing straight-edge
%%                  and compass diagrams
%% E-mail: stacey@math.ntnu.no
%% Released under the LaTeX Project Public Licence v1.3c or later
%% See http://www.latex-project.org/lppl.txt
%% ---------------------------------------------------------------
%% 
\usetikzlibrary{intersections,calc}
\newif\ifrc@draft
\newif\ifrc@beamer
\newif\ifrc@fliparc
\newcount\rc@picture@id
\newcounter{pointlabels}
\@ifclassloaded{beamer}{%
  \rc@beamertrue
}{}
\def\rc@pathsep{@}
\ifrc@beamer
\resetcounteronoverlays{pointlabels}
\resetcountonoverlays{rc@picture@id}
\tikzset{
  alt if exist/.code args={#1#2#3}{%
    \@ifundefined{path@\the\rc@picture@id @#1}{%
      \pgfkeysalso{#2}%
    }{
      \alt<.-\csname path@\the\rc@picture@id @#1\endcsname>{%
        \pgfkeysalso{#2}%
      }{
        \pgfkeysalso{#3}%
      }%
    }%
  },
  intersection/save/.code={%
    \only<.>{%
      \begingroup
      \tikz@intersect@path@names@parse#1\tikz@stop
      \protected@write\pgfutil@auxout{}{%
        \string\global\string\@namedef{path@\the\rc@picture@id @\tikz@intersect@path@a}{\the\beamer@slideinframe}%
        \string\global\string\@namedef{path@\the\rc@picture@id @\tikz@intersect@path@b}{\the\beamer@slideinframe}%
      }%
    \endgroup
    }%
  }
}
\newcommand<>\compass[3][]{%
  \draw#4[#1,ruler compass/compass={#2}{#3}];
}

\newcommand<>\ruler[3][]{%
  \draw#4[#1,ruler compass/ruler={#2}{#3}];
}
\newcommand<>\point[4][]{%
  {%
    \advance\c@pointlabels by 1\relax
    \xdef\rc@temp{\thepointlabels}%
  }%
  \edef\rc@tempa{\the\rc@picture@id}%
  \expandafter\ifx\csname rc@id@\rc@temp\endcsname\rc@tempa
    \path#5 (\rc@temp) node[ruler compass/point,#1] {};
  \else
    \path#5 [name intersections={use=#2 and #3}] (intersection-#4) node[ruler compass/point,#1] {};
  \fi
}
\else
\tikzset{
  alt if exist/.code args={#1#2#3}{%
    \pgfkeysalso{#2}%
  },
  intersection/save/.code={%
    \begingroup
    \tikz@intersect@path@names@parse#1\tikz@stop
    \protected@write\pgfutil@auxout{}{%
        \string\global\string\@namedef{path@\the\rc@picture@id @\tikz@intersect@path@a}{\thepage}%
        \string\global\string\@namedef{path@\the\rc@picture@id @\tikz@intersect@path@b}{\thepage}%
    }%
    \endgroup
  }
}
\newcommand\compass[3][]{%
  \draw [#1,ruler compass/compass={#2}{#3}];
}

\newcommand\ruler[3][]{%
  \draw [#1,ruler compass/ruler={#2}{#3}];
}

\newcommand\point[4][]{%
  \path [name intersections={use=#2 and #3}] (intersection-#4) node[ruler compass/point,#1] {};
}
\fi
\def\rc@processpt#1{%
  \pgfutil@ifnextchar.{\rc@processpt@@#1}{\rc@processpt@#1}}
\def\rc@processpt@#1#2\pgf@stop{%
  \pgfutil@in@+{#2}%
  \ifpgfutil@in@
   \let\@next=\rc@processpt@plus
  \else
   \pgfutil@in@-{#2}%
   \ifpgfutil@in@
    \let\@next=\rc@processpt@minus
   \else
    \let\@next=\rc@processpt@bare
   \fi
  \fi
  \@next#1#2\pgf@stop
}
\def\rc@processpt@@#1.#2\pgf@stop{%
  \def\rc@temp{#2}%
  \ifx\rc@temp\pgfutil@empty
  \edef\rc@temp{\thepointlabels}%
  \else
  \pgfmathparse{int(\the\c@pointlabels + #2)}%
  \begingroup
  \c@pointlabels=\pgfmathresult\relax
  \xdef\rc@temp{\thepointlabels}%
  \endgroup
  \fi
  \let#1\rc@temp
}
\def\rc@processpt@plus#1#2+#3\pgf@stop{%
  \pgfmathsetmacro\rc@temp{0}%
  \rc@reverse#2\pgf@stop%
  \pgfmathparse{int(\rc@temp + #3)}%
  \begingroup
  \c@pointlabels=\pgfmathresult\relax
  \xdef\rc@temp{\thepointlabels}%
  \endgroup
  \let#1\rc@temp
}
\def\rc@processpt@minus#1#2-#3\pgf@stop{%
  \pgfmathsetmacro\rc@temp{0}%
  \rc@reverse#2\pgf@stop%
  \pgfmathparse{int(\rc@temp - #3)}%
  \begingroup
  \c@pointlabels=\pgfmathresult\relax
  \xdef\rc@temp{\thepointlabels}%
  \endgroup
  \let#1\rc@temp
}
\def\rc@processpt@bare#1#2\pgf@stop{%
  \def#1{#2}}
\def\rc@reverse#1{%
  \ifx#1\pgf@stop
    \let\@next=\pgfutil@empty
  \else
    \let\@next=\rc@reverse
    \pgfutil@tempcnta=`#1\relax
    \pgfmathsetmacro\rc@temp{\rc@temp * \rc@factor + \the\pgfutil@tempcnta - \rc@initial}%
  \fi
  \@next}
\def\rc@parsepath#1#2#3#4\pgf@stop{%
  \rc@processpt\rc@tempa#3\pgf@stop
  \rc@processpt\rc@tempb#4\pgf@stop
  \xdef#1{#2\rc@pathsep\rc@tempa\rc@pathsep\rc@tempb}%
}
\tikzset{
  every picture/.append style={
    ruler compass/at begin picture
  },
  intersection/use/.code args={#1 and #2}{%
    \rc@parsepath\rc@pta#1\pgf@stop
    \rc@parsepath\rc@ptb#2\pgf@stop
    \pgfkeysalso{
      of={\rc@pta} and \rc@ptb,
      save={\rc@pta} and \rc@ptb,
    }
  },
  circle through/.style={
    to path={
      \pgfextra{
        \tikz@scan@one@point\pgfutil@firstofone(\tikztostart)\relax
        \pgf@xa=\pgf@x
        \pgf@ya=\pgf@y
        \tikz@scan@one@point\pgfutil@firstofone(\tikztotarget)\relax
        \pgfmathsetmacro\rc@radius{veclen(\pgf@x - \pgf@xa,\pgf@y - \pgf@ya)}%
      }
      circle[radius=\rc@radius pt] (\tikztotarget)
    }
  },
  arc flip/.is if=rc@fliparc,
  centred arc to/.code 2 args={%
    \tikz@scan@one@point\pgfutil@firstofone(#1)\relax
    \pgfmathsetmacro\rc@radius{veclen(\tikz@lastx-\pgf@x,\tikz@lasty-\pgf@y)}%
    \pgfmathsetmacro\rc@sangle{atan2(\tikz@lasty - \pgf@y,\tikz@lastx - \pgf@x)}%
    \pgf@xa=\pgf@x
    \pgf@ya=\pgf@y
    \tikz@scan@one@point\pgfutil@firstofone(#2)\relax
    \pgfmathsetmacro\rc@eangle{atan2(\pgf@y - \pgf@ya,\pgf@x - \pgf@xa)}%
    \pgfmathsetmacro\rc@eangle{\rc@eangle < \rc@sangle ? \rc@eangle +       360 : \rc@eangle}%
    \ifrc@fliparc
    \pgfmathsetmacro\rc@eangle{\rc@eangle - 360}%
    \fi
    \pgfkeysalso{start angle=\rc@sangle, end angle=\rc@eangle, radius=\rc@radius pt}
  },
  ruler compass/.is family,
  ruler compass/.cd,
  draft mode/.is if=rc@draft,
  at begin picture/.style={
    execute at begin picture={
      \global\advance\rc@picture@id by 1\relax
      \setcounter{pointlabels}{0}%
    },
  },
  point labels/.is choice,
  point labels/arabic/.code={%
    \renewcommand\thepointlabels{\@arabic \c@pointlabels}%
    \def\rc@initial{48}%
    \def\rc@factor{10}%
  },
  point labels/alph/.code={%
    \renewcommand\thepointlabels{\@alph \c@pointlabels}%
    \def\rc@initial{96}%
    \def\rc@factor{26}%
  },
  point labels/Alph/.code={%
    \renewcommand\thepointlabels{\@Alph \c@pointlabels}%
    \def\rc@initial{64}%
    \def\rc@factor{26}%
  },
  point labels/alphalph/.code={%
    \@ifundefined{alphalph}{%
      \message{The "alphalph" option only works if the 'alphalph' package has been loaded (using "alph" instead).}%
      \renewcommand\thepointlabels{\@alph \c@pointlabels}%
      \def\rc@initial{96}%
      \def\rc@factor{26}%
    }{%
      \renewcommand\thepointlabels{\alphalph \c@pointlabels}%
      \def\rc@initial{96}%
      \def\rc@factor{26}%
    }%
  },
  point labels/AlphAlph/.code={%
    \@ifundefined{alphalph}{%
      \message{The "AlphAlph" option only works if the 'alphalph' package has been loaded (using "Alph" instead).}%
      \renewcommand\thepointlabels{\@Alph \c@pointlabels}%
      \def\rc@initial{64}%
      \def\rc@factor{26}%
    }{%
      \renewcommand\thepointlabels{\AlphAlph \c@pointlabels}%
      \def\rc@initial{64}%
      \def\rc@factor{26}%
    }%
  },
  construction in use/.style={
    draw=blue
  },
  construction not in use/.style={
    draw=gray!75,
  },
  compass/.code 2 args={%
    \rc@processpt\rc@pta#1\pgf@stop
    \rc@processpt\rc@ptb#2\pgf@stop
    \pgfkeysalso{ruler compass/compass aux={\rc@pta}{\rc@ptb}}%
  },
  compass aux/.style 2 args={
    alt if exist={c\rc@pathsep#1\rc@pathsep#2}{
      ruler compass/construction in use/.try,
    }{
      ruler compass/construction not in use/.try
    },
    name path=c\rc@pathsep#1\rc@pathsep#2,
    ruler compass/every construction path/.try,
    ruler compass/every compass/.try,
    insert path={
      (#1) to[circle through] (#2)
      node[name=c\rc@pathsep#1\rc@pathsep#2\rc@pathsep centre,ruler compass/aux point={#1}] {}
      node[name=c\rc@pathsep#1\rc@pathsep#2\rc@pathsep rim,ruler compass/aux point={#2}] {}
    },
  },
  ruler/.code 2 args={%
    \rc@processpt\rc@pta#1\pgf@stop
    \rc@processpt\rc@ptb#2\pgf@stop
    \pgfkeysalso{ruler compass/ruler aux={\rc@pta}{\rc@ptb}}%
  },
  ruler aux/.style 2 args={
    overlay,
    alt if exist={r\rc@pathsep#1\rc@pathsep#2}{
      ruler compass/construction in use/.try
    }{
      ruler compass/construction not in use/.try
    },
    name path=r\rc@pathsep#1\rc@pathsep#2,
    ruler compass/every construction path/.try,
    ruler compass/every ruler/.try,
    insert path={
      ($(#1)!\pgfkeysvalueof{/tikz/ruler compass/ruler length}!(#2)$) -- ($(#2)!\pgfkeysvalueof{/tikz/ruler compass/ruler length}!(#1)$)
      node[name=r\rc@pathsep#1\rc@pathsep#2\rc@pathsep start,ruler compass/aux point={#1}] {}
      node[name=r\rc@pathsep#1\rc@pathsep#2\rc@pathsep end,ruler compass/aux point={#2}] {}
    },
  },
  ruler length/.initial=20,
  aux point/.style={
    node contents/.try={},
    at={(#1)},
    ruler compass/every aux point/.try
  },
  point/.style={
    ruler compass/name it,
    coordinate,
    node contents/.try={},
    insert path={
      node[
        fill=#1,
        circle,
        minimum width=1mm,
        inner sep=0mm,
        reset label anchor,
        anchor=center,
        node contents/.try={},
        ruler compass/every point/.try,
      ] {}
    }
  },
  name it/.code={%
    \ifx\tikz@fig@name\pgfutil@empty
    \stepcounter{pointlabels}%
    \pgfkeysalso{name=\thepointlabels}%
    \expandafter\xdef\csname rc@id@\thepointlabels\endcsname{\the\rc@picture@id}%
    \ifrc@draft
    \pgfkeysalso{label={[ruler compass/draft label/.try]\thepointlabels}}%
    \fi
    \fi
  },
  point/.default=black,
}
\def\rc@scale{1}
\def\rc@offset{0pt}
\def\jump@setbb#1#2#3{%
  \@ifundefined{jump@#1@maxbb}{%
    \expandafter\gdef\csname jump@#1@maxbb\endcsname{#3}%
  }{%
    \csname jump@#1@maxbb\endcsname
    \pgf@xa=\pgf@x
    \pgf@ya=\pgf@y
    #3
    \pgfmathsetlength\pgf@x{max(\pgf@x,\pgf@xa)}%
    \pgfmathsetlength\pgf@y{max(\pgf@y,\pgf@ya)}%
    \expandafter\xdef\csname jump@#1@maxbb\endcsname{\noexpand\pgfpoint{\the\pgf@x}{\the\pgf@y}}%
  }
  \@ifundefined{jump@#1@minbb}{%
    \expandafter\gdef\csname jump@#1@minbb\endcsname{#2}%
  }{%
    \csname jump@#1@minbb\endcsname
    \pgf@xa=\pgf@x
    \pgf@ya=\pgf@y
    #2
    \pgfmathsetlength\pgf@x{min(\pgf@x,\pgf@xa)}%
    \pgfmathsetlength\pgf@y{min(\pgf@y,\pgf@ya)}%
    \expandafter\xdef\csname jump@#1@minbb\endcsname{\noexpand\pgfpoint{\the\pgf@x}{\the\pgf@y}}%
  }
}
\tikzset{
  stop jumping/.style={
    execute at end picture={%
      \pgfmathsetlength\pgf@xa{\pgf@picminx/\rc@scale}%
      \pgfmathsetlength\pgf@ya{\pgf@picminy/\rc@scale}%
      \pgfmathsetlength\pgf@xb{\pgf@picmaxx/\rc@scale}%
      \pgfmathsetlength\pgf@yb{\pgf@picmaxy/\rc@scale}%
      \immediate\write\pgfutil@auxout{%
        \noexpand\jump@setbb{\the\rc@picture@id}{\noexpand\pgfpoint{\the\pgf@xa}{\the\pgf@ya}}{\noexpand\pgfpoint{\the\pgf@xb}{\the\pgf@yb}}%
      },
      \pgf@x=\pgf@picminx
      \pgf@y=\pgf@picminy
      \csname jump@\the\rc@picture@id @minbb\endcsname
      \pgf@xa=\pgf@x
      \pgf@ya=\pgf@y
      \pgf@x=\pgf@picmaxx
      \pgf@y=\pgf@picmaxy
      \csname jump@\the\rc@picture@id @maxbb\endcsname
      \edef\rc@temp{\noexpand\path (\the\pgf@xa - \rc@offset,\the\pgf@ya - \rc@offset) -- (\the\pgf@x + \rc@offset,\the\pgf@y + \rc@offset);}%
      \rc@temp
    },
  },
  max size/.code 2 args={%
    \pgfutil@ifundefined{jump@\the\rc@picture@id @maxbb}{}{%
      \csname jump@\the\rc@picture@id @maxbb\endcsname
      \pgf@xa=\pgf@x
      \pgf@ya=\pgf@y
      \csname jump@\the\rc@picture@id @minbb\endcsname
      \advance\pgf@xa by -\pgf@x
      \advance\pgf@ya by -\pgf@y
      \advance\pgf@xa by \rc@offset
      \advance\pgf@xa by \rc@offset
      \advance\pgf@ya by \rc@offset
      \advance\pgf@ya by \rc@offset
      \pgfmathsetmacro\rc@xratio{\pgf@xa > #1 ? \pgf@xa/#1 : 1}%
      \pgfmathsetmacro\rc@yratio{\pgf@ya > #2 ? \pgf@ya/#2 : 1}%
      \pgfmathsetmacro\rc@scale{1/max(\rc@xratio,\rc@yratio)}%
      \pgfkeysalso{scale=\rc@scale}%
    }
  },
  enclosing box/offset/.store in=\rc@offset,
  constrain/.style={
    execute at begin picture=\constrain
  }
}
\newcommand\constrain{%
  \pgfutil@ifundefined{jump@\the\rc@picture@id @minbb}{}{%
    \csname jump@\the\rc@picture@id @minbb\endcsname
    \pgfmathsetlength\pgf@xa{\pgf@x-\rc@offset}%
    \pgfmathsetlength\pgf@ya{\pgf@y-\rc@offset}%
    \csname jump@\the\rc@picture@id @maxbb\endcsname
    \pgfmathsetlength\pgf@xb{\pgf@x+\rc@offset}%
    \pgfmathsetlength\pgf@yb{\pgf@y+\rc@offset}%
    \edef\rc@temp{\noexpand\clip (\the\pgf@xa,\the\pgf@ya) rectangle (\the\pgf@xb,\the\pgf@yb);}
    \ifpgf@relevantforpicturesize
      \pgf@relevantforpicturesizefalse
      \rc@temp
      \pgf@relevantforpicturesizetrue
    \else
      \rc@temp
    \fi
  }%
}

\expandafter\def\csname pgf@sh@ns@enclosing box\endcsname{rectangle}
\expandafter\def\csname pgf@sh@np@enclosing box\endcsname{%
  \pgfutil@ifundefined{jump@\the\rc@picture@id @minbb}{%
    \def\southwest{\pgfqpoint{\pgf@picminx}{\pgf@picminy}}%
    \def\northeast{\pgfqpoint{\pgf@picmaxx}{\pgf@picmaxy}}%
}{%
    \csname jump@\the\rc@picture@id @minbb\endcsname
    \pgfmathsetlength\pgf@xa{\pgf@x-\rc@offset}%
    \pgfmathsetlength\pgf@ya{\pgf@y-\rc@offset}%
    \edef\southwest{\noexpand\pgfqpoint{\the\pgf@xa}{\the\pgf@ya}}%
    \csname jump@\the\rc@picture@id @maxbb\endcsname
    \pgfmathsetlength\pgf@xb{\pgf@x+\rc@offset}%
    \pgfmathsetlength\pgf@yb{\pgf@y+\rc@offset}%
    \edef\northeast{\noexpand\pgfqpoint{\the\pgf@xb}{\the\pgf@yb}}%
  }%
}
\expandafter\def\csname pgf@sh@nt@enclosing box\endcsname{{1}{0}{0}{1}{0pt}{0pt}}
\expandafter\def\csname pgf@sh@pi@enclosing box\endcsname{\pgfpictureid}

\tikzset{
  on layer/.code={
    \pgfonlayer{#1}\begingroup
    \aftergroup\endpgfonlayer
    \aftergroup\endgroup
  },
  node on layer/.code={
    \gdef\node@@on@layer{%
      \setbox\tikz@tempbox=\hbox\bgroup\pgfonlayer{#1}\unhbox\tikz@tempbox\endpgfonlayer\egroup}
    \aftergroup\node@on@layer
  },
  reset label anchor/.code={%
    \let\tikz@auto@anchor=\pgfutil@empty
    \def\tikz@anchor{#1}
  },
  reset label anchor/.default=center
}
\def\node@on@layer{\aftergroup\node@@on@layer}
\@ifpackageloaded{alphalph}%
{
  \tikzset{ruler compass/point labels=alphalph}
}
{
  \tikzset{ruler compass/point labels=alph}
}

%% 
%% Copyright (C) 2013 by Andrew Stacey <stacey@math.ntnu.no>
%% 
%% This file may be distributed and/or modified under the conditions
%% of the LaTeX Project Public License, either version 1.3 of this
%% license or (at your option) any later version.
%% The latest version of this license is in:
%% 
%%    http://www.latex-project.org/lppl.txt
%% 
%% and version 1.3 or later is part of all distributions of LaTeX
%% version 2005/12/01 or later.
%% 
%% This work is "maintained" (as per LPPL maintenance status) by
%% Andrew Stacey.
%% 
%% This work consists of the files  rulercompass.dtx
%%                                  rulercompass_doc.tex
%% and the derived files            tikzlibraryrulercompass.code.tex
%%                                  rulercompass.ins
%%                                  rulercompass.pdf
%%                                  rulercompass_doc.pdf
%%                                  README.txt
%% 
%% 
%%
%% End of file `tikzlibraryrulercompass.code.tex'.