summaryrefslogtreecommitdiff
path: root/graphics/pgf/contrib/yquant/tex/yquant-shapes.tex
blob: 0f88ed634506d933645f5d044fef403eb38b6014 (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
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
% To draw the wires, we need to determine border angles. However, pgf's approach for this (giving the border point that lies on a line from the center to a desired probe point) is not suitable for this. Instead, we need to give a point that is projected perpendicularly onto the shape.
\def\pgf@sh@anchorxproj#1{%
   \csgdef{pgf@anchor@\pgf@sm@shape@name @xproj}##1{\pgf@process{##1}#1}%
}%
\def\pgf@sh@inheritanchorxproj[from=#1]{%
   \global\csletcs{pgf@anchor@\pgf@sm@shape@name @xproj}{pgf@anchor@#1@xproj}%
}%
\def\pgf@sh@anchoryproj#1{%
   \csgdef{pgf@anchor@\pgf@sm@shape@name @yproj}##1{\pgf@process{##1}#1}%
}%
\def\pgf@sh@inheritanchoryproj[from=#1]{%
   \global\csletcs{pgf@anchor@\pgf@sm@shape@name @yproj}{pgf@anchor@#1@yproj}%
}%
\patchcmd%
   \pgfdeclareshape%
   {\let\anchorborder=\pgf@sh@anchorborder}%
   {\let\anchorborder=\pgf@sh@anchorborder%
    \let\anchorxproj=\pgf@sh@anchorxproj%
    \let\inheritanchorxproj=\pgf@sh@inheritanchorxproj
    \let\anchoryproj=\pgf@sh@anchoryproj%
    \let\inheritanchoryproj=\pgf@sh@inheritanchoryproj}%
   {}%
   {\PackageError{yquant.sty}%
                 {Failed to patch \string\pgfdeclareshape}%
                 {yquant could not provide a necessary extension to pgf.}}%
% This is mostly a copy of \pgfpointshapeborder, but we do not perform the center-anchor shift.
\def\pgfpointshapexproj#1#2{%
   % Ok, check whether #1 is known!
   \ifcsname pgf@sh@ns@#1\endcsname%
      \pgf@process{%
         \edef\pgfreferencednodename{#1}% for use inside of anchors.
         % MW install special macros
         \csname pgf@sh@ma@#1\endcsname% MW
         % install special coordinates
         \csname pgf@sh@np@#1\endcsname%
         \pgf@process{%
            \pgf@process{\pgfpointtransformed{#2}}%
            \pgfsettransform{\csname pgf@sh@nt@#1\endcsname}%
            \pgftransforminvert%
            \pgf@pos@transform@glob%
            \pgf@xa=\pgf@x%
            \pgf@ya=\pgf@y%
            \csname pgf@anchor@\csname pgf@sh@ns@#1\endcsname @xproj\endcsname{\pgfqpoint{\pgf@xa}{\pgf@ya}}%
            \pgfsettransform{\csname pgf@sh@nt@#1\endcsname}%
            \pgf@pos@transform@glob%
         }%
         % Add inter picture transformation
         \pgf@shape@interpictureshift{#1}%
         % Undo current transformation
         \pgftransforminvert%
         \pgf@pos@transform@glob%
      }%
   \else%
      \pgferror{No shape named #1 is known}%
      \pgfpointorigin%
   \fi%
}%
\def\ifpgfpointshapexproj#1{%
   \pgfutil@ifundefined{pgf@sh@ns@#1}%
      {\pgferror{No shape named #1 is known}}%
      {\ifcsname pgf@anchor@\csname pgf@sh@ns@#1\endcsname @xproj\endcsname}%
}
\let\pgfpointshapeyproj=\pgfpointshapexproj%
\patchcmd%
   \pgfpointshapeyproj%
   {xproj}{yproj}%
   {}{\PackageError{yquant.sty}{Failed to provide \string\pgfpointshapeyproj}{}}%
\def\ifpgfpointshapeyproj#1{%
   \pgfutil@ifundefined{pgf@sh@ns@#1}%
      {\pgferror{No shape named #1 is known}}%
      {\ifcsname pgf@anchor@\csname pgf@sh@ns@#1\endcsname @yproj\endcsname}%
}

% Calculate the intersection of an ellipse centered at the origin with radii #1 and #2 with a horizontal line at position #3. Result goes to \pgf@xa, and it is the right intersection point.
\protected\def\yquant@shape@ellipse@xfromy#1#2#3{%
   \ifdim#3>#2\relax%
      \global\pgf@xa=0pt %
   \else%
      \ifdim-\dimexpr#3\relax>#2\relax%
         \global\pgf@xa=0pt %
      \else%
         \begingroup%
            % Here, we essentially do #1*sqrt(1-(#3/#2)^2)
            \dimen2=#2\relax%
            \dimen3=#3\relax%
            % if we divide by a dimension, it is internally converted to sp, so we divide by its pt-value and again by 65536. Same for multiplication. etex fuses muldiv to 64bit, so we don't get overflows.
            % calculate the sqrt; but \pgfmathsqrt@ expects a real number without dimension suffix. It internally does \expandafter\pgfmath@x#1pt\relax, so just gobble the additional pt.
            % TODO: is there a better way, exploiting perhaps a representation in sp?
            \pgfmathsqrt@{\the\dimexpr1pt-\dimen3*\dimen3/\dimen2*65536/\dimen2\relax%
                          \@gobbletwo}%
            \global\pgf@xa=\pgfmathresult\dimexpr#1\relax%
         \endgroup%
      \fi%
   \fi%
}

\pgfdeclareshape{yquant-text}{%
   \inheritsavedanchors[from=rectangle]%
   \foreach \anc in {center, mid, base, north, south, west, mid west, base west, north west, south west, east, mid east, base east, north east, south east} {%
      \inheritanchor[from=rectangle]{\anc}%
   }%
   \global\cslet{pgf@anchor@yquant-text@circuit}\pgf@anchor@rectangle@center%
   \inheritanchorborder[from=rectangle]%
   \inheritbackgroundpath[from=rectangle]%
   \anchorxproj{%
      \pgf@xa=\pgf@x%
      \pgf@ya=\pgf@y%
      % The origin is at the left baseline of the text, i.e. to the left we have the inner + outer xsep, the the right there's the text + inner + outer xsep.
      \northeast%
      \pgf@xb=.5\pgf@x%
      \southwest%
      \advance \pgf@xb by .5\pgf@x%
      \ifdim\pgf@xa>\pgf@xb%
         % to the right
         \northeast%
      % else we already called \southwest
      \fi%
      \pgf@y=\pgf@ya%
   }%
   \anchoryproj{%
      \pgf@xa=\pgf@x%
      \pgf@ya=\pgf@y%
      % The origin is at the left baseline of the text, i.e. to the top we have the text height + inner + outer ysep, the the bottom there's the text depth + inner + outer ysep.
      \northeast%
      \pgf@yb=.5\pgf@y%
      \southwest%
      \advance \pgf@yb by .5\pgf@y%
      \ifdim\pgf@ya>\pgf@yb%
         % to the top
         \northeast%
      % else we already called \southwest
      \fi%
      \pgf@x=\pgf@xa%
   }
}

\pgfdeclareshape{yquant-rectangle}{%
   % BEGIN_FOLD Saved anchors
   \saveddimen\xradius{%
      \pgfmathsetlength\pgf@x{\pgfkeysvalueof{/tikz/x radius}}%
      \ifdim\wd\pgfnodeparttextbox=0pt %
         \pgf@xa=0pt %
      \else%
         \pgfmathsetlength\pgf@xa{\pgfkeysvalueof{/pgf/inner xsep}}%
      \fi%
      \ifdim\dimexpr.5\wd\pgfnodeparttextbox+\pgf@xa\relax>\pgf@x%
         \pgf@x=\dimexpr.5\wd\pgfnodeparttextbox+\pgf@xa\relax%
      \fi%
   }%
   \saveddimen\yradius{%
      \pgfmathsetlength\pgf@x{\pgfkeysvalueof{/tikz/y radius}}%
      \ifdim\dimexpr\ht\pgfnodeparttextbox+\dp\pgfnodeparttextbox\relax=0pt %
         \pgf@xa=0pt %
      \else%
         \pgfmathsetlength\pgf@xa{\pgfkeysvalueof{/pgf/inner ysep}}%
      \fi%
      \@tempdima=\dimexpr.5\ht\pgfnodeparttextbox+.5\dp\pgfnodeparttextbox+\pgf@xa\relax%
      \ifdim\@tempdima>\pgf@x%
         \pgf@x=\@tempdima%
      \fi%
   }%
   \savedanchor\stext{%
      \pgfqpoint%
         {-.5\wd\pgfnodeparttextbox}%
         {-\dimexpr.5\ht\pgfnodeparttextbox-.5\dp\pgfnodeparttextbox\relax}%
   }%
   % END_FOLD
   % BEGIN_FOLD Operator anchors
   \global\cslet{pgf@anchor@yquant-rectangle@center}\pgfpointorigin%
   \anchor{text}{\stext}%
   \anchor{north}%
          {\pgfqpoint{0pt}%
                     {\yradius}}%
   \anchor{north east}%
          {\pgfqpoint{\xradius}%
                     {\yradius}}%
   \anchor{east}%
          {\pgfqpoint{\xradius}%
                     {0pt}}%
   \anchor{south east}%
          {\pgfqpoint{\xradius}%
                     {-\yradius}}%
   \anchor{south}%
          {\pgfqpoint{0pt}%
                     {-\yradius}}%
   \anchor{south west}%
          {\pgfqpoint{-\xradius}%
                     {-\yradius}}%
   \anchor{west}%
          {\pgfqpoint{-\xradius}% \dimexpr not really necessary...
                     {0pt}}%
   \anchor{north west}%
          {\pgfqpoint{-\xradius}%
                     {\yradius}}%
   \anchorborder{%
      \@tempdima=\pgf@x%
      \@tempdimb=\pgf@y%
      \pgfpointborderrectangle{\pgfqpoint{\@tempdima}{\@tempdimb}}%
                              {\pgfqpoint{\xradius}{\yradius}}%
   }%
   \anchorxproj{%
      \ifdim\pgf@x>0pt %
         % to the right
         \pgf@x=\xradius\relax%
      \else%
         % to the left
         \pgf@x=-\xradius\relax%
      \fi%
   }%
   \anchoryproj{%
      \ifdim\pgf@y>0pt %
         % to the top
         \pgf@y=\yradius\relax%
      \else%
         % to the bottom
         \pgf@y=-\yradius\relax%
      \fi%
   }%
   % END_FOLD
   % BEGIN_FOLD Circuit-related anchors
   \global\csletcs{pgf@anchor@yquant-rectangle@circuit}%
                  {pgf@anchor@yquant-rectangle@center}%
   % END_FOLD
   % BEGIN_FOLD Path
   \backgroundpath{%
      \pgfpathrectanglecorners%
         {\pgfqpoint{-\xradius}{\yradius}}%
         {\pgfqpoint{\xradius}{-\yradius}}%
   }%
   % END_FOLD
}

\pgfdeclareshape{yquant-circle}{%
   \inheritsavedanchors[from=yquant-rectangle]%
   \foreach \anc in {center, north, east, south, west, circuit, text} {%
      \inheritanchor[from=yquant-rectangle]{\anc}%
   }%
   \anchor{north east}%
          {\pgfqpoint{.707107\dimexpr\xradius\relax}%
                     {.707107\dimexpr\yradius\relax}}%
   \anchor{south east}%
          {\pgfqpoint{.707107\dimexpr\xradius\relax}%
                     {-.707107\dimexpr\yradius\relax}}%
   \anchor{south west}%
          {\pgfqpoint{-.707107\dimexpr\xradius\relax}%
                     {-.707107\dimexpr\yradius\relax}}%
   \anchor{north west}%
          {\pgfqpoint{-.707107\dimexpr\xradius\relax}%
                     {.707107\dimexpr\yradius\relax}}%
   \anchorborder{%
      \@tempdima=\pgf@x%
      \@tempdimb=\pgf@y%
      \pgfpointborderellipse{\pgfqpoint{\@tempdima}{\@tempdimb}}%
                            {\pgfqpoint{.707107\dimexpr\xradius\relax}%
                                       {.707107\dimexpr\yradius\relax}}%
   }%
   \anchorxproj{%
      \yquant@shape@ellipse@xfromy\xradius\yradius\pgf@y%
      \ifdim\pgf@x>0pt %
         % to the right
         \pgf@x=\pgf@xa%
      \else%
         % to the left
         \pgf@x=-\pgf@xa%
      \fi%
   }%
   \anchoryproj{%
      \yquant@shape@ellipse@xfromy\yradius\xradius\pgf@x%
      \ifdim\pgf@y>0pt %
         % to the top
         \pgf@y=\pgf@xa%
      \else%
         % to the bottom
         \pgf@y=-\pgf@xa%
      \fi%
   }%
   \foregroundpath{%
      \pgfpathellipse{\pgfpointorigin}%
                     {\pgfqpoint{\xradius}{0pt}}%
                     {\pgfqpoint{0pt}{\yradius}}%
   }%
}

\pgfdeclareshape{yquant-zz}{%
   % Here, the radii have a special meaning, we don't put text into the shape
   \saveddimen\xradius{%
      \pgfmathsetlength\pgf@x{\pgfkeysvalueof{/tikz/x radius}}%
   }%
   \saveddimen\yradius{%
      \pgfmathsetlength\pgf@x{\pgfkeysvalueof{/tikz/y radius}}%
   }%
   \foreach \anc in {center, north, east, south, west, circuit} {%
      \inheritanchor[from=yquant-circle]{\anc}%
   }%
   \anchor{north east}%
          {\pgfqpoint{.707107\dimexpr\xradius\relax}%
                     {\dimexpr\yradius-.292893\dimexpr\xradius\relax\relax}}%
   \anchor{south east}%
          {\pgfqpoint{.707107\dimexpr\xradius\relax}%
                     {\dimexpr-\yradius+.292893\dimexpr\xradius\relax\relax}}%
   \anchor{south west}%
          {\pgfqpoint{-.707107\dimexpr\xradius\relax}%
                     {\dimexpr-\yradius+.292893\dimexpr\xradius\relax\relax}}%
   \anchor{north west}%
          {\pgfqpoint{-.707107\dimexpr\xradius\relax}%
                     {\dimexpr\yradius-.292893\dimexpr\xradius\relax\relax}}%
   % TODO: this is not really the correct border anchor
   \inheritanchorborder[from=yquant-rectangle]%
   \anchorxproj{%
      \ifdim\pgf@y<0pt %
         \pgf@ya=\dimexpr\pgf@y+\yradius-\xradius\relax%
      \else%
         \pgf@ya=\dimexpr\pgf@y-\yradius+\xradius\relax%
      \fi%
      \yquant@shape@ellipse@xfromy\xradius\xradius\pgf@ya%
      \ifdim\pgf@x>0pt %
         % to the right
         \pgf@x=\pgf@xa%
      \else%
         % to the left
         \pgf@x=-\pgf@xa%
      \fi%
   }%
   \anchoryproj{%
      \yquant@shape@ellipse@xfromy\xradius\xradius\pgf@xa%
      \ifdim\pgf@y>0pt %
         % to the top
         \pgf@y=\dimexpr\yradius-\xradius+\pgf@xa\relax%
      \else%
         % to the bottom
         \pgf@y=-\dimexpr\yradius-\xradius+\pgf@xa\relax%
      \fi%
   }%
   \backgroundpath{%
      \pgfpathmoveto{\pgfqpoint{0pt}{\dimexpr\yradius-2\dimexpr\xradius\relax\relax}}%
      \pgfpathlineto{\pgfqpoint{0pt}{-\dimexpr\yradius-2\dimexpr\xradius\relax\relax}}%
      \pgfpathcircle{\pgfqpoint{0pt}{\dimexpr\yradius-\xradius\relax}}%
                    {\xradius}%
      \pgfpathcircle{\pgfqpoint{0pt}{\dimexpr\xradius-\yradius\relax}}%
                    {\xradius}%
   }%
}

\pgfdeclareshape{yquant-xx}{%
   \inheritsavedanchors[from=yquant-zz]%
   \savedmacro\ifconnector{%
      \let\ifconnector=\ifyquant@config@multi@line%
   }%
   \foreach \anc in {center, north, north east, east, south east, south, south west, west, north west, circuit} {%
      \inheritanchor[from=yquant-rectangle]{\anc}%
   }%
   % TODO: this is not really the correct border anchor
   \inheritanchorborder[from=yquant-rectangle]%
   \inheritanchorxproj[from=yquant-rectangle]%
   \inheritanchoryproj[from=yquant-rectangle]%
   % Draw the operator itself
   \backgroundpath{%
      \ifconnector%
         \pgfpathmoveto{\pgfqpoint{0pt}{\dimexpr\yradius-2\dimexpr\xradius\relax\relax}}%
         \pgfpathlineto{\pgfqpoint{0pt}{-\dimexpr\yradius-2\dimexpr\xradius\relax\relax}}%
      \fi%
      \pgfpathrectanglecorners%
         {\pgfqpoint{-\xradius}{\dimexpr\yradius\relax}}%
         {\pgfqpoint{\xradius}{\dimexpr\yradius-2\dimexpr\xradius\relax\relax}}%
      \pgfpathrectanglecorners%
         {\pgfqpoint{-\xradius}{-\yradius}}%
         {\pgfqpoint{\xradius}{-\dimexpr\yradius-2\dimexpr\xradius\relax\relax}}%
   }%
}

\pgfdeclareshape{yquant-slash}{%
   \inheritsavedanchors[from=yquant-zz]%
   \foreach \anc in {center, north, north east, east, south east, south, south west, west, north west, circuit} {%
      \inheritanchor[from=yquant-rectangle]{\anc}%
   }%
   \inheritanchorborder[from=yquant-rectangle]%
   \backgroundpath{%
      \pgfpathmoveto{\pgfqpoint{\xradius}{\yradius}}%
      \pgfpathlineto{\pgfqpoint{-\xradius}{-\yradius}}%
   }%
}

\pgfdeclareshape{yquant-swap}{%
   \inheritsavedanchors[from=yquant-xx]%
   \foreach \anc in {center, north, north east, east, south east, south, south west, west, north west, circuit} {%
      \inheritanchor[from=yquant-rectangle]{\anc}%
   }%
   \inheritanchorborder[from=yquant-rectangle]%
   \inheritanchoryproj[from=yquant-rectangle]%
   \backgroundpath{%
      % Connector
      \ifconnector%
         \pgfpathmoveto{\pgfqpoint{0pt}{\dimexpr\yradius-\xradius\relax}}%
         \pgfpathlineto{\pgfqpoint{0pt}{-\dimexpr\yradius-\xradius\relax}}%
      \fi%
      % Upper cross
      \pgfpathmoveto{\pgfqpoint{-\xradius}{\yradius}}%
      \pgfpathlineto{\pgfqpoint{\xradius}%
                               {\dimexpr\yradius-2\dimexpr\xradius\relax\relax}}%
      \pgfpathmoveto{\pgfqpoint{\xradius}{\yradius}}%
      \pgfpathlineto{\pgfqpoint{-\xradius}
                               {\dimexpr\yradius-2\dimexpr\xradius\relax\relax}}%
      % Lower cross
      \pgfpathmoveto{\pgfqpoint{-\xradius}%
                               {-\dimexpr\yradius-2\dimexpr\xradius\relax\relax}}%
      \pgfpathlineto{\pgfqpoint{\xradius}{-\yradius}}%
      \pgfpathmoveto{\pgfqpoint{\xradius}%
                               {-\dimexpr\yradius-2\dimexpr\xradius\relax\relax}}%
      \pgfpathlineto{\pgfqpoint{-\xradius}{-\yradius}}%
   }%
}

\pgfdeclareshape{yquant-oplus}{%
   \inheritsavedanchors[from=yquant-zz]%
   \foreach \anc in {center, north, north east, east, south east, south, south west, west, north west, circuit} {%
      \inheritanchor[from=yquant-circle]{\anc}%
   }%
   \inheritanchorborder[from=yquant-circle]%
   \inheritanchorxproj[from=yquant-circle]%
   \inheritanchoryproj[from=yquant-circle]%
   \backgroundpath{%
      \pgfpathmoveto{\pgfqpoint{0pt}{\yradius}}%
      \pgfpathlineto{\pgfqpoint{0pt}{-\yradius}}%
      \pgfpathmoveto{\pgfqpoint{-\xradius}{0pt}}%
      \pgfpathlineto{\pgfqpoint{\xradius}{0pt}}%
      \pgfpathellipse{\pgfpointorigin}%
                     {\pgfqpoint{\xradius}{0pt}}%
                     {\pgfqpoint{0pt}{\yradius}}%
   }%
}

\pgfdeclareshape{yquant-measure}{%
   \saveddimen\xradius{%
      \pgfmathsetlength\pgf@x{\pgfkeysvalueof{/tikz/x radius}}%
      \ifdim.5\wd\pgfnodeparttextbox>\pgf@x%
         \pgf@x=.5\wd\pgfnodeparttextbox%
      \fi%
   }%
   \saveddimen\yradius{%
      \pgfmathsetlength\pgf@x{\pgfkeysvalueof{/tikz/y radius}}%
      \ifdim\dimexpr\ht\pgfnodeparttextbox+\dp\pgfnodeparttextbox\relax=0pt %
         \ifdim\pgf@x<1.25mm %
            \pgf@x=1.25mm %
         \fi%
      \else%
         % We need the 2.3mm for the meter sign, the height of the text plus a minimum separation of 2pt
         \pgf@y=.5\dimexpr\ht\pgfnodeparttextbox+\dp\pgfnodeparttextbox+2.3mm+4pt\relax%
         \ifdim\pgf@x<\pgf@y%
            \pgf@x=\pgf@y%
         \fi%
      \fi%
   }%
   \savedanchor\stext{%
      \pgfqpoint%
         {-.5\wd\pgfnodeparttextbox}%
         {\dp\pgfnodeparttextbox}%
   }%
   \saveddimen\textheight{%
      \pgf@x=\ht\pgfnodeparttextbox%
   }
   \foreach \anc in {center, north, north east, east, south east, south, south west, west, north west, circuit} {%
      \inheritanchor[from=yquant-rectangle]{\anc}%
   }%
   \anchor{text}{%
      \stext%
      \pgf@y=\dimexpr-\yradius+1pt+\pgf@y\relax%
   }%
   \inheritanchorborder[from=yquant-rectangle]%
   \inheritanchorxproj[from=yquant-rectangle]%
   \inheritanchoryproj[from=yquant-rectangle]%
   \backgroundpath{%
      \pgfpathrectanglecorners%
         {\pgfqpoint{-\xradius}{\yradius}}%
         {\pgfqpoint{\xradius}{-\yradius}}%
   }
   \beforebackgroundpath{%
      % Make sure the meter does not extend beyond the box (we are in a scope here)
      \path [clip]
         (-\xradius, \yradius) rectangle (\xradius, -\yradius);%
      % The position of the meter symbol depends on the presence of the text. If there is no text, we just vertically center. If there is some text, we shift the symbol upwards from the text until there is no overlap any more.
      \csname pgf@anchor@yquant-measure@text\endcsname%
      \advance\pgf@y by \textheight\relax%
      \ifdim\pgf@y<-1.15mm %
         \@tempdima=-1.15mm %
      \else%
         \@tempdima=\dimexpr\pgf@y+2pt\relax%
      \fi%
      \path [/yquant/operators/every measure meter]
         (-2.25mm, \@tempdima) arc[start angle=160, end angle=20,%
                                   x radius=2.25mm, y radius=1.4mm]
         (0, \@tempdima) -- ++(1.6mm, 2.3mm);
   }%
}

\pgfdeclareshape{yquant-dmeter}{%
   \saveddimen\xradius{%
      \pgfmathsetlength\pgf@x{\pgfkeysvalueof{/tikz/x radius}}%
      \ifdim\wd\pgfnodeparttextbox=0pt %
         \pgf@xa=0pt %
      \else%
         \pgfmathsetlength\pgf@xa{\pgfkeysvalueof{/pgf/inner xsep}+.5mm}%
      \fi%
      \ifdim\dimexpr.5\wd\pgfnodeparttextbox+\pgf@xa\relax>\pgf@x%
         \pgf@x=\dimexpr.5\wd\pgfnodeparttextbox+\pgf@xa\relax%
      \fi%
   }%
   \saveddimen\yradius{%
      \pgfmathsetlength\pgf@x{\pgfkeysvalueof{/tikz/y radius}}%
      \ifdim\dimexpr\ht\pgfnodeparttextbox+\dp\pgfnodeparttextbox\relax=0pt %
         \pgf@xa=0pt %
      \else%
         \pgfmathsetlength\pgf@xa{\pgfkeysvalueof{/pgf/inner ysep}}%
      \fi%
      \@tempdima=\dimexpr.5\ht\pgfnodeparttextbox+.5\dp\pgfnodeparttextbox+\pgf@xa\relax%
      \ifdim\@tempdima>\pgf@x%
         \pgf@x=\@tempdima%
      \fi%
   }%
   \savedanchor\stext{%
      \pgfqpoint%
         {-\dimexpr.5\wd\pgfnodeparttextbox+1mm\relax}%
         {-\dimexpr.5\ht\pgfnodeparttextbox-.5\dp\pgfnodeparttextbox\relax}%
   }%
   \foreach \anc in {center, north, south, south west, west, north west, circuit, text} {%
      \inheritanchor[from=yquant-rectangle]{\anc}%
   }%
   \foreach \anc in {north east, east, south east} {%
      \inheritanchor[from=yquant-circle]{\anc}%
   }%
%   \anchor{text}{%
%      \stext%
%      \pgf@x=-.5\dimexpr\xradius-\pgf@x\relax%
%   }%
   \anchorborder{%
      \@tempdima=\pgf@x%
      \@tempdimb=\pgf@y%
      \ifdim\pgf@x>\dimexpr\xradius-3mm\relax%
         \pgfpointborderellipse{\pgfqpoint{\dimexpr\@tempdima-\xradius+3mm\relax}%
                                          {\@tempdimb}}%
                               {\pgfqpoint{3mm}%
                                          {.707107\dimexpr\yradius\relax}}%
         \advance\pgf@x by \dimexpr\xradius-3mm\relax%
      \else%
         \pgfpointborderrectangle{\pgfqpoint{\@tempdima}{\@tempdimb}}%
                                 {\pgfqpoint{\xradius}{\yradius}}%
      \fi%
   }%
   \anchorxproj{%
      \ifdim\pgf@x>\dimexpr\xradius-3mm\relax%
         % to the right
         \advance\pgf@x by -\dimexpr\xradius-3mm\relax%
         \yquant@shape@ellipse@xfromy{3mm}\yradius\pgf@y%
         \pgf@x=\dimexpr\pgf@xa+\xradius-3mm\relax%
      \else%
         % to the left
         \pgf@x=-\xradius\relax%
      \fi%
   }%
   \anchoryproj{%
      \ifdim\pgf@x>\dimexpr\xradius-3mm\relax%
         % to the right
         \advance\pgf@x by -\dimexpr\xradius-3mm\relax%
         \yquant@shape@ellipse@xfromy\yradius{3mm}\pgf@x%
         \advance\pgf@x by \dimexpr\xradius-3mm\relax%
         \ifdim\pgf@y>0pt %
            % to the top
            \pgf@y=\pgf@xa%
         \else%
            % to the bottom
            \pgf@y=-\pgf@xa%
         \fi%
      \else%
         % to the left
         \ifdim\pgf@y>0pt %
            % to the top
            \pgf@y=\yradius\relax%
         \else%
            \pgf@y=-\yradius\relax%
         \fi%
      \fi%
   }%
   \backgroundpath{%
      \pgfpathmoveto{\pgfqpoint{-\xradius}{\yradius}}%
      \pgfpathlineto{\pgfqpoint{\dimexpr\xradius-3mm\relax}{\yradius}}%
      \pgfpatharc{90}{-90}{3mm and \yradius}%
      \pgfpathlineto{\pgfqpoint{-\xradius}{-\yradius}}%
      \pgfpathclose%
   }%
}

\pgfdeclareshape{yquant-barrier}{%
   % Here, the radii have a special meaning, we don't put text into the shape
   \saveddimen\xradius{%
      \pgf@x=.5\pgflinewidth%
   }%
   \savedanchor\shorten{%
      \pgfqpoint\pgf@shorten@end@additional\pgf@shorten@start@additional%
   }%
   \saveddimen\yradius{%
      \pgfmathsetlength\pgf@x{\pgfkeysvalueof{/tikz/y radius}+.5*\yquant@config@register@sep}%
   }%
   \foreach \anc in {center, north, north east, east, south east, south, south west, west, north west, circuit} {%
      \inheritanchor[from=yquant-rectangle]{\anc}%
   }%
   \inheritanchorborder[from=yquant-rectangle]%
   \backgroundpath{%
      \pgfsetlinewidth{\xradius}%
      \shorten%
      \pgf@xa=\dimexpr\yradius+\pgf@x\relax%
      \pgf@ya=\dimexpr\yradius+\pgf@y\relax%
      \pgfpathmoveto{\pgfqpoint{0pt}{\pgf@xa}}%
      \pgfpathlineto{\pgfqpoint{0pt}{-\pgf@ya}}%
   }%
}