Debian Codegraph @

texmf-dist/tex/generic/pgf/libraries/shapes/circuits/pgflibraryshapes.gates.logic.US.code.tex

raw
1 % Copyright 2018 by Mark Wibrow
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 \usepgflibrary{shapes.gates.logic}%
11
12
13 \newif\ifpgfgateanchorsuseboundingrectangle%
14
15
16 % Keys for US/CDH logic gates.
17 %
18 \pgfkeys{
19 /pgf/logic gate anchors use bounding box/.is if=pgfgateanchorsuseboundingrectangle,%
20 }%
21
22 % An internal macro for calculating internal dimensions of
23 % the US + CDH gates (excluding and gate US and nand gate US).
24 %
25 \def\pgf@lib@sh@logicgates@dimensions@orUS{%
26 \pgfmathsetlength\pgf@x{\pgfkeysvalueof{/pgf/inner xsep}}%
27 \advance\[email protected]\wd\pgfnodeparttextbox%
28 \pgfmathsetlength\pgf@y{\pgfkeysvalueof{/pgf/inner ysep}}%
29 \advance\[email protected]\ht\pgfnodeparttextbox%
30 \advance\[email protected]\dp\pgfnodeparttextbox%
31 %
32 % Adjust the height for the number of inputs.
33 %
34 \c@pgf@counta\pgf@lib@sh@logicgate@numinputs%
35 \advance\c@pgf@counta1\relax%
36 \pgfmathsetlength\pgf@ya{\pgfkeysvalueof{/pgf/logic gate inverted radius}}%
37 \advance\pgf@ya\pgflinewidth%
38 \pgfmathsetlength\pgf@yb{\pgfkeysvalueof{/pgf/logic gate input sep}}%
39 \[email protected]\pgf@yb%
40 \ifdim\pgf@ya<\pgf@yb%
41 \pgf@ya\pgf@yb%
42 \fi%
43 \multiply\pgf@ya\c@pgf@counta%
44 \ifdim\pgf@y<\pgf@ya%
45 \pgf@y\pgf@ya%
46 \fi%
47 %
48 \ifdim\pgf@x>\pgf@y%
49 \pgf@y\pgf@x%
50 \else%
51 \pgf@x\pgf@y%
52 \fi%
53 %
54 % Adjust for minimum height and width.
55 %
56 \pgfmathsetlength\pgf@xa{\pgfkeysvalueof{/pgf/minimum width}}%
57 \pgfmathsetlength\pgf@ya{\pgfkeysvalueof{/pgf/minimum height}}%
58 \ifdim\pgf@y<.5\pgf@ya%
59 \[email protected]\pgf@ya%
60 \fi%
61 \pgf@xb\pgf@x%
62 \advance\[email protected]\pgf@y% 2y*cos(30)
63 \ifdim\pgf@xb<\pgf@xa%
64 \pgf@xb\pgf@xa%
65 \[email protected]\pgf@xb% xb / (1 + 2*cos(30))
66 \fi%
67 %
68 \ifdim\pgf@x>\pgf@y%
69 \pgf@y\pgf@x%
70 \else%
71 \pgf@x\pgf@y%
72 \fi%
73 \edef\halfside{\the\pgf@x}%
74 \addtosavedmacro\halfside%
75 %
76 % Take into account the outer sep.
77 %
78 \pgfmathsetlength\pgf@xa{\pgfkeysvalueof{/pgf/outer xsep}}%
79 \pgfmathsetlength\pgf@ya{\pgfkeysvalueof{/pgf/outer ysep}}%
80 \edef\outerxsep{\the\pgf@xa}%
81 \edef\outerysep{\the\pgf@ya}%
82 \addtosavedmacro\outerxsep%
83 \addtosavedmacro\outerysep%
84 \advance\pgf@x\pgf@xa%
85 \advance\pgf@y\pgf@ya%
86 %
87 \edef\halfwidth{\the\pgf@x}%
88 \edef\halfheight{\the\pgf@y}%
89 \addtosavedmacro\halfwidth%
90 \addtosavedmacro\halfheight%
91 %
92 \pgfextract@process\tipanchor{%
93 \advance\pgf@x-\pgf@xa%
94 \advance\pgf@y-\pgf@ya%
95 \[email protected]\pgf@x%
96 \[email protected]\pgf@y%
97 \advance\[email protected]\pgf@yb%
98 \advance\[email protected]\pgf@xa%
99 \pgf@y0pt%
100 }%
101 \addtosavedmacro\tipanchor%
102 }%
103
104
105 % An internal macro for calculating internal dimensions of
106 % the and gate US and nand gate US.
107 %
108 \def\pgf@lib@sh@logicgates@dimensions@andUS{%
109 \pgfmathsetlength\pgf@x{\pgfkeysvalueof{/pgf/inner xsep}}%
110 \advance\[email protected]\wd\pgfnodeparttextbox%
111 \pgfmathsetlength\pgf@y{\pgfkeysvalueof{/pgf/inner ysep}}%
112 \advance\[email protected]\ht\pgfnodeparttextbox%
113 \advance\[email protected]\dp\pgfnodeparttextbox%
114 %
115 % Adjust the height for the number of inputs.
116 %
117 \c@pgf@counta\pgf@lib@sh@logicgate@numinputs%
118 \advance\c@pgf@counta1\relax%
119 \pgfmathsetlength\pgf@ya{\pgfkeysvalueof{/pgf/logic gate inverted radius}}%
120 \advance\pgf@ya\pgflinewidth%
121 \pgfmathsetlength\pgf@yb{\pgfkeysvalueof{/pgf/logic gate input sep}}%
122 \[email protected]\pgf@yb%
123 \ifdim\pgf@ya<\pgf@yb%
124 \pgf@ya\pgf@yb%
125 \fi%
126 \multiply\pgf@ya\c@pgf@counta%
127 \ifdim\pgf@y<\pgf@ya%
128 \pgf@y\pgf@ya%
129 \fi%
130 %
131 \ifdim\pgf@x>\pgf@y%
132 \pgf@y\pgf@x%
133 \else%
134 \pgf@x\pgf@y%
135 \fi%
136 %
137 % Adjust for minimum height and width.
138 %
139 \pgfmathsetlength\pgf@xa{\pgfkeysvalueof{/pgf/minimum width}}%
140 \pgfmathsetlength\pgf@ya{\pgfkeysvalueof{/pgf/minimum height}}%
141 \ifdim\pgf@y<.5\pgf@ya%
142 \[email protected]\pgf@ya%
143 \fi%
144 \[email protected]\pgf@x%
145 \ifdim\pgf@xb<\pgf@xa%
146 \pgf@xb\pgf@xa%
147 \[email protected]\pgf@xb%
148 \fi%
149 %
150 \ifdim\pgf@x>\pgf@y%
151 \pgf@y\pgf@x%
152 \else%
153 \pgf@x\pgf@y%
154 \fi%
155 \edef\halfside{\the\pgf@x}%
156 \addtosavedmacro\halfside%
157 %
158 % Take into account the outer sep.
159 %
160 \pgfmathsetlength\pgf@xa{\pgfkeysvalueof{/pgf/outer xsep}}%
161 \pgfmathsetlength\pgf@ya{\pgfkeysvalueof{/pgf/outer ysep}}%
162 \edef\outerxsep{\the\pgf@xa}%
163 \edef\outerysep{\the\pgf@ya}%
164 \addtosavedmacro\outerxsep%
165 \addtosavedmacro\outerysep%
166 \advance\pgf@x\pgf@xa%
167 \advance\pgf@y\pgf@ya%
168 %
169 \edef\halfwidth{\the\pgf@x}%
170 \edef\halfheight{\the\pgf@y}%
171 \addtosavedmacro\halfwidth%
172 \addtosavedmacro\halfheight%
173 %
174 }%
175
176
177 % Internal macro for calculation input anchors. Used by
178 % both and gates and nand gates, and also the not gate and buffer.
179 %
180 \def\pgf@lib@sh@logicgate@AND@inputanchor#1{%
181 \dimensions%
182 \centerpoint%
183 \pgf@xa\halfside%
184 \advance\[email protected]\pgf@xa%
185 \advance\pgf@x-\halfwidth%
186 \expandafter\ifx\expandafter\pgf@lib@sh@itext\csname input-#1\endcsname%
187 \advance\pgf@x-\invertedradius%
188 \advance\pgf@x-\outerinvertedradius%
189 \fi%
190 %
191 \pgfutil@tempdima\halfside%
192 \multiply\pgfutil@tempdima2\relax%
193 \c@pgf@counta\numinputs%
194 \advance\c@pgf@counta1\relax%
195 \divide\pgfutil@tempdima\c@pgf@counta%
196 \multiply\pgfutil@tempdima#1\relax%
197 \advance\pgf@y\halfside%
198 \advance\pgf@y-\pgfutil@tempdima%
199 }%
200
201
202
203
204 % Shape and gate US
205 %
206 \pgfdeclareshape{and gate US}{%
207 \expandafter\pgfutil@g@addto@macro\csname pgf@sh@s@and gate US\endcsname{%
208 \pgf@lib@sh@logicgate@parseinputs{1024}% Maximum 1024 (!) inputs.
209 %
210 \pgfmathloop%
211 \ifnum\pgfmathcounter>\pgf@lib@sh@logicgate@numinputs%
212 \else%
213 \pgfutil@ifundefined{pgf@anchor@and gate US@input \pgfmathcounter}{%
214 \expandafter\xdef\csname pgf@anchor@and gate US@input \pgfmathcounter\endcsname{%
215 \noexpand\pgf@lib@sh@logicgate@AND@inputanchor{\pgfmathcounter}%
216 }%
217 }{}%
218 \repeatpgfmathloop%
219 \ifnum\pgf@lib@sh@logicgate@numinputs<2\relax%
220 \pgferror{An and gate must have at least two inputs}%
221 \fi%
222 }%
223 \savedmacro\numinputs{\let\numinputs\pgf@lib@sh@logicgate@numinputs}%
224 \saveddimen\invertedradius{%
225 \pgfmathsetlength\pgf@x{\pgfkeysvalueof{/pgf/logic gate inverted radius}}%
226 }%
227 \saveddimen\outerinvertedradius{%
228 \pgfmathsetlength\pgf@x{\pgfkeysvalueof{/pgf/logic gate inverted radius}}%
229 \advance\[email protected]\pgflinewidth%
230 }%
231 \savedmacro\dimensions{\pgf@lib@sh@logicgates@dimensions@andUS}%
232 \savedanchor\centerpoint{%
233 \[email protected]\wd\pgfnodeparttextbox%
234 \[email protected]\ht\pgfnodeparttextbox%
235 \advance\[email protected]\dp\pgfnodeparttextbox%
236 }%
237 \savedanchor\midpoint{%
238 \[email protected]\wd\pgfnodeparttextbox%
239 \pgfmathsetlength\pgf@y{+0.5ex}%
240 }%
241 \savedanchor\basepoint{%
242 \[email protected]\wd\pgfnodeparttextbox%
243 \pgf@y0pt%
244 }%
245 \anchor{center}{\centerpoint}%
246 \anchor{mid}{\midpoint}%
247 \anchor{mid east}{%
248 \csname pgf@anchor@and gate US@east\endcsname%
249 \pgf@xa\pgf@x%
250 \midpoint%
251 \pgf@x\pgf@xa}%
252 \anchor{mid west}{%
253 \csname pgf@anchor@and gate US@west\endcsname%
254 \pgf@xa\pgf@x%
255 \midpoint%
256 \pgf@x\pgf@xa}%
257 \anchor{base}{\basepoint}%
258 \anchor{base east}{%
259 \csname pgf@anchor@and gate US@east\endcsname%
260 \pgf@xa\pgf@x%
261 \basepoint%
262 \pgf@x\pgf@xa}%
263 \anchor{base west}{%
264 \csname pgf@anchor@and gate US@west\endcsname%
265 \pgf@xa\pgf@x%
266 \basepoint%
267 \pgf@x\pgf@xa}%
268 \anchor{east}{%
269 \dimensions%
270 \pgf@xa\halfwidth%
271 \pgf@xb\pgf@xa%
272 \advance\pgf@xb-\outerxsep%
273 \centerpoint%
274 \advance\[email protected]\pgf@xb%
275 \advance\pgf@x\pgf@xa%
276 }%
277 \anchor{output}{\csname pgf@anchor@and gate US@east\endcsname}%
278 \anchor{north east}{%
279 \dimensions%
280 \ifpgfgateanchorsuseboundingrectangle%
281 \csname pgf@anchor@nand gate US@east\endcsname%
282 \advance\pgf@y\halfheight%
283 \else
284 \pgf@xa\halfwidth%
285 \pgf@ya\halfheight%
286 \pgf@xb\pgf@xa%
287 \advance\pgf@xb-\outerxsep%
288 \centerpoint%
289 \advance\[email protected]\pgf@xb%
290 \advance\[email protected]\pgf@xa%
291 \advance\[email protected]\pgf@ya%
292 \fi%
293 }%
294 \anchor{south east}{%
295 \dimensions%
296 \ifpgfgateanchorsuseboundingrectangle%
297 \csname pgf@anchor@nand gate US@east\endcsname%
298 \advance\pgf@y-\halfheight%
299 \else
300 \pgf@xa\halfwidth%
301 \pgf@ya\halfheight%
302 \pgf@xb\pgf@xa%
303 \advance\pgf@xb-\outerxsep%
304 \centerpoint%
305 \advance\[email protected]\pgf@xb%
306 \advance\[email protected]\pgf@xa%
307 \advance\[email protected]\pgf@ya%
308 \fi%
309 }%
310 \anchor{north}{%
311 \dimensions%
312 \centerpoint%
313 \advance\pgf@y\halfheight%
314 }%
315 \anchor{south}{%
316 \dimensions%
317 \centerpoint%
318 \advance\pgf@y-\halfheight%
319 }%
320 \anchor{south west}{%
321 \dimensions%
322 \centerpoint%
323 \pgf@xa\halfside%
324 \advance\[email protected]\pgf@xa%
325 \advance\pgf@x-\outerxsep%
326 \advance\pgf@y-\halfheight%
327 }%
328 \anchor{north west}{%
329 \dimensions%
330 \centerpoint%
331 \pgf@xa\halfside%
332 \advance\[email protected]\pgf@xa%
333 \advance\pgf@x-\outerxsep%
334 \advance\pgf@y\halfheight%
335 }%
336 \anchor{west}{%
337 \dimensions%
338 \centerpoint%
339 \pgf@xa\halfside%
340 \advance\[email protected]\pgf@xa%
341 \advance\pgf@x-\outerxsep%
342 }%
343 \backgroundpath{%
344 \dimensions%
345 \pgf@xc\halfwidth%
346 \pgf@yc\halfheight%
347 \advance\pgf@xc-\outerxsep%
348 \advance\pgf@yc-\outerysep%
349 \[email protected]\pgf@xc%
350 {%
351 \pgftransformshift{\centerpoint}%
352 \pgfpathmoveto{\pgfqpoint{\pgf@xb}{\pgf@yc}}%
353 {%
354 \edef\pgf@marshal{%
355 \noexpand\pgfpatharc{90}{-90}{\the\pgf@yc}%
356 }%
357 \pgf@marshal%
358 }
359 \pgfpathlineto{\pgfqpoint{-1.16666\pgf@xc}{-\pgf@yc}}%
360 \pgfpathlineto{\pgfqpoint{-1.16666\pgf@xc}{\pgf@yc}}%
361 \pgfpathclose%
362 %
363 % Draw the inputs.
364 %
365 \[email protected]\pgf@yc%
366 \c@pgf@counta\numinputs%
367 \advance\c@pgf@counta1\relax%
368 \divide\pgfutil@tempdima\c@pgf@counta%
369 \pgfmathloop%
370 \ifnum\pgfmathcounter>\numinputs%
371 \else%
372 \advance\pgf@yc-\pgfutil@tempdima%
373 \expandafter\ifx\expandafter\pgf@lib@sh@itext\csname input-\pgfmathcounter\endcsname%
374 {%
375 \pgfpathcircle{%
376 \pgf@xa\halfside%
377 \[email protected]\pgf@xa%
378 \advance\[email protected]\pgflinewidth%
379 \advance\pgf@x-\invertedradius%
380 \pgf@y\pgf@yc%
381 }{+\invertedradius}%
382 }%
383 \fi%
384 \repeatpgfmathloop%
385 }%
386 }%
387 \anchorborder{%
388 \pgfextract@process\externalpoint{}%
389 \pgfextract@process\externalpoint{\pgfpointadd{\centerpoint}{\externalpoint}}%
390 \pgfmathanglebetweenpoints{\centerpoint}{\externalpoint}%
391 \let\externalangle\pgfmathresult%
392 \dimensions%
393 \pgf@xb\halfside%
394 \[email protected]\pgf@xb%
395 \advance\pgf@xc\outerxsep%
396 \pgf@yc\halfheight%
397 \pgfmathanglebetweenpoints{\centerpoint}{\csname pgf@anchor@and gate US@north west\endcsname}%
398 \ifdim\externalangle pt<\pgfmathresult pt\relax%
399 \pgfmathanglebetweenpoints{\centerpoint}{\centerpoint\advance\[email protected]\pgf@xb\advance\pgf@y\pgf@yc}%
400 \ifdim\externalangle pt<\pgfmathresult pt\relax%
401 \pgfmathpointintersectionoflineandarc{\externalpoint}{\centerpoint}%
402 {%
403 \centerpoint%
404 \advance\[email protected]\pgf@xb%
405 }%
406 {0}{90}{+\halfwidth and +\halfheight}%
407 \else%
408 \pgfpointintersectionoflines{\externalpoint}{\centerpoint}%
409 {\centerpoint\advance\[email protected]\pgf@xb\advance\pgf@y\pgf@yc}%
410 {\centerpoint\advance\pgf@x-\pgf@xc\advance\pgf@y\pgf@yc}%
411 \fi%
412 \else%
413 \pgfmathanglebetweenpoints{\centerpoint}{\centerpoint\advance\[email protected]\pgf@xb\advance\pgf@y-\pgf@yc}%
414 \ifdim\externalangle pt>\pgfmathresult pt\relax%
415 \pgfmathpointintersectionoflineandarc{\externalpoint}{\centerpoint}%
416 {%
417 \centerpoint%
418 \advance\[email protected]\pgf@xb%
419 }%
420 {270}{360}{+\halfwidth and +\halfheight}%
421 \else%
422 \pgfmathanglebetweenpoints{\centerpoint}{\csname pgf@anchor@and gate US@south west\endcsname}%
423 \ifdim\externalangle pt>\pgfmathresult pt\relax%
424 \pgfpointintersectionoflines{\externalpoint}{\centerpoint}%
425 {\centerpoint\advance\[email protected]\pgf@xb\advance\pgf@y-\pgf@yc}%
426 {\csname pgf@anchor@and gate US@south west\endcsname}%
427 \else%
428 \pgfpointintersectionoflines{\externalpoint}{\centerpoint}%
429 {\csname pgf@anchor@and gate US@north west\endcsname}%
430 {\csname pgf@anchor@and gate US@south west\endcsname}%
431 \fi%
432 \fi%
433 \fi%
434 }%
435 }%
436
437
438
439
440
441 % Shape nand gate US
442 %
443 \pgfdeclareshape{nand gate US}{%
444 \expandafter\pgfutil@g@addto@macro\csname pgf@sh@s@nand gate US\endcsname{%
445 \pgf@lib@sh@logicgate@parseinputs{1024}% Maximum 1024 (!) inputs.
446 %
447 \pgfmathloop%
448 \ifnum\pgfmathcounter>\pgf@lib@sh@logicgate@numinputs%
449 \else%
450 \pgfutil@ifundefined{pgf@anchor@nand gate US@input \pgfmathcounter}{%
451 \expandafter\xdef\csname pgf@anchor@nand gate US@input \pgfmathcounter\endcsname{%
452 \noexpand\pgf@lib@sh@logicgate@AND@inputanchor{\pgfmathcounter}%
453 }%
454 }{}%
455 \repeatpgfmathloop%
456 \ifnum\pgf@lib@sh@logicgate@numinputs<2\relax%
457 \pgferror{A nand gate must have at least two inputs}%
458 \fi%
459 }%
460 \savedmacro\numinputs{\let\numinputs\pgf@lib@sh@logicgate@numinputs}%
461 \saveddimen\invertedradius{%
462 \pgfmathsetlength\pgf@x{\pgfkeysvalueof{/pgf/logic gate inverted radius}}%
463 }%
464 \saveddimen\outerinvertedradius{%
465 \pgfmathsetlength\pgf@x{\pgfkeysvalueof{/pgf/logic gate inverted radius}}%
466 \advance\[email protected]\pgflinewidth%
467 }%
468 \savedmacro\dimensions{\pgf@lib@sh@logicgates@dimensions@andUS}%
469 \savedanchor\centerpoint{%
470 \[email protected]\wd\pgfnodeparttextbox%
471 \[email protected]\ht\pgfnodeparttextbox%
472 \advance\[email protected]\dp\pgfnodeparttextbox%
473 }%
474 \savedanchor\midpoint{%
475 \[email protected]\wd\pgfnodeparttextbox%
476 \pgfmathsetlength\pgf@y{+0.5ex}%
477 }%
478 \savedanchor\basepoint{%
479 \[email protected]\wd\pgfnodeparttextbox%
480 \pgf@y0pt%
481 }%
482 \anchor{center}{\centerpoint}%
483 \inheritanchor[from=and gate US]{mid}%
484 \inheritanchor[from=and gate US]{mid east}%
485 \inheritanchor[from=and gate US]{mid west}%
486 \inheritanchor[from=and gate US]{base}%
487 \inheritanchor[from=and gate US]{base east}%
488 \inheritanchor[from=and gate US]{base west}%
489 \anchor{output}{%
490 \dimensions
491 \pgfpointadd{\centerpoint}{%
492 \pgf@xa\halfside%
493 \[email protected]\pgf@xa%
494 \advance\pgf@x\invertedradius%
495 \advance\pgf@x\outerinvertedradius%
496 \advance\pgf@x\outerxsep%
497 \pgf@y0pt%
498 }%
499 }%
500 \inheritanchor[from=and gate US]{east}%
501 \inheritanchor[from=and gate US]{north east}%
502 \inheritanchor[from=and gate US]{south east}%
503 \inheritanchor[from=and gate US]{north}%
504 \inheritanchor[from=and gate US]{south}%
505 \inheritanchor[from=and gate US]{south west}%
506 \inheritanchor[from=and gate US]{north west}%
507 \inheritanchor[from=and gate US]{west}%
508 \backgroundpath{%
509 \dimensions%
510 \pgf@xc\halfwidth%
511 \pgf@yc\halfheight%
512 \advance\pgf@xc-\outerxsep%
513 \advance\pgf@yc-\outerysep%
514 \[email protected]\pgf@xc%
515 {%
516 \pgftransformshift{\centerpoint}%
517 \pgfpathmoveto{\pgfqpoint{\pgf@xb}{\pgf@yc}}%
518 {%
519 \edef\pgf@marshal{%
520 \noexpand\pgfpatharc{90}{-90}{\the\pgf@yc}%
521 }%
522 \pgf@marshal%
523 }
524 \pgfpathlineto{\pgfqpoint{-1.16666\pgf@xc}{-\pgf@yc}}%
525 \pgfpathlineto{\pgfqpoint{-1.16666\pgf@xc}{\pgf@yc}}%
526 \pgfpathclose%
527 %
528 % Draw the inputs.
529 %
530 \[email protected]\pgf@yc%
531 \c@pgf@counta\numinputs%
532 \advance\c@pgf@counta1\relax%
533 \divide\pgfutil@tempdima\c@pgf@counta%
534 \pgfmathloop%
535 \ifnum\pgfmathcounter>\numinputs%
536 \else%
537 \advance\pgf@yc-\pgfutil@tempdima%
538 \expandafter\ifx\expandafter\pgf@lib@sh@itext\csname input-\pgfmathcounter\endcsname%
539 {%
540 \pgfpathcircle{%
541 \pgf@xa\halfside%
542 \[email protected]\pgf@xa%
543 \advance\[email protected]\pgflinewidth%
544 \advance\pgf@x-\invertedradius%
545 \pgf@y\pgf@yc%
546 }{+\invertedradius}%
547 }%
548 \fi%
549 \repeatpgfmathloop%
550 %
551 % Draw the output inverter.
552 %
553 {%
554 \pgfpathcircle{%
555 \[email protected]\pgf@xc%
556 \advance\pgf@x\outerinvertedradius%
557 \pgf@y0pt%
558 }{+\invertedradius}%
559 }%
560 }%
561 }%
562 \inheritanchorborder[from=and gate US]%
563 }%
564
565
566 % Internal macro for calculation input anchors. Used by
567 % or, nor xnor gates (US).
568 %
569 \def\pgf@lib@sh@logicgate@OR@inputanchor#1{%
570 \dimensions%
571 \pgf@ya\halfside%
572 \[email protected]\pgf@ya%
573 %
574 \pgfutil@tempdima\halfside%
575 \multiply\pgfutil@tempdima2\relax%
576 \c@pgf@counta\numinputs%
577 \advance\c@pgf@counta1\relax%
578 \divide\pgfutil@tempdima\c@pgf@counta%
579 \multiply\pgfutil@tempdima#1\relax%
580 \pgf@yc\pgf@ya%
581 \advance\pgf@yc-\pgfutil@tempdima%
582 %
583 \pgf@xb\pgf@yb%
584 \advance\pgf@yb-\halflinewidth%
585 \pgfmathdivide@{\pgfmath@tonumber{\pgf@yc}}{\pgfmath@tonumber{\pgf@yb}}%
586 \pgfmathasin@{\pgfmathresult}%
587 \pgfmathcos@{\pgfmathresult}%
588 %
589 \[email protected]\pgf@ya%
590 \advance\[email protected]\pgf@xb%
591 \advance\pgf@xc\pgfmathresult\pgf@yb%
592 \advance\pgf@xc\halflinewidth%
593 \advance\pgf@xc-\outerxsep%
594 %
595 \expandafter\ifx\expandafter\pgf@lib@sh@itext\csname input-#1\endcsname%
596 \advance\pgf@xc-\invertedradius%
597 \advance\pgf@xc-\outerinvertedradius%
598 \fi%
599 %
600 \centerpoint%
601 \advance\pgf@x\pgf@xc%
602 \advance\pgf@y\pgf@yc%
603 }%
604
605
606 % Shape or gate US
607 %
608 \pgfdeclareshape{or gate US}{%
609 \expandafter\pgfutil@g@addto@macro\csname pgf@sh@s@or gate US\endcsname{%
610 \pgf@lib@sh@logicgate@parseinputs{1024}% Maximum 1024 (!) inputs.
611 %
612 \pgfmathloop%
613 \ifnum\pgfmathcounter>\pgf@lib@sh@logicgate@numinputs%
614 \else%
615 \pgfutil@ifundefined{pgf@anchor@or gate US@input \pgfmathcounter}{%
616 \expandafter\xdef\csname pgf@anchor@or gate US@input \pgfmathcounter\endcsname{%
617 \noexpand\pgf@lib@sh@logicgate@OR@inputanchor{\pgfmathcounter}%
618 }%
619 }{}%
620 \repeatpgfmathloop%
621 \ifnum\pgf@lib@sh@logicgate@numinputs<2\relax%
622 \pgferror{An or gate must have at least two inputs}%
623 \fi%
624 }%
625 \savedmacro\numinputs{\let\numinputs\pgf@lib@sh@logicgate@numinputs}%
626 \saveddimen\invertedradius{%
627 \pgfmathsetlength\pgf@x{\pgfkeysvalueof{/pgf/logic gate inverted radius}}%
628 }%
629 \saveddimen\halflinewidth{%
630 \[email protected]\pgflinewidth%
631 }%
632 \saveddimen\outerinvertedradius{%
633 \pgfmathsetlength\pgf@x{\pgfkeysvalueof{/pgf/logic gate inverted radius}}%
634 \advance\[email protected]\pgflinewidth%
635 }%
636 \savedmacro\dimensions{\pgf@lib@sh@logicgates@dimensions@orUS}%
637 \savedanchor\centerpoint{%
638 \[email protected]\wd\pgfnodeparttextbox%
639 \[email protected]\ht\pgfnodeparttextbox%
640 \advance\[email protected]\dp\pgfnodeparttextbox%
641 }%
642 \savedanchor\midpoint{%
643 \[email protected]\wd\pgfnodeparttextbox%
644 \pgfmathsetlength\pgf@y{+0.5ex}%
645 }%
646 \savedanchor\basepoint{%
647 \[email protected]\wd\pgfnodeparttextbox%
648 \pgf@y0pt%
649 }%
650 \savedanchor\centerpoint{%
651 \[email protected]\wd\pgfnodeparttextbox%
652 \[email protected]\ht\pgfnodeparttextbox%
653 \advance\[email protected]\dp\pgfnodeparttextbox%
654 }%
655 \savedanchor\midpoint{%
656 \[email protected]\wd\pgfnodeparttextbox%
657 \pgfmathsetlength\pgf@y{+0.5ex}%
658 }%
659 \savedanchor\basepoint{%
660 \[email protected]\wd\pgfnodeparttextbox%
661 \pgf@y0pt%
662 }%
663 \anchor{center}{\centerpoint}%
664 \anchor{mid}{\midpoint}%
665 \anchor{mid east}{%
666 \csname pgf@anchor@or gate US@east\endcsname%
667 \pgf@xa\pgf@x%
668 \midpoint%
669 \pgf@x\pgf@xa}%
670 \anchor{mid west}{%
671 \csname pgf@anchor@or gate US@north west\endcsname%
672 \pgf@xa\pgf@x%
673 \midpoint%
674 \pgf@x\pgf@xa}%
675 \anchor{base}{\basepoint}%
676 \anchor{base east}{%
677 \csname pgf@anchor@or gate US@east\endcsname%
678 \pgf@xa\pgf@x%
679 \basepoint%
680 \pgf@x\pgf@xa}%
681 \anchor{base west}{%
682 \csname pgf@anchor@or gate US@north west\endcsname%
683 \pgf@xa\pgf@x%
684 \basepoint%
685 \pgf@x\pgf@xa}%
686 \anchor{east}{%
687 \dimensions%
688 \pgfpointadd{\centerpoint}{\tipanchor}%
689 }%
690 \anchor{output}{\csname pgf@anchor@or gate US@east\endcsname}%
691 \anchor{north east}{%
692 \dimensions%
693 \ifpgfgateanchorsuseboundingrectangle%
694 \tipanchor%
695 \pgf@xa\pgf@x%
696 \centerpoint%
697 \advance\pgf@x\pgf@xa%
698 \advance\pgf@y\halfheight%
699 \else%
700 \centerpoint%
701 \pgf@xa\halfwidth%
702 \pgf@ya\halfheight%
703 \pgf@xb\halfside%
704 \advance\[email protected]\pgf@xb%
705 \advance\pgf@xa\pgf@xb%
706 \advance\[email protected]\pgf@xa%
707 \advance\pgf@y-\pgf@xb%
708 \advance\pgf@ya\pgf@xb%
709 \advance\[email protected]\pgf@ya%
710 \fi%
711 }%
712 \anchor{south east}{%
713 \dimensions%
714 \ifpgfgateanchorsuseboundingrectangle%
715 \tipanchor%
716 \pgf@xa\pgf@x%
717 \centerpoint%
718 \advance\pgf@x\pgf@xa%
719 \advance\pgf@y-\halfheight%
720 \else
721 \centerpoint%
722 \pgf@xa\halfwidth%
723 \pgf@ya\halfheight%
724 \pgf@xb\halfside%
725 \advance\[email protected]\pgf@xb%
726 \advance\pgf@xa\pgf@xb%
727 \advance\[email protected]\pgf@xa%
728 \advance\pgf@y\pgf@xb%
729 \advance\pgf@ya\pgf@xb%
730 \advance\[email protected]\pgf@ya%
731 \fi%
732 }%
733 \anchor{north}{%
734 \dimensions%
735 \centerpoint%
736 \ifpgfgateanchorsuseboundingrectangle%
737 \advance\pgf@y\halfheight%
738 \else%
739 \pgf@ya\halfheight%
740 \advance\[email protected]\pgf@ya%
741 \fi%
742 }%
743 \anchor{south}{%
744 \dimensions%
745 \centerpoint%
746 \ifpgfgateanchorsuseboundingrectangle%
747 \advance\pgf@y-\halfheight%
748 \else%
749 \pgf@ya\halfheight%
750 \advance\[email protected]\pgf@ya%
751 \fi%
752 }%
753 \anchor{south west}{%
754 \dimensions%
755 \centerpoint%
756 \pgf@xa\halfside%
757 \advance\[email protected]\pgf@xa%
758 \pgf@xa\outerxsep%
759 \advance\[email protected]\pgf@xa%
760 \advance\pgf@y-\halfheight%
761 }%
762 \anchor{north west}{%
763 \dimensions%
764 \centerpoint%
765 \pgf@xa\halfside%
766 \advance\[email protected]\pgf@xa%
767 \pgf@xa\outerxsep%
768 \advance\[email protected]\pgf@xa%
769 \advance\pgf@y\halfheight%
770 }%
771 \anchor{west}{%
772 \dimensions%
773 \centerpoint%
774 \pgf@xa\halfside%
775 \ifpgfgateanchorsuseboundingrectangle%
776 \advance\[email protected]\pgf@xa%
777 \advance\pgf@x-\outerxsep%
778 \else%
779 \advance\[email protected]\pgf@xa%
780 \advance\pgf@x-\outerxsep%
781 \advance\[email protected]\pgf@xa%
782 \fi%
783 }%
784 \backgroundpath{%
785 \dimensions%
786 \pgf@xc\halfwidth%
787 \pgf@yc\halfheight%
788 \advance\pgf@xc-\outerxsep%
789 \advance\pgf@yc-\outerysep%
790 {%
791 \pgftransformshift{\centerpoint}%
792 \pgfpathmoveto{\pgfqpoint{-.16666\pgf@xc}{\pgf@yc}}%
793 {%
794 \[email protected]\pgf@yc%
795 \edef\pgf@marshal{%
796 \noexpand\pgfpatharc{90}{30}{\the\pgf@yc}%
797 }%
798 \pgf@marshal%
799 }
800 {%
801 \[email protected]\pgf@yc%
802 \edef\pgf@marshal{%
803 \noexpand\pgfpatharc{-30}{-90}{\the\pgf@yc}%
804 }%
805 \pgf@marshal%
806 }
807 \pgfpathlineto{\pgfqpoint{-1.16666\pgf@xc}{-\pgf@yc}}%
808 {%
809 \[email protected]\pgf@yc%
810 \pgfpatharc{-30}{0}{+\pgf@yc}%
811 }
812 {%
813 \[email protected]\pgf@yc%
814 \pgfpatharc{0}{30}{+\pgf@yc}%
815 }%
816 \pgfpathclose%
817 %
818 % Draw the inputs.
819 %
820 \[email protected]\pgf@yc%
821 \c@pgf@counta\numinputs%
822 \advance\c@pgf@counta1\relax%
823 \divide\pgfutil@tempdima\c@pgf@counta%
824 \pgfmathloop%
825 \ifnum\pgfmathcounter>\numinputs%
826 \else%
827 \advance\pgf@yc-\pgfutil@tempdima%
828 \expandafter\ifx\expandafter\pgf@lib@sh@itext\csname input-\pgfmathcounter\endcsname%
829 {%
830 \pgfpathcircle{%
831 \pgf@ya\halfside%
832 \[email protected]\pgf@ya%
833 \pgf@xa\pgf@yb%
834 \advance\pgf@yb-\halflinewidth%
835 \pgfmathdivide@{\pgfmath@tonumber{\pgf@yc}}{\pgfmath@tonumber{\pgf@yb}}%
836 \let\sineangle\pgfmathresult%
837 \pgfmathasin@{\pgfmathresult}%
838 \pgfmathcos@{\pgfmathresult}%
839 %
840 \[email protected]\pgf@ya%
841 \advance\[email protected]\pgf@xa%
842 \advance\pgf@x\pgfmathresult\pgf@yb%
843 \advance\pgf@x-\invertedradius%
844 \pgf@y\pgf@yc%
845 }{+\invertedradius}%
846 }%
847 \fi%
848 \repeatpgfmathloop%
849 }%
850 }%
851 \anchorborder{%
852 \pgfextract@process\externalpoint{}%
853 \pgfextract@process\externalpoint{\pgfpointadd{\centerpoint}{\externalpoint}}%
854 \pgf@xa\pgf@x%
855 \pgf@ya\pgf@y%
856 \centerpoint%
857 \pgf@xb\pgf@x%
858 \pgf@yb\pgf@y%
859 \pgfmathanglebetweenpoints{\centerpoint}{\externalpoint}%
860 \let\externalangle\pgfmathresult%
861 \dimensions%
862 \pgf@xc\halfside%
863 %
864 \[email protected]\pgf@xc%
865 \ifdim\pgf@xa<\pgf@xc%
866 \pgfmathanglebetweenpoints{\centerpoint}{\csname pgf@anchor@or gate US@north west\endcsname}%
867 \ifdim\externalangle pt<\pgfmathresult pt\relax%
868 \pgfpointintersectionoflines{\externalpoint}{\centerpoint}%
869 {%
870 \pgfgateanchorsuseboundingrectangletrue%
871 \csname pgf@anchor@or gate US@north\endcsname%
872 }%
873 {\csname pgf@anchor@or gate US@north west\endcsname}%
874 \else%
875 \pgfmathsubtract@{360}{\pgfmathresult}%
876 \ifdim\externalangle pt>\pgfmathresult pt\relax%
877 \pgfpointintersectionoflines{\externalpoint}{\centerpoint}%
878 {%
879 \pgfgateanchorsuseboundingrectangletrue%
880 \csname pgf@anchor@or gate US@south\endcsname%
881 }%
882 {\csname pgf@anchor@or gate US@south west\endcsname}%
883 \else%
884 \ifdim\pgf@ya>\pgf@yb%
885 \pgf@yc\halfheight%
886 \advance\pgf@yc\halfside%
887 \advance\pgf@yc-\outerxsep%
888 \pgfextract@process\point{%
889 \pgfmathpointintersectionoflineandarc{\centerpoint}{\externalpoint}%
890 {%
891 \centerpoint%
892 \pgf@xa\halfside%
893 \advance\[email protected]\pgf@xa%
894 \[email protected]\pgf@xa%
895 \advance\[email protected]\pgf@xa%
896 \advance\pgf@x-\outerxsep%
897 }%
898 {0}{90}{+\pgf@yc}%
899 }%
900 \else%
901 \pgf@yc\halfheight%
902 \advance\pgf@yc\halfside%
903 \advance\pgf@yc-\outerxsep%
904 \pgfextract@process\point{%
905 \pgfmathpointintersectionoflineandarc{\centerpoint}{\externalpoint}%
906 {%
907 \centerpoint%
908 \pgf@xa\halfside%
909 \advance\[email protected]\pgf@xa%
910 \[email protected]\pgf@xa%
911 \advance\[email protected]\pgf@xa%
912 \advance\pgf@x-\outerxsep%
913 }%
914 {270}{360}{+\pgf@yc}%
915 }%
916 \fi%
917 \fi%
918 \fi%
919 \else%
920 \ifdim\pgf@y=0pt\relax%
921 \csname pgf@anchor@and gate US@east\endcsname%
922 \else%
923 \pgf@xc\halfwidth%
924 \advance\pgf@xc\halfside%
925 \pgf@yc\halfheight%
926 \advance\pgf@yc\halfside%
927 \pgf@xb\halfside%
928 \[email protected]\pgf@xb%
929 \ifdim\pgf@ya<0pt%
930 \pgfmathpointintersectionoflineandarc{\externalpoint}{\centerpoint}%
931 {%
932 \centerpoint%
933 \advance\pgf@y\halfside%
934 \advance\pgf@x\pgf@xb%
935 }%
936 {270}{330}{+\pgf@yc}%
937 \else%
938 \pgfmathpointintersectionoflineandarc{\externalpoint}{\centerpoint}%
939 {%
940 \centerpoint%
941 \advance\pgf@y-\halfside%
942 \advance\pgf@x\pgf@xb%
943 }%
944 {30}{90}{+\pgf@xc and +\pgf@yc}%
945 \fi%
946 \fi%
947 \fi%
948 }%
949 }%
950
951
952
953
954 % Shape nor gate US
955 %
956 \pgfdeclareshape{nor gate US}{%
957 \expandafter\pgfutil@g@addto@macro\csname pgf@sh@s@nor gate US\endcsname{%
958 \pgf@lib@sh@logicgate@parseinputs{1024}% Maximum 1024 (!) inputs.
959 %
960 \pgfmathloop%
961 \ifnum\pgfmathcounter>\pgf@lib@sh@logicgate@numinputs%
962 \else%
963 \pgfutil@ifundefined{pgf@anchor@nor gate US@input \pgfmathcounter}{%
964 \expandafter\xdef\csname pgf@anchor@nor gate US@input \pgfmathcounter\endcsname{%
965 \noexpand\pgf@lib@sh@logicgate@OR@inputanchor{\pgfmathcounter}%
966 }%
967 }{}%
968 \repeatpgfmathloop%
969 \ifnum\pgf@lib@sh@logicgate@numinputs<2\relax%
970 \pgferror{A nor gate must have at least two inputs}%
971 \fi%
972 }%
973 \savedmacro\numinputs{\let\numinputs\pgf@lib@sh@logicgate@numinputs}%
974 \saveddimen\invertedradius{%
975 \pgfmathsetlength\pgf@x{\pgfkeysvalueof{/pgf/logic gate inverted radius}}%
976 }%
977 \saveddimen\halflinewidth{%
978 \[email protected]\pgflinewidth%
979 }%
980 \saveddimen\outerinvertedradius{%
981 \pgfmathsetlength\pgf@x{\pgfkeysvalueof{/pgf/logic gate inverted radius}}%
982 \advance\[email protected]\pgflinewidth%
983 }%
984 \savedmacro\dimensions{\pgf@lib@sh@logicgates@dimensions@orUS}%
985 \savedanchor\centerpoint{%
986 \[email protected]\wd\pgfnodeparttextbox%
987 \[email protected]\ht\pgfnodeparttextbox%
988 \advance\[email protected]\dp\pgfnodeparttextbox%
989 }%
990 \savedanchor\midpoint{%
991 \[email protected]\wd\pgfnodeparttextbox%
992 \pgfmathsetlength\pgf@y{+0.5ex}%
993 }%
994 \savedanchor\basepoint{%
995 \[email protected]\wd\pgfnodeparttextbox%
996 \pgf@y0pt%
997 }%
998 \inheritanchor[from=or gate US]{center}%
999 \inheritanchor[from=or gate US]{mid}%
1000 \inheritanchor[from=or gate US]{mid east}%
1001 \inheritanchor[from=or gate US]{mid west}%
1002 \inheritanchor[from=or gate US]{base}%
1003 \inheritanchor[from=or gate US]{base east}%
1004 \inheritanchor[from=or gate US]{base west}%
1005 \inheritanchor[from=or gate US]{east}%
1006 \inheritanchor[from=or gate US]{north east}%
1007 \inheritanchor[from=or gate US]{south east}%
1008 \inheritanchor[from=or gate US]{north}%
1009 \inheritanchor[from=or gate US]{south}%
1010 \inheritanchor[from=or gate US]{south west}%
1011 \inheritanchor[from=or gate US]{north west}%
1012 \inheritanchor[from=or gate US]{west}%
1013 \anchor{output}{%
1014 \dimensions%
1015 \centerpoint%
1016 \pgf@xc\halfside%
1017 \pgf@yc\pgf@xc%
1018 \advance\[email protected]\pgf@xc%
1019 \[email protected]\pgf@yc%
1020 \advance\[email protected]\pgf@yc%
1021 \advance\pgf@x\outerinvertedradius%
1022 \advance\pgf@x\invertedradius%
1023 \advance\pgf@x\outerxsep%
1024 }%
1025 \backgroundpath{%
1026 \dimensions%
1027 \pgf@xc\halfwidth%
1028 \pgf@yc\halfheight%
1029 \advance\pgf@xc-\outerxsep%
1030 \advance\pgf@yc-\outerysep%
1031 {%
1032 \pgftransformshift{\centerpoint}%
1033 \pgfpathmoveto{\pgfqpoint{-.16666\pgf@xc}{\pgf@yc}}%
1034 {%
1035 \[email protected]\pgf@yc%
1036 \edef\pgf@marshal{%
1037 \noexpand\pgfpatharc{90}{30}{\the\pgf@yc}%
1038 }%
1039 \pgf@marshal%
1040 }
1041 {%
1042 \[email protected]\pgf@yc%
1043 \edef\pgf@marshal{%
1044 \noexpand\pgfpatharc{-30}{-90}{\the\pgf@yc}%
1045 }%
1046 \pgf@marshal%
1047 }
1048 \pgfpathlineto{\pgfqpoint{-1.16666\pgf@xc}{-\pgf@yc}}%
1049 {%
1050 \[email protected]\pgf@yc%
1051 \pgfpatharc{-30}{0}{+\pgf@yc}%
1052 }
1053 {%
1054 \[email protected]\pgf@yc%
1055 \pgfpatharc{0}{30}{+\pgf@yc}%
1056 }%
1057 \pgfpathclose%
1058 % Draw the output inverter.
1059 %
1060 {%
1061 \pgfpathcircle{%
1062 \[email protected]\pgf@xc%
1063 \[email protected]\pgf@yc%
1064 \advance\[email protected]\pgf@yc%
1065 \advance\pgf@x\outerinvertedradius%
1066 \pgf@y0pt%
1067 }{+\invertedradius}%
1068 }%
1069 %
1070 % Draw the inputs.
1071 %
1072 \[email protected]\pgf@yc%
1073 \c@pgf@counta\numinputs%
1074 \advance\c@pgf@counta1\relax%
1075 \divide\pgfutil@tempdima\c@pgf@counta%
1076 \pgfmathloop%
1077 \ifnum\pgfmathcounter>\numinputs%
1078 \else%
1079 \advance\pgf@yc-\pgfutil@tempdima%
1080 \expandafter\ifx\expandafter\pgf@lib@sh@itext\csname input-\pgfmathcounter\endcsname%
1081 {%
1082 \pgfpathcircle{%
1083 \pgf@ya\halfside%
1084 \[email protected]\pgf@ya%
1085 \pgf@xa\pgf@yb%
1086 \advance\pgf@yb-\halflinewidth%
1087 \pgfmathdivide@{\pgfmath@tonumber{\pgf@yc}}{\pgfmath@tonumber{\pgf@yb}}%
1088 \let\sineangle\pgfmathresult%
1089 \pgfmathasin@{\pgfmathresult}%
1090 \pgfmathcos@{\pgfmathresult}%
1091 %
1092 \[email protected]\pgf@ya%
1093 \advance\[email protected]\pgf@xa%
1094 \advance\pgf@x\pgfmathresult\pgf@yb%
1095 \advance\pgf@x-\invertedradius%
1096 \pgf@y\pgf@yc%
1097 }{+\invertedradius}%
1098 }%
1099 \fi%
1100 \repeatpgfmathloop%
1101 }%
1102 }%
1103 \inheritanchorborder[from=or gate US]%
1104 }%
1105
1106
1107
1108 % Internal macro for calculation input anchors. Used by
1109 % xor and xnor gates (US).
1110 %
1111 \def\pgf@lib@sh@logicgate@XOR@inputanchor#1{%
1112 \dimensions%
1113 \pgf@ya\halfside%
1114 \[email protected]\pgf@ya%
1115 %
1116 \pgfutil@tempdima\halfside%
1117 \multiply\pgfutil@tempdima2\relax%
1118 \c@pgf@counta\numinputs%
1119 \advance\c@pgf@counta1\relax%
1120 \divide\pgfutil@tempdima\c@pgf@counta%
1121 \multiply\pgfutil@tempdima#1\relax%
1122 \pgf@yc\pgf@ya%
1123 \advance\pgf@yc-\pgfutil@tempdima%
1124 %
1125 \pgf@xb\pgf@yb%
1126 \advance\pgf@yb-\halflinewidth%
1127 \pgfmathdivide@{\pgfmath@tonumber{\pgf@yc}}{\pgfmath@tonumber{\pgf@yb}}%
1128 \pgfmathasin@{\pgfmathresult}%
1129 \pgfmathcos@{\pgfmathresult}%
1130 %
1131 \[email protected]\pgf@ya%
1132 \advance\[email protected]\pgf@xb%
1133 \advance\pgf@xc\pgfmathresult\pgf@yb%
1134 \advance\pgf@xc\halflinewidth%
1135 \advance\pgf@xc-\outerxsep%
1136 %
1137 \expandafter\ifx\expandafter\pgf@lib@sh@itext\csname input-#1\endcsname%
1138 \advance\pgf@xc-\invertedradius%
1139 \advance\pgf@xc-\outerinvertedradius%
1140 \fi%
1141 %
1142 \centerpoint%
1143 \advance\pgf@x\pgf@xc%
1144 \advance\pgf@y\pgf@yc%
1145 \pgf@xa\halfside%
1146 \advance\[email protected]\pgf@xa%
1147 }%
1148
1149
1150
1151
1152
1153 % Shape xor gate US
1154 %
1155 \pgfdeclareshape{xor gate US}{%
1156 \expandafter\pgfutil@g@addto@macro\csname pgf@sh@s@xor gate US\endcsname{%
1157 \pgf@lib@sh@logicgate@parseinputs{2}%
1158 %
1159 \pgfmathloop%
1160 \ifnum\pgfmathcounter>\pgf@lib@sh@logicgate@numinputs%
1161 \else%
1162 \pgfutil@ifundefined{pgf@anchor@xor gate US@input \pgfmathcounter}{%
1163 \expandafter\xdef\csname pgf@anchor@xor gate US@input \pgfmathcounter\endcsname{%
1164 \noexpand\pgf@lib@sh@logicgate@XOR@inputanchor{\pgfmathcounter}%
1165 }%
1166 }{}%
1167 \repeatpgfmathloop%
1168 \ifnum\pgf@lib@sh@logicgate@numinputs<2\relax%
1169 \pgferror{An xor gate must have at two inputs}%
1170 \fi%
1171 }%
1172 \savedmacro\numinputs{\let\numinputs\pgf@lib@sh@logicgate@numinputs}%
1173 \saveddimen\invertedradius{%
1174 \pgfmathsetlength\pgf@x{\pgfkeysvalueof{/pgf/logic gate inverted radius}}%
1175 }%
1176 \saveddimen\halflinewidth{%
1177 \[email protected]\pgflinewidth%
1178 }%
1179 \saveddimen\outerinvertedradius{%
1180 \pgfmathsetlength\pgf@x{\pgfkeysvalueof{/pgf/logic gate inverted radius}}%
1181 \advance\[email protected]\pgflinewidth%
1182 }%
1183 \savedmacro\dimensions{\pgf@lib@sh@logicgates@dimensions@orUS}%
1184 \savedanchor\centerpoint{%
1185 \[email protected]\wd\pgfnodeparttextbox%
1186 \[email protected]\ht\pgfnodeparttextbox%
1187 \advance\[email protected]\dp\pgfnodeparttextbox%
1188 }%
1189 \savedanchor\midpoint{%
1190 \[email protected]\wd\pgfnodeparttextbox%
1191 \pgfmathsetlength\pgf@y{+0.5ex}%
1192 }%
1193 \savedanchor\basepoint{%
1194 \[email protected]\wd\pgfnodeparttextbox%
1195 \pgf@y0pt%
1196 }%
1197 \anchor{center}{\centerpoint}%
1198 \anchor{mid}{\midpoint}%
1199 \inheritanchor[from=or gate US]{mid east}%
1200 \anchor{mid west}{%
1201 \csname pgf@anchor@xor gate US@north west\endcsname%
1202 \pgf@xa\pgf@x%
1203 \midpoint%
1204 \pgf@x\pgf@xa}%
1205 \anchor{base}{\basepoint}%
1206 \inheritanchor[from=or gate US]{base east}%
1207 \anchor{base west}{%
1208 \csname pgf@anchor@xor gate US@north west\endcsname%
1209 \pgf@xa\pgf@x%
1210 \basepoint%
1211 \pgf@x\pgf@xa}%
1212 \inheritanchor[from=or gate US]{base}%
1213 \inheritanchor[from=or gate US]{output}%
1214 \inheritanchor[from=or gate US]{east}%
1215 \inheritanchor[from=or gate US]{north east}%
1216 \inheritanchor[from=or gate US]{south east}%
1217 \inheritanchor[from=or gate US]{north}%
1218 \inheritanchor[from=or gate US]{south}%
1219 \anchor{south west}{%
1220 \dimensions%
1221 \pgf@xa\halfside%
1222 \[email protected]\pgf@xa% (7/6 + 2*cos(30) + 1/3) * x
1223 \pgf@xb\halfside%
1224 \[email protected]\pgf@xb%
1225 \advance\pgf@xb-\halflinewidth%
1226 \advance\[email protected]\pgf@xb%
1227 \[email protected]\pgf@xb%
1228 \centerpoint%
1229 \advance\pgf@x\pgf@xa%
1230 \ifpgfgateanchorsuseboundingrectangle%
1231 \advance\pgf@y-\halfheight%
1232 \else%
1233 \advance\pgf@y-\pgf@ya%
1234 \fi%
1235 }%
1236 \anchor{north west}{%
1237 \dimensions%
1238 \pgf@xa\halfside%
1239 \[email protected]\pgf@xa% (7/6 + 2*cos(30) + 1/3) * x
1240 \pgf@xb\halfside%
1241 \[email protected]\pgf@xb%
1242 \advance\pgf@xb-\halflinewidth%
1243 \advance\[email protected]\pgf@xb%
1244 \[email protected]\pgf@xb%
1245 \centerpoint%
1246 \advance\pgf@x\pgf@xa%
1247 \ifpgfgateanchorsuseboundingrectangle%
1248 \advance\pgf@y\halfheight%
1249 \else%
1250 \advance\pgf@y\pgf@ya%
1251 \fi%
1252 }%
1253 \anchor{west}{%
1254 \dimensions%
1255 \pgf@ya\halfside%
1256 \[email protected]\pgf@ya%
1257 %
1258 \pgf@xb\pgf@yb%
1259 \advance\pgf@yb-\halflinewidth%
1260 \pgfmathdivide@{0}{\pgfmath@tonumber{\pgf@yb}}%
1261 \pgfmathasin@{\pgfmathresult}%
1262 \pgfmathcos@{\pgfmathresult}%
1263 %
1264 \[email protected]\pgf@ya%
1265 \advance\[email protected]\pgf@xb%
1266 \advance\pgf@xc\pgfmathresult\pgf@yb%
1267 \advance\pgf@xc\halflinewidth%
1268 \advance\pgf@xc-\outerxsep%
1269 %
1270 \centerpoint%
1271 \advance\pgf@x\pgf@xc%
1272 \pgf@xa\halfside%
1273 \advance\[email protected]\pgf@xa%
1274 \ifpgfgateanchorsuseboundingrectangle%
1275 \[email protected]\pgf@xa%
1276 \advance\[email protected]\pgf@xa%
1277 \fi%
1278 }%
1279 \backgroundpath{%
1280 \dimensions%
1281 \pgf@xc\halfwidth%
1282 \pgf@yc\halfheight%
1283 \advance\pgf@xc-\outerxsep%
1284 \advance\pgf@yc-\outerysep%
1285 {%
1286 \pgftransformshift{\centerpoint}%
1287 \pgfpathmoveto{\pgfqpoint{-.16666\pgf@xc}{\pgf@yc}}%
1288 {%
1289 \[email protected]\pgf@yc%
1290 \edef\pgf@marshal{%
1291 \noexpand\pgfpatharc{90}{30}{\the\pgf@yc}%
1292 }%
1293 \pgf@marshal%
1294 }
1295 {%
1296 \[email protected]\pgf@yc%
1297 \edef\pgf@marshal{%
1298 \noexpand\pgfpatharc{-30}{-90}{\the\pgf@yc}%
1299 }%
1300 \pgf@marshal%
1301 }
1302 \pgfpathlineto{\pgfqpoint{-1.16666\pgf@xc}{-\pgf@yc}}%
1303 {%
1304 \[email protected]\pgf@yc%
1305 \pgfpatharc{-22}{0}{+1.166666\pgf@yc and +\pgf@yc}%
1306 }
1307 {%
1308 \[email protected]\pgf@yc%
1309 \pgfpatharc{0}{22}{+1.166666\pgf@yc and +\pgf@yc}%
1310 }%
1311 \pgfpathclose%
1312 %
1313 % Draw the inputs.
1314 %
1315 \[email protected]\pgf@yc%
1316 \c@pgf@counta\numinputs%
1317 \advance\c@pgf@counta1\relax%
1318 \divide\pgfutil@tempdima\c@pgf@counta%
1319 \pgfmathloop%
1320 \ifnum\pgfmathcounter>\numinputs%
1321 \else%
1322 \advance\pgf@yc-\pgfutil@tempdima%
1323 \expandafter\ifx\expandafter\pgf@lib@sh@itext\csname input-\pgfmathcounter\endcsname%
1324 {%
1325 \pgfpathcircle{%
1326 \pgf@ya\halfside%
1327 \[email protected]\pgf@ya%
1328 \pgf@xa\pgf@yb%
1329 \advance\pgf@yb-\halflinewidth%
1330 \pgfmathdivide@{\pgfmath@tonumber{\pgf@yc}}{\pgfmath@tonumber{\pgf@yb}}%
1331 \pgfmathasin@{\pgfmathresult}%
1332 \pgfmathcos@{\pgfmathresult}%
1333 %
1334 \[email protected]\pgf@ya%
1335 \advance\[email protected]\pgf@xa%
1336 \advance\pgf@x\pgfmathresult\pgf@yb%
1337 \advance\pgf@x-\invertedradius%
1338 \pgf@y\pgf@yc%
1339 }{+\invertedradius}%
1340 }%
1341 \fi%
1342 \repeatpgfmathloop%
1343 %
1344 % Now, some fooling around to stop the `tail' being filled.
1345 % Technically it still is, but it isn't visible.
1346 %
1347 \pgf@xc\halfside%
1348 \pgf@yc\halfside%
1349 \pgfpathmoveto{\pgfqpoint{-1.5\pgf@xc}{-\pgf@yc}}%
1350 \[email protected]\pgf@yc%
1351 \pgfmathloop%
1352 \ifnum\pgfmathcounter<61\relax%
1353 {%
1354 \pgfextract@process\point{%
1355 \pgfpointadd{%
1356 \pgf@x\halfside%
1357 \[email protected]\pgf@x% (7/6 + 2*cos(30) + 1/3) * x
1358 \pgf@y0pt%
1359 }{%
1360 \pgfpointpolar{\pgfmathcounter-30}{+\pgf@yc}%
1361 }%
1362 }%
1363 \pgfpathlineto{\point}%
1364 \pgfpathmoveto{\point}%
1365 }
1366 \repeatpgfmathloop%
1367 }%
1368 }%
1369 \anchorborder{%
1370 \pgfextract@process\externalpoint{}%
1371 \pgfextract@process\externalpoint{\pgfpointadd{\centerpoint}{\externalpoint}}%
1372 \pgf@xa\pgf@x%
1373 \pgf@ya\pgf@y%
1374 \centerpoint%
1375 \pgf@xb\pgf@x%
1376 \pgf@yb\pgf@y%
1377 \pgfmathanglebetweenpoints{\centerpoint}{\externalpoint}%
1378 \let\externalangle\pgfmathresult%
1379 \dimensions%
1380 \pgf@xc\halfside%
1381 %
1382 \[email protected]\pgf@xc%
1383 \ifdim\pgf@xa<\pgf@xc%
1384 \pgfmathanglebetweenpoints{\centerpoint}%
1385 {%
1386 \pgfgateanchorsuseboundingrectangletrue%
1387 \csname pgf@anchor@xor gate US@north west\endcsname%
1388 }%
1389 \ifdim\externalangle pt<\pgfmathresult pt\relax%
1390 \pgfpointintersectionoflines{\externalpoint}{\centerpoint}%
1391 {%
1392 \pgfgateanchorsuseboundingrectangletrue%
1393 \csname pgf@anchor@xor gate US@north\endcsname%
1394 }%
1395 {%
1396 \pgfgateanchorsuseboundingrectangletrue%
1397 \csname pgf@anchor@xor gate US@north west\endcsname%
1398 }%
1399 \else%
1400 \pgfmathsubtract@{360}{\pgfmathresult}%
1401 \ifdim\externalangle pt>\pgfmathresult pt\relax%
1402 \pgfpointintersectionoflines{\externalpoint}{\centerpoint}%
1403 {%
1404 \pgfgateanchorsuseboundingrectangletrue%
1405 \csname pgf@anchor@xor gate US@south\endcsname%
1406 }%
1407 {%
1408 \pgfgateanchorsuseboundingrectangletrue%
1409 \csname pgf@anchor@xor gate US@south west\endcsname%
1410 }%
1411 \else%
1412 \ifdim\pgf@ya>\pgf@yb%
1413 \pgf@yc\halfheight%
1414 \advance\pgf@yc\halfside%
1415 \advance\pgf@yc-\outerxsep%
1416 \pgf@process{%
1417 \pgfmathpointintersectionoflineandarc{\centerpoint}{\externalpoint}%
1418 {%
1419 \centerpoint%
1420 \pgf@xa\halfside%
1421 \advance\[email protected]\pgf@xa%
1422 \[email protected]\pgf@xa%
1423 \advance\[email protected]\pgf@xa%
1424 \advance\pgf@x-\outerxsep%
1425 \advance\[email protected]\pgf@xa%
1426 }%
1427 {0}{90}{+\pgf@yc}%
1428 }%
1429 \else%
1430 \pgf@yc\halfheight%
1431 \advance\pgf@yc\halfside%
1432 \advance\pgf@yc-\outerxsep%
1433 \pgf@process{%
1434 \pgfmathpointintersectionoflineandarc{\centerpoint}{\externalpoint}%
1435 {%
1436 \centerpoint%
1437 \pgf@xa\halfside%
1438 \advance\[email protected]\pgf@xa%
1439 \[email protected]\pgf@xa%
1440 \advance\[email protected]\pgf@xa%
1441 \advance\pgf@x-\outerxsep%
1442 \advance\[email protected]\pgf@xa%
1443 }%
1444 {270}{360}{+\pgf@yc}%
1445 }%
1446 \fi%
1447 \fi%
1448 \fi%
1449 \else%
1450 \ifdim\pgf@y=0pt\relax%
1451 \csname pgf@anchor@and gate US@east\endcsname%
1452 \else%
1453 \pgf@xc\halfwidth%
1454 \advance\pgf@xc\halfside%
1455 \pgf@yc\halfheight%
1456 \advance\pgf@yc\halfside%
1457 \pgf@xb\halfside%
1458 \[email protected]\pgf@xb%
1459 \ifdim\pgf@ya<0pt%
1460 \pgfmathpointintersectionoflineandarc{\externalpoint}{\centerpoint}%
1461 {%
1462 \centerpoint%
1463 \advance\pgf@y\halfside%
1464 \advance\pgf@x\pgf@xb%
1465 }%
1466 {270}{330}{+\pgf@yc}%
1467 \else%
1468 \pgfmathpointintersectionoflineandarc{\externalpoint}{\centerpoint}%
1469 {%
1470 \centerpoint%
1471 \advance\pgf@y-\halfside%
1472 \advance\pgf@x\pgf@xb%
1473 }%
1474 {30}{90}{+\pgf@xc and +\pgf@yc}%
1475 \fi%
1476 \fi%
1477 \fi%
1478 }%
1479 }%
1480
1481
1482
1483
1484 % Shape xnor gate US
1485 %
1486 \pgfdeclareshape{xnor gate US}{%
1487 \expandafter\pgfutil@g@addto@macro\csname pgf@sh@s@xnor gate US\endcsname{%
1488 \pgf@lib@sh@logicgate@parseinputs{2}%
1489 %
1490 \pgfmathloop%
1491 \ifnum\pgfmathcounter>\pgf@lib@sh@logicgate@numinputs%
1492 \else%
1493 \pgfutil@ifundefined{pgf@anchor@xnor gate US@input \pgfmathcounter}{%
1494 \expandafter\xdef\csname pgf@anchor@xnor gate US@input \pgfmathcounter\endcsname{%
1495 \noexpand\pgf@lib@sh@logicgate@XOR@inputanchor{\pgfmathcounter}%
1496 }%
1497 }{}%
1498 \repeatpgfmathloop%
1499 \ifnum\pgf@lib@sh@logicgate@numinputs<2\relax%
1500 \pgferror{An xnor gate must have two inputs}%
1501 \fi%
1502 }%
1503 \savedmacro\numinputs{\let\numinputs\pgf@lib@sh@logicgate@numinputs}%
1504 \saveddimen\invertedradius{%
1505 \pgfmathsetlength\pgf@x{\pgfkeysvalueof{/pgf/logic gate inverted radius}}%
1506 }%
1507 \saveddimen\halflinewidth{%
1508 \[email protected]\pgflinewidth%
1509 }%
1510 \saveddimen\outerinvertedradius{%
1511 \pgfmathsetlength\pgf@x{\pgfkeysvalueof{/pgf/logic gate inverted radius}}%
1512 \advance\[email protected]\pgflinewidth%
1513 }%
1514 \savedmacro\dimensions{\pgf@lib@sh@logicgates@dimensions@orUS}%
1515 \savedanchor\centerpoint{%
1516 \[email protected]\wd\pgfnodeparttextbox%
1517 \[email protected]\ht\pgfnodeparttextbox%
1518 \advance\[email protected]\dp\pgfnodeparttextbox%
1519 }%
1520 \savedanchor\midpoint{%
1521 \[email protected]\wd\pgfnodeparttextbox%
1522 \pgfmathsetlength\pgf@y{+0.5ex}%
1523 }%
1524 \savedanchor\basepoint{%
1525 \[email protected]\wd\pgfnodeparttextbox%
1526 \pgf@y0pt%
1527 }%
1528 \anchor{center}{\centerpoint}%
1529 \anchor{mid}{\midpoint}%
1530 \inheritanchor[from=xor gate US]{mid east}%
1531 \inheritanchor[from=xor gate US]{mid west}%
1532 \anchor{base}{\basepoint}%%
1533 \inheritanchor[from=xor gate US]{base east}%
1534 \inheritanchor[from=xor gate US]{base west}%
1535 \inheritanchor[from=xor gate US]{base}%
1536 \inheritanchor[from=nor gate US]{output}%
1537 \inheritanchor[from=xor gate US]{east}%
1538 \inheritanchor[from=xor gate US]{north east}%
1539 \inheritanchor[from=xor gate US]{south east}%
1540 \inheritanchor[from=xor gate US]{north}%
1541 \inheritanchor[from=xor gate US]{south}%
1542 \inheritanchor[from=xor gate US]{south west}%
1543 \inheritanchor[from=xor gate US]{north west}%
1544 \inheritanchor[from=xor gate US]{west}%
1545 \backgroundpath{%
1546 \dimensions%
1547 \pgf@xc\halfwidth%
1548 \pgf@yc\halfheight%
1549 \advance\pgf@xc-\outerxsep%
1550 \advance\pgf@yc-\outerysep%
1551 {%
1552 \pgftransformshift{\centerpoint}%
1553 \pgfpathmoveto{\pgfqpoint{-.16666\pgf@xc}{\pgf@yc}}%
1554 {%
1555 \[email protected]\pgf@yc%
1556 \edef\pgf@marshal{%
1557 \noexpand\pgfpatharc{90}{30}{\the\pgf@yc}%
1558 }%
1559 \pgf@marshal%
1560 }
1561 {%
1562 \[email protected]\pgf@yc%
1563 \edef\pgf@marshal{%
1564 \noexpand\pgfpatharc{-30}{-90}{\the\pgf@yc}%
1565 }%
1566 \pgf@marshal%
1567 }
1568 \pgfpathlineto{\pgfqpoint{-1.16666\pgf@xc}{-\pgf@yc}}%
1569 {%
1570 \[email protected]\pgf@yc%
1571 \pgfpatharc{-22}{0}{+1.166666\pgf@yc and +\pgf@yc}%
1572 }
1573 {%
1574 \[email protected]\pgf@yc%
1575 \pgfpatharc{0}{22}{+1.166666\pgf@yc and +\pgf@yc}%
1576 }%
1577 \pgfpathclose%
1578 %
1579 % Draw the output inverter.
1580 %
1581 {%
1582 \pgfpathcircle{%
1583 \[email protected]\pgf@xc%
1584 \[email protected]\pgf@yc%
1585 \advance\[email protected]\pgf@yc%
1586 \advance\pgf@x\outerinvertedradius%
1587 \pgf@y0pt%
1588 }{+\invertedradius}%
1589 }%
1590 %
1591 % Draw the inputs.
1592 %
1593 \[email protected]\pgf@yc%
1594 \c@pgf@counta\numinputs%
1595 \advance\c@pgf@counta1\relax%
1596 \divide\pgfutil@tempdima\c@pgf@counta%
1597 \pgfmathloop%
1598 \ifnum\pgfmathcounter>\numinputs%
1599 \else%
1600 \advance\pgf@yc-\pgfutil@tempdima%
1601 \expandafter\ifx\expandafter\pgf@lib@sh@itext\csname input-\pgfmathcounter\endcsname%
1602 {%
1603 \pgfpathcircle{%
1604 \pgf@ya\halfside%
1605 \[email protected]\pgf@ya%
1606 \pgf@xa\pgf@yb%
1607 \advance\pgf@yb-\halflinewidth%
1608 \pgfmathdivide@{\pgfmath@tonumber{\pgf@yc}}{\pgfmath@tonumber{\pgf@yb}}%
1609 \pgfmathasin@{\pgfmathresult}%
1610 \pgfmathcos@{\pgfmathresult}%
1611 %
1612 \[email protected]\pgf@ya%
1613 \advance\[email protected]\pgf@xa%
1614 \advance\pgf@x\pgfmathresult\pgf@yb%
1615 \advance\pgf@x-\invertedradius%
1616 \pgf@y\pgf@yc%
1617 }{+\invertedradius}%
1618 }%
1619 \fi%
1620 \repeatpgfmathloop%
1621 %
1622 % Now, some fooling around to stop the `tail' being filled.
1623 %
1624 \pgf@xc\halfside%
1625 \pgf@yc\halfside%
1626 \pgfpathmoveto{\pgfqpoint{-1.5\pgf@xc}{-\pgf@yc}}%
1627 \[email protected]\pgf@yc%
1628 \pgfmathloop%
1629 \ifnum\pgfmathcounter<61\relax%
1630 {%
1631 \pgfextract@process\point{%
1632 \pgfpointadd{%
1633 \pgf@x\halfside%
1634 \[email protected]\pgf@x% (7/6 + 2*cos(30) + 1/3) * x
1635 \pgf@y0pt%
1636 }{%
1637 \pgfpointpolar{\pgfmathcounter-30}{+\pgf@yc}%
1638 }%
1639 }%
1640 \pgfpathlineto{\point}%
1641 \pgfpathmoveto{\point}%
1642 }
1643 \repeatpgfmathloop%
1644 }%
1645 }%
1646 \inheritanchorborder[from=xor gate US]%
1647 }%
1648
1649
1650
1651
1652
1653
1654 % Shape not gate US
1655 %
1656 \pgfdeclareshape{not gate US}{%
1657 \expandafter\pgfutil@g@addto@macro\csname pgf@sh@s@not gate US\endcsname{%
1658 \pgf@lib@sh@logicgate@parseinputs{1}%
1659 \ifnum\pgf@lib@sh@logicgate@numinputs=0\relax%
1660 \pgferror{A not gate must have one input}%
1661 \fi%
1662 }%
1663 \savedmacro\numinputs{\let\numinputs\pgf@lib@sh@logicgate@numinputs}%
1664 \saveddimen\invertedradius{%
1665 \pgfmathsetlength\pgf@x{\pgfkeysvalueof{/pgf/logic gate inverted radius}}%
1666 }%
1667 \saveddimen\halflinewidth{%
1668 \[email protected]\pgflinewidth%
1669 }%
1670 \saveddimen\outerinvertedradius{%
1671 \pgfmathsetlength\pgf@x{\pgfkeysvalueof{/pgf/logic gate inverted radius}}%
1672 \advance\[email protected]\pgflinewidth%
1673 }%
1674 \savedmacro\dimensions{\pgf@lib@sh@logicgates@dimensions@orUS}%
1675 \savedanchor\centerpoint{%
1676 \[email protected]\wd\pgfnodeparttextbox%
1677 \[email protected]\ht\pgfnodeparttextbox%
1678 \advance\[email protected]\dp\pgfnodeparttextbox%
1679 }%
1680 \savedanchor\midpoint{%
1681 \[email protected]\wd\pgfnodeparttextbox%
1682 \pgfmathsetlength\pgf@y{+0.5ex}%
1683 }%
1684 \savedanchor\basepoint{%
1685 \[email protected]\wd\pgfnodeparttextbox%
1686 \pgf@y0pt%
1687 }%
1688 \anchor{center}{\centerpoint}%
1689 \anchor{mid}{\midpoint}%
1690 \anchor{mid east}{%
1691 \midpoint%
1692 \pgfutil@tempdima\pgf@y%
1693 \csname pgf@anchor@not gate US@east\endcsname%
1694 \pgf@y\pgfutil@tempdima%
1695 }%
1696 \anchor{mid west}{%
1697 \dimensions%
1698 \pgf@xc\halfside%
1699 \[email protected]\pgf@xc%
1700 \advance\pgf@xc-\outerxsep%
1701 \midpoint%
1702 \advance\pgf@x\pgf@xc%
1703 }%
1704 \anchor{base}{\basepoint}%
1705 \anchor{base east}{%
1706 \basepoint%
1707 \pgfutil@tempdima\pgf@y%
1708 \csname pgf@anchor@not gate US@east\endcsname%
1709 \pgf@y\pgfutil@tempdima%
1710 }%
1711 \anchor{base west}{%
1712 \dimensions%
1713 \pgf@xc\halfside%
1714 \[email protected]\pgf@xc%
1715 \advance\pgf@xc-\outerxsep%
1716 \basepoint%
1717 \advance\pgf@x\pgf@xc%
1718 }%
1719 \inheritanchor[from=and gate US]{base}%
1720 \anchor{output}{%
1721 \dimensions%
1722 \pgf@xc\halfside%
1723 \centerpoint%
1724 \advance\[email protected]\pgf@xc%
1725 \[email protected]\pgf@xc%
1726 \advance\[email protected]\pgf@xc%
1727 \advance\pgf@x\invertedradius%
1728 \advance\pgf@x\outerinvertedradius%
1729 \advance\pgf@x\outerxsep%
1730 }%
1731 \anchor{east}{%
1732 \dimensions%
1733 \tipanchor%
1734 \pgf@xa\pgf@x%
1735 \centerpoint%
1736 \advance\pgf@x\pgf@xa%
1737 }%
1738 \anchor{north}{%
1739 \dimensions%
1740 \ifpgfgateanchorsuseboundingrectangle%
1741 \csname pgf@anchor@not gate US@north west\endcsname%
1742 \pgf@ya\pgf@y%
1743 \centerpoint%
1744 \pgf@y\pgf@ya%
1745 \else%
1746 \pgfpointintersectionoflines{\centerpoint}{\centerpoint\advance\pgf@y1pt}%
1747 {\csname pgf@anchor@not gate US@north west\endcsname}%
1748 {%
1749 \pgfpointadd{\centerpoint}{%
1750 \tipanchor%
1751 \pgf@xa\outerxsep%
1752 \advance\[email protected]\pgf@xa%
1753 }%
1754 }%
1755 \fi%
1756 }%
1757 \anchor{south}{%
1758 \dimensions%
1759 \ifpgfgateanchorsuseboundingrectangle%
1760 \csname pgf@anchor@not gate US@south west\endcsname%
1761 \pgf@ya\pgf@y%
1762 \centerpoint%
1763 \pgf@y\pgf@ya%
1764 \else%
1765 \pgfpointintersectionoflines{\centerpoint}{\centerpoint\advance\pgf@y-1pt}%
1766 {\csname pgf@anchor@not gate US@south west\endcsname}%
1767 {%
1768 \pgfpointadd{\centerpoint}{%
1769 \tipanchor%
1770 \pgf@xa\outerxsep%
1771 \advance\[email protected]\pgf@xa%
1772 }%
1773 }%
1774 \fi%
1775 }%
1776 \anchor{south east}{%
1777 \dimensions%
1778 \ifpgfgateanchorsuseboundingrectangle%
1779 \csname pgf@anchor@not gate US@south west\endcsname%
1780 \pgf@ya\pgf@y%
1781 \pgf@process{%
1782 \dimensions%
1783 \tipanchor%
1784 \pgf@xa\pgf@x%
1785 \centerpoint%
1786 \advance\pgf@x\pgf@xa%
1787 }%
1788 \pgf@y\pgf@ya%
1789 \else%
1790 \pgfpointintersectionoflines{\centerpoint}{\centerpoint\advance\pgf@x1pt\advance\pgf@y-1pt}%
1791 {\csname pgf@anchor@not gate US@south west\endcsname}%
1792 {%
1793 \pgfpointadd{\centerpoint}{%
1794 \tipanchor%
1795 \pgf@xa\outerxsep%
1796 \advance\[email protected]\pgf@xa%
1797 }%
1798 }%
1799 \fi%
1800 }%
1801 \anchor{north east}{%
1802 \dimensions%
1803 \ifpgfgateanchorsuseboundingrectangle%
1804 \csname pgf@anchor@not gate US@north west\endcsname%
1805 \pgf@ya\pgf@y%
1806 \pgf@process{%
1807 \dimensions%
1808 \tipanchor%
1809 \pgf@xa\pgf@x%
1810 \centerpoint%
1811 \advance\pgf@x\pgf@xa%
1812 }%
1813 \pgf@y\pgf@ya%
1814 \else%
1815 \pgfpointintersectionoflines{\centerpoint}{\centerpoint\advance\pgf@x1pt\advance\pgf@y1pt}%
1816 {\csname pgf@anchor@not gate US@north west\endcsname}%
1817 {%
1818 \pgfpointadd{\centerpoint}{%
1819 \tipanchor%
1820 \pgf@xa\outerxsep%
1821 \advance\[email protected]\pgf@xa%
1822 }%
1823 }%
1824 \fi%
1825 }%
1826 \anchor{south west}{%
1827 \dimensions%
1828 \pgf@xa\halfside%
1829 \centerpoint%
1830 \advance\[email protected]\pgf@xa
1831 \advance\pgf@x-\outerxsep%
1832 \advance\[email protected]\pgf@xa%
1833 \pgf@ya\outerysep%
1834 \advance\[email protected]\pgf@ya% Selected by trial and error.
1835 }%
1836 \anchor{north west}{%
1837 \dimensions%
1838 \pgf@xa\halfside%
1839 \centerpoint%
1840 \advance\[email protected]\pgf@xa
1841 \advance\pgf@x-\outerxsep%
1842 \advance\[email protected]\pgf@xa%
1843 \pgf@ya\outerysep%
1844 \advance\[email protected]\pgf@ya% Selected by trial and error.
1845 }%
1846 \anchor{input}{%
1847 \dimensions%
1848 \pgf@lib@sh@logicgate@AND@inputanchor{1}%
1849 \pgf@xc\halfside%
1850 \advance\[email protected]\pgf@xc%
1851 }%
1852 \anchor{west}{%
1853 \dimensions%
1854 \pgf@xc\halfside%
1855 \[email protected]\pgf@xc%
1856 \advance\pgf@xc-\outerxsep%
1857 \centerpoint%
1858 \advance\pgf@x\pgf@xc%
1859 }%
1860 \backgroundpath{%
1861 \dimensions%
1862 \pgf@xc\halfwidth%
1863 \pgf@yc\halfheight%
1864 \advance\pgf@xc-\outerxsep%
1865 \advance\pgf@yc-\outerysep%
1866 {%
1867 \pgftransformshift{\centerpoint}%
1868 \pgfpathmoveto{\tipanchor}%
1869 \pgfpathlineto{\pgfqpoint{-.833333\pgf@xc}{1.166666\pgf@yc}}%
1870 \pgfpathlineto{\pgfqpoint{-.833333\pgf@xc}{-1.166666\pgf@yc}}%
1871 \pgfpathlineto{\tipanchor}%
1872 %
1873 % Draw the output inverter.
1874 %
1875 {%
1876 \pgfpathcircle{%
1877 \[email protected]\pgf@xc%
1878 \[email protected]\pgf@yc%
1879 \advance\[email protected]\pgf@yc%
1880 \advance\pgf@x\outerinvertedradius%
1881 \pgf@y0pt%
1882 }{+\invertedradius}%
1883 }%
1884 %
1885 % Draw the input.
1886 %
1887 \expandafter\ifx\expandafter\pgf@lib@sh@itext\csname input-1\endcsname%
1888 {%
1889 \pgfpathcircle{%
1890 \pgf@xa\halfside%
1891 \[email protected]\pgf@xa%
1892 \advance\[email protected]\pgflinewidth%
1893 \advance\pgf@x-\invertedradius%
1894 \pgf@y0pt%
1895 }{+\invertedradius}%
1896 }%
1897 \fi%
1898 }%
1899 }%
1900 \anchorborder{%
1901 \pgf@lib@gates@not@buffer@border{not gate US}
1902 }%
1903 }%
1904
1905 \def\pgf@lib@gates@not@buffer@border#1{
1906 \pgfextract@process\externalpoint{}%
1907 \pgfextract@process\externalpoint{\pgfpointadd{\centerpoint}{\externalpoint}}%
1908 \pgfmathanglebetweenpoints{\centerpoint}{\externalpoint}%
1909 \ifx\pgfmathresult\pgf@lib@zero@text%
1910 \csname pgf@anchor@#1@output\endcsname%
1911 \else%
1912 \ifx\pgfmathresult\pgf@lib@onehundredeighty@text%
1913 \csname pgf@anchor@#1@input\endcsname%
1914 \else%
1915 \let\externalangle\pgfmathresult%
1916 \dimensions%
1917 \pgfmathanglebetweenpoints{\centerpoint}{\csname pgf@anchor@not gate US@north west\endcsname}%
1918 \ifdim\externalangle pt<\pgfmathresult pt%
1919 \pgfpointintersectionoflines{\centerpoint}{\externalpoint}%
1920 {\csname pgf@anchor@not gate US@north west\endcsname}%
1921 {%
1922 \pgfpointadd{\centerpoint}{%
1923 \tipanchor%
1924 \pgf@xa\outerxsep%
1925 \advance\[email protected]\pgf@xa%
1926 }%
1927 }%
1928 \else%
1929 \pgfmathanglebetweenpoints{\centerpoint}{\csname pgf@anchor@not gate US@south west\endcsname}%
1930 \ifdim\externalangle pt<\pgfmathresult pt%
1931 \pgfpointintersectionoflines{\externalpoint}{\centerpoint}%
1932 {\csname pgf@anchor@not gate US@north west\endcsname}%
1933 {\csname pgf@anchor@not gate US@south west\endcsname}%
1934 \else%
1935 \pgfpointintersectionoflines{\centerpoint}{\externalpoint}%
1936 {\csname pgf@anchor@not gate US@south west\endcsname}%
1937 {%
1938 \pgfpointadd{\centerpoint}{%
1939 \tipanchor%
1940 \pgf@xa\outerxsep%
1941 \advance\[email protected]\pgf@xa%
1942 }%
1943 }%
1944 \fi%
1945 \fi%
1946 \fi%
1947 \fi%
1948 }%
1949
1950
1951 \def\pgf@lib@zero@text{0.0}%
1952 \def\pgf@lib@onehundredeighty@text{180.0}%
1953
1954
1955
1956
1957 % Shape buffer gate US.
1958 %
1959 \pgfdeclareshape{buffer gate US}{%
1960 \expandafter\pgfutil@g@addto@macro\csname pgf@sh@s@buffer gate US\endcsname{%
1961 \pgf@lib@sh@logicgate@parseinputs{1}%
1962 \ifnum\pgf@lib@sh@logicgate@numinputs=0\relax%
1963 \pgferror{A buffer gate must have one input}%
1964 \fi%
1965 }%
1966 \savedmacro\numinputs{\let\numinputs\pgf@lib@sh@logicgate@numinputs}%
1967 \saveddimen\invertedradius{%
1968 \pgfmathsetlength\pgf@x{\pgfkeysvalueof{/pgf/logic gate inverted radius}}%
1969 }%
1970 \saveddimen\halflinewidth{%
1971 \[email protected]\pgflinewidth%
1972 }%
1973 \saveddimen\outerinvertedradius{%
1974 \pgfmathsetlength\pgf@x{\pgfkeysvalueof{/pgf/logic gate inverted radius}}%
1975 \advance\[email protected]\pgflinewidth%
1976 }%
1977 \savedmacro\dimensions{\pgf@lib@sh@logicgates@dimensions@orUS}%
1978 \savedanchor\centerpoint{%
1979 \[email protected]\wd\pgfnodeparttextbox%
1980 \[email protected]\ht\pgfnodeparttextbox%
1981 \advance\[email protected]\dp\pgfnodeparttextbox%
1982 }%
1983 \savedanchor\midpoint{%
1984 \[email protected]\wd\pgfnodeparttextbox%
1985 \pgfmathsetlength\pgf@y{+0.5ex}%
1986 }%
1987 \savedanchor\basepoint{%
1988 \[email protected]\wd\pgfnodeparttextbox%
1989 \pgf@y0pt%
1990 }%
1991 \anchor{center}{\centerpoint}%
1992 \anchor{mid}{\midpoint}%
1993 \anchor{mid east}{%
1994 \midpoint%
1995 \pgfutil@tempdima\pgf@y%
1996 \csname pgf@anchor@buffer gate US@east\endcsname%
1997 \pgf@y\pgfutil@tempdima%
1998 }%
1999 \anchor{mid west}{%
2000 \dimensions%
2001 \pgf@xc\halfside%
2002 \[email protected]\pgf@xc%
2003 \advance\pgf@xc-\outerxsep%
2004 \midpoint%
2005 \advance\pgf@x\pgf@xc%
2006 }%
2007 \anchor{base}{\basepoint}%
2008 \anchor{base east}{%
2009 \basepoint%
2010 \pgfutil@tempdima\pgf@y%
2011 \csname pgf@anchor@buffer gate US@east\endcsname%
2012 \pgf@y\pgfutil@tempdima%
2013 }%
2014 \inheritanchor[from=not gate US]{base west}%
2015 \inheritanchor[from=and gate US]{base}%
2016 \anchor{output}{\csname pgf@anchor@buffer gate US@east\endcsname}%
2017 \anchor{east}{%
2018 \dimensions%
2019 \pgfpointadd{\centerpoint}{%
2020 \tipanchor%
2021 \pgf@xa\outerxsep%
2022 \advance\[email protected]\pgf@xa%
2023 }%
2024 }%
2025 \anchor{north}{%
2026 \dimensions%
2027 \ifpgfgateanchorsuseboundingrectangle%
2028 \csname pgf@anchor@not gate US@north west\endcsname%
2029 \pgf@ya\pgf@y%
2030 \centerpoint%
2031 \pgf@y\pgf@ya%
2032 \else%
2033 \pgfpointintersectionoflines{\centerpoint}{\centerpoint\advance\pgf@y1pt}%
2034 {\csname pgf@anchor@buffer gate US@north west\endcsname}%
2035 {%
2036 \pgfpointadd{\centerpoint}{%
2037 \tipanchor%
2038 \pgf@xa\outerxsep%
2039 \advance\[email protected]\pgf@xa%
2040 }%
2041 }%
2042 \fi%
2043 }%
2044 \anchor{south}{%
2045 \dimensions%
2046 \ifpgfgateanchorsuseboundingrectangle%
2047 \csname pgf@anchor@not gate US@south west\endcsname%
2048 \pgf@ya\pgf@y%
2049 \centerpoint%
2050 \pgf@y\pgf@ya%
2051 \else%
2052 \pgfpointintersectionoflines{\centerpoint}{\centerpoint\advance\pgf@y-1pt}%
2053 {\csname pgf@anchor@not gate US@south west\endcsname}%
2054 {%
2055 \pgfpointadd{\centerpoint}{%
2056 \tipanchor%
2057 \pgf@xa\outerxsep%
2058 \advance\[email protected]\pgf@xa%
2059 }%
2060 }%
2061 \fi%
2062 }%
2063 \anchor{south east}{%
2064 \dimensions%
2065 \ifpgfgateanchorsuseboundingrectangle%
2066 \csname pgf@anchor@not gate US@south west\endcsname%
2067 \pgfutil@tempdima\pgf@y%
2068 \csname pgf@anchor@buffer gate US@east\endcsname%
2069 \pgf@y\pgfutil@tempdima%
2070 \else%
2071 \pgfpointintersectionoflines{\centerpoint}{\centerpoint\advance\pgf@x1pt\advance\pgf@y-1pt}%
2072 {\csname pgf@anchor@buffer gate US@south west\endcsname}%
2073 {%
2074 \pgfpointadd{\centerpoint}{%
2075 \tipanchor%
2076 \pgf@xc\outerxsep%
2077 \advance\[email protected]\pgf@xc%
2078 }%
2079 }%
2080 \fi%
2081 }%
2082 \anchor{north east}{%
2083 \dimensions%
2084 \ifpgfgateanchorsuseboundingrectangle%
2085 \csname pgf@anchor@not gate US@north west\endcsname%
2086 \pgfutil@tempdima\pgf@y%
2087 \csname pgf@anchor@buffer gate US@east\endcsname%
2088 \pgf@y\pgfutil@tempdima%
2089 \else%
2090 \pgfpointintersectionoflines{\centerpoint}{\centerpoint\advance\pgf@x1pt\advance\pgf@y1pt}%
2091 {\csname pgf@anchor@buffer gate US@north west\endcsname}%
2092 {%
2093 \pgfpointadd{\centerpoint}{%
2094 \tipanchor%
2095 \pgf@xa\outerxsep%
2096 \advance\[email protected]\pgf@xa%
2097 }%
2098 }%
2099 \fi%
2100 }%
2101 \inheritanchor[from=not gate US]{south west}%
2102 \inheritanchor[from=not gate US]{north west}%
2103 \inheritanchor[from=not gate US]{input}%
2104 \inheritanchor[from=not gate US]{west}%
2105 \backgroundpath{%
2106 \dimensions%
2107 \pgf@xc\halfwidth%
2108 \pgf@yc\halfheight%
2109 \advance\pgf@xc-\outerxsep%
2110 \advance\pgf@yc-\outerysep%
2111 {%
2112 \pgftransformshift{\centerpoint}%
2113 \pgfpathmoveto{\tipanchor}%
2114 \pgfpathlineto{\pgfqpoint{-.833333\pgf@xc}{1.166666\pgf@yc}}%
2115 \pgfpathlineto{\pgfqpoint{-.833333\pgf@xc}{-1.166666\pgf@yc}}%
2116 \pgfpathclose%
2117 %
2118 % Draw the input.
2119 %
2120 \expandafter\ifx\expandafter\pgf@lib@sh@itext\csname input-1\endcsname%
2121 {%
2122 \pgfpathcircle{%
2123 \pgf@xa\halfside%
2124 \[email protected]\pgf@xa%
2125 \advance\[email protected]\pgflinewidth%
2126 \advance\pgf@x-\invertedradius%
2127 \pgf@y0pt%
2128 }{+\invertedradius}%
2129 }%
2130 \fi%
2131 }%
2132 }%
2133 \anchorborder{%
2134 \pgf@lib@gates@not@buffer@border{buffer gate US}
2135 }%
2136 }%
2137
2138
2139
2140
2141
2142 \pgfdeclareshape{and gate CDH}{%
2143 \expandafter\pgfutil@g@addto@macro\csname pgf@sh@s@and gate CDH\endcsname{%
2144 \pgf@lib@sh@logicgate@parseinputs{1024}% Maximum 1024 (!) inputs.
2145 %
2146 \pgfmathloop%
2147 \ifnum\pgfmathcounter>\pgf@lib@sh@logicgate@numinputs%
2148 \else%
2149 \pgfutil@ifundefined{pgf@anchor@and gate CDH@input \pgfmathcounter}{%
2150 \expandafter\xdef\csname pgf@anchor@and gate CDH@input \pgfmathcounter\endcsname{%
2151 \noexpand\pgf@lib@sh@logicgate@AND@inputanchor{\pgfmathcounter}%
2152 }%
2153 }{}%
2154 \repeatpgfmathloop%
2155 \ifnum\pgf@lib@sh@logicgate@numinputs<2\relax%
2156 \pgferror{An and gate must have at least two inputs}%
2157 \fi%
2158 }%
2159 \savedmacro\numinputs{\let\numinputs\pgf@lib@sh@logicgate@numinputs}%
2160 \saveddimen\invertedradius{%
2161 \pgfmathsetlength\pgf@x{\pgfkeysvalueof{/pgf/logic gate inverted radius}}%
2162 }%
2163 \saveddimen\outerinvertedradius{%
2164 \pgfmathsetlength\pgf@x{\pgfkeysvalueof{/pgf/logic gate inverted radius}}%
2165 \advance\[email protected]\pgflinewidth%
2166 }%
2167 \savedmacro\dimensions{\pgf@lib@sh@logicgates@dimensions@orUS}%
2168 \savedanchor\centerpoint{%
2169 \[email protected]\wd\pgfnodeparttextbox%
2170 \[email protected]\ht\pgfnodeparttextbox%
2171 \advance\[email protected]\dp\pgfnodeparttextbox%
2172 }%
2173 \savedanchor\midpoint{%
2174 \[email protected]\wd\pgfnodeparttextbox%
2175 \pgfmathsetlength\pgf@y{+0.5ex}%
2176 }%
2177 \savedanchor\basepoint{%
2178 \[email protected]\wd\pgfnodeparttextbox%
2179 \pgf@y0pt%
2180 }%
2181 \anchor{center}{\centerpoint}%
2182 \anchor{mid}{\midpoint}%
2183 \anchor{mid east}{%
2184 \csname pgf@anchor@and gate CDH@east\endcsname%
2185 \pgf@xa\pgf@x%
2186 \midpoint%
2187 \pgf@x\pgf@xa}%
2188 \anchor{mid west}{%
2189 \csname pgf@anchor@and gate CDH@west\endcsname%
2190 \pgf@xa\pgf@x%
2191 \midpoint%
2192 \pgf@x\pgf@xa}%
2193 \anchor{base}{\basepoint}%
2194 \anchor{base east}{%
2195 \csname pgf@anchor@and gate CDH@east\endcsname%
2196 \pgf@xa\pgf@x%
2197 \basepoint%
2198 \pgf@x\pgf@xa}%
2199 \anchor{base west}{%
2200 \csname pgf@anchor@and gate CDH@west\endcsname%
2201 \pgf@xa\pgf@x%
2202 \basepoint%
2203 \pgf@x\pgf@xa}%
2204 \anchor{east}{%
2205 \dimensions%
2206 \pgfpointadd{\centerpoint}{\tipanchor}%
2207 }%
2208 \anchor{output}{\csname pgf@anchor@and gate CDH@east\endcsname}%
2209 \anchor{north east}{%
2210 \dimensions%
2211 \ifpgfgateanchorsuseboundingrectangle%
2212 \tipanchor%
2213 \pgf@xa\pgf@x%
2214 \centerpoint%
2215 \advance\pgf@x\pgf@xa%
2216 \advance\pgf@y\halfheight%
2217 \else%
2218 \centerpoint%
2219 \pgf@xa\halfwidth%
2220 \pgf@ya\halfheight%
2221 \pgf@xb\halfside%
2222 \advance\[email protected]\pgf@xb%
2223 \advance\pgf@xa\pgf@xb%
2224 \advance\[email protected]\pgf@xa%
2225 \advance\pgf@y-\pgf@xb%
2226 \advance\pgf@ya\pgf@xb%
2227 \advance\[email protected]\pgf@ya%
2228 \fi%
2229 }%
2230 \anchor{south east}{%
2231 \dimensions%
2232 \ifpgfgateanchorsuseboundingrectangle%
2233 \tipanchor%
2234 \pgf@xa\pgf@x%
2235 \centerpoint%
2236 \advance\pgf@x\pgf@xa%
2237 \advance\pgf@y-\halfheight%
2238 \else
2239 \centerpoint%
2240 \pgf@xa\halfwidth%
2241 \pgf@ya\halfheight%
2242 \pgf@xb\halfside%
2243 \advance\[email protected]\pgf@xb%
2244 \advance\pgf@xa\pgf@xb%
2245 \advance\[email protected]\pgf@xa%
2246 \advance\pgf@y\pgf@xb%
2247 \advance\pgf@ya\pgf@xb%
2248 \advance\[email protected]\pgf@ya%
2249 \fi%
2250 }%
2251 \anchor{north}{%
2252 \dimensions%
2253 \centerpoint%
2254 \ifpgfgateanchorsuseboundingrectangle%
2255 \advance\pgf@y\halfheight%
2256 \else%
2257 \pgf@ya\halfheight%
2258 \advance\[email protected]\pgf@ya%
2259 \fi%
2260 }%
2261 \anchor{south}{%
2262 \dimensions%
2263 \centerpoint%
2264 \ifpgfgateanchorsuseboundingrectangle%
2265 \advance\pgf@y-\halfheight%
2266 \else%
2267 \pgf@ya\halfheight%
2268 \advance\[email protected]\pgf@ya%
2269 \fi%
2270 }%
2271 \anchor{south west}{%
2272 \dimensions%
2273 \centerpoint%
2274 \pgf@xa\halfside%
2275 \advance\[email protected]\pgf@xa%
2276 \advance\pgf@x-\outerxsep%
2277 \advance\pgf@y-\halfheight%
2278 }%
2279 \anchor{north west}{%
2280 \dimensions%
2281 \centerpoint%
2282 \pgf@xa\halfside%
2283 \advance\[email protected]\pgf@xa%
2284 \advance\pgf@x-\outerxsep%
2285 \advance\pgf@y\halfheight%
2286 }%
2287 \anchor{west}{%
2288 \dimensions%
2289 \centerpoint%
2290 \pgf@xa\halfside%
2291 \advance\[email protected]\pgf@xa%
2292 \advance\pgf@x-\outerxsep%
2293 }%
2294 \backgroundpath{%
2295 \dimensions%
2296 \pgf@xc\halfwidth%
2297 \pgf@yc\halfheight%
2298 \advance\pgf@xc-\outerxsep%
2299 \advance\pgf@yc-\outerysep%
2300 {%
2301 \pgftransformshift{\centerpoint}%
2302 \pgfpathmoveto{\pgfqpoint{-.16666\pgf@xc}{\pgf@yc}}%
2303 {%
2304 \[email protected]\pgf@yc%
2305 \edef\pgf@marshal{%
2306 \noexpand\pgfpatharc{90}{30}{\the\pgf@yc}%
2307 }%
2308 \pgf@marshal%
2309 }
2310 {%
2311 \[email protected]\pgf@yc%
2312 \edef\pgf@marshal{%
2313 \noexpand\pgfpatharc{-30}{-90}{\the\pgf@yc}%
2314 }%
2315 \pgf@marshal%
2316 }
2317 \pgfpathlineto{\pgfqpoint{-1.16666\pgf@xc}{-\pgf@yc}}%
2318 \pgfpathlineto{\pgfqpoint{-1.16666\pgf@xc}{\pgf@yc}}%
2319 \pgfpathclose%
2320 %
2321 % Draw the inputs.
2322 %
2323 \[email protected]\pgf@yc%
2324 \c@pgf@counta\numinputs%
2325 \advance\c@pgf@counta1\relax%
2326 \divide\pgfutil@tempdima\c@pgf@counta%
2327 \pgfmathloop%
2328 \ifnum\pgfmathcounter>\numinputs%
2329 \else%
2330 \advance\pgf@yc-\pgfutil@tempdima%
2331 \expandafter\ifx\expandafter\pgf@lib@sh@itext\csname input-\pgfmathcounter\endcsname%
2332 {%
2333 \pgfpathcircle{%
2334 \pgf@xa\halfside%
2335 \[email protected]\pgf@xa%
2336 \advance\[email protected]\pgflinewidth%
2337 \advance\pgf@x-\invertedradius%
2338 \pgf@y\pgf@yc%
2339 }{+\invertedradius}%
2340 }%
2341 \fi%
2342 \repeatpgfmathloop%
2343 }%
2344 }%
2345 \anchorborder{%
2346 \pgfextract@process\externalpoint{}%
2347 \pgf@xa\pgf@x%
2348 \pgf@ya\pgf@y%
2349 \dimensions%
2350 \pgf@xb\halfside%
2351 %
2352 \[email protected]\pgf@xb%
2353 \ifdim\pgf@xa<\pgf@xb%
2354 \pgfpointadd{\centerpoint}{%
2355 \pgfpointborderrectangle{\externalpoint}{%
2356 \pgf@xc\halfside%
2357 \[email protected]\pgf@xc%
2358 \advance\pgf@xc\halfwidth%
2359 \pgfqpoint{\pgf@xc}{\halfheight}%
2360 }%
2361 }%
2362 \else%
2363 \ifdim\pgf@y=0pt\relax%
2364 \csname pgf@anchor@and gate CDH@east\endcsname%
2365 \else%
2366 \pgfextract@process\externalpoint{\pgfpointadd{\centerpoint}{\externalpoint}}%
2367 \pgf@xc\halfwidth%
2368 \advance\pgf@xc\halfside%
2369 \pgf@yc\halfheight%
2370 \advance\pgf@yc\halfside%
2371 \ifdim\pgf@ya<0pt%
2372 \pgfmathpointintersectionoflineandarc{\externalpoint}{\centerpoint}%
2373 {%
2374 \centerpoint%
2375 \advance\pgf@y\halfside%
2376 \advance\pgf@x\pgf@xb%
2377 }%
2378 {270}{330}{+\pgf@yc}%
2379 \else%
2380 \pgfmathpointintersectionoflineandarc{\externalpoint}{\centerpoint}%
2381 {%
2382 \centerpoint%
2383 \advance\pgf@y-\halfside%
2384 \advance\pgf@x\pgf@xb%
2385 }%
2386 {30}{90}{+\pgf@xc and +\pgf@yc}%
2387 \fi%
2388 \fi%
2389 \fi%
2390 }%
2391 }%
2392
2393
2394 \pgfdeclareshape{nand gate CDH}{%
2395 \expandafter\pgfutil@g@addto@macro\csname pgf@sh@s@nand gate CDH\endcsname{%
2396 \pgf@lib@sh@logicgate@parseinputs{1024}% Maximum 1024 (!) inputs.
2397 %
2398 \pgfmathloop%
2399 \ifnum\pgfmathcounter>\pgf@lib@sh@logicgate@numinputs%
2400 \else%
2401 \pgfutil@ifundefined{pgf@anchor@nand gate CDH@input \pgfmathcounter}{%
2402 \expandafter\xdef\csname pgf@anchor@nand gate CDH@input \pgfmathcounter\endcsname{%
2403 \noexpand\pgf@lib@sh@logicgate@AND@inputanchor{\pgfmathcounter}%
2404 }%
2405 }{}%
2406 \repeatpgfmathloop%
2407 \ifnum\pgf@lib@sh@logicgate@numinputs<2\relax%
2408 \pgferror{A nand gate must have at least two inputs}%
2409 \fi%
2410 }%
2411 \savedmacro\numinputs{\let\numinputs\pgf@lib@sh@logicgate@numinputs}%
2412 \saveddimen\invertedradius{%
2413 \pgfmathsetlength\pgf@x{\pgfkeysvalueof{/pgf/logic gate inverted radius}}%
2414 }%
2415 \saveddimen\outerinvertedradius{%
2416 \pgfmathsetlength\pgf@x{\pgfkeysvalueof{/pgf/logic gate inverted radius}}%
2417 \advance\[email protected]\pgflinewidth%
2418 }%
2419 \savedmacro\dimensions{\pgf@lib@sh@logicgates@dimensions@orUS}%
2420 \savedanchor\centerpoint{%
2421 \[email protected]\wd\pgfnodeparttextbox%
2422 \[email protected]\ht\pgfnodeparttextbox%
2423 \advance\[email protected]\dp\pgfnodeparttextbox%
2424 }%
2425 \savedanchor\midpoint{%
2426 \[email protected]\wd\pgfnodeparttextbox%
2427 \pgfmathsetlength\pgf@y{+0.5ex}%
2428 }%
2429 \savedanchor\basepoint{%
2430 \[email protected]\wd\pgfnodeparttextbox%
2431 \pgf@y0pt%
2432 }%
2433 \anchor{center}{\centerpoint}%
2434 \anchor{mid}{\midpoint}%
2435 \inheritanchor[from=and gate CDH]{mid east}%
2436 \inheritanchor[from=and gate CDH]{mid west}%
2437 \anchor{base}{\basepoint}%%
2438 \inheritanchor[from=and gate CDH]{base east}%
2439 \inheritanchor[from=and gate CDH]{base west}%
2440 \anchor{output}{%
2441 \dimensions
2442 \pgfpointadd{\centerpoint}{%
2443 \pgf@xa\halfside%
2444 \[email protected]\pgf@xa%
2445 \[email protected]\pgf@xa%
2446 \advance\[email protected]\pgf@xb%
2447 \advance\pgf@x\invertedradius%
2448 \advance\pgf@x\outerinvertedradius%
2449 \advance\pgf@x\outerxsep%
2450 \pgf@y0pt%
2451 }%
2452 }%
2453 \inheritanchor[from=and gate CDH]{east}%
2454 \inheritanchor[from=and gate CDH]{north east}%
2455 \inheritanchor[from=and gate CDH]{south east}%
2456 \inheritanchor[from=and gate CDH]{north}%
2457 \inheritanchor[from=and gate CDH]{south}%
2458 \inheritanchor[from=and gate CDH]{south west}%
2459 \inheritanchor[from=and gate CDH]{north west}%
2460 \inheritanchor[from=and gate CDH]{west}%
2461 \backgroundpath{%
2462 \dimensions%
2463 \pgf@xc\halfwidth%
2464 \pgf@yc\halfheight%
2465 \advance\pgf@xc-\outerxsep%
2466 \advance\pgf@yc-\outerysep%
2467 {%
2468 \pgftransformshift{\centerpoint}%
2469 \pgfpathmoveto{\pgfqpoint{-.16666\pgf@xc}{\pgf@yc}}%
2470 {%
2471 \[email protected]\pgf@yc%
2472 \edef\pgf@marshal{%
2473 \noexpand\pgfpatharc{90}{30}{\the\pgf@yc}%
2474 }%
2475 \pgf@marshal%
2476 }
2477 {%
2478 \[email protected]\pgf@yc%
2479 \edef\pgf@marshal{%
2480 \noexpand\pgfpatharc{-30}{-90}{\the\pgf@yc}%
2481 }%
2482 \pgf@marshal%
2483 }
2484 \pgfpathlineto{\pgfqpoint{-1.16666\pgf@xc}{-\pgf@yc}}%
2485 \pgfpathlineto{\pgfqpoint{-1.16666\pgf@xc}{\pgf@yc}}%
2486 \pgfpathclose%
2487 %
2488 % Draw the output inverter.
2489 %
2490 {%
2491 \pgfpathcircle{%
2492 \[email protected]\pgf@xc%
2493 \[email protected]\pgf@yc%
2494 \advance\[email protected]\pgf@yc%
2495 \advance\pgf@x\outerinvertedradius%
2496 \pgf@y0pt%
2497 }{+\invertedradius}%
2498 }%
2499 %
2500 % Draw the inputs.
2501 %
2502 \[email protected]\pgf@yc%
2503 \c@pgf@counta\numinputs%
2504 \advance\c@pgf@counta1\relax%
2505 \divide\pgfutil@tempdima\c@pgf@counta%
2506 \pgfmathloop%
2507 \ifnum\pgfmathcounter>\numinputs%
2508 \else%
2509 \advance\pgf@yc-\pgfutil@tempdima%
2510 \expandafter\ifx\expandafter\pgf@lib@sh@itext\csname input-\pgfmathcounter\endcsname%
2511 {%
2512 \pgfpathcircle{%
2513 \pgf@xa\halfside%
2514 \[email protected]\pgf@xa%
2515 \advance\[email protected]\pgflinewidth%
2516 \advance\pgf@x-\invertedradius%
2517 \pgf@y\pgf@yc%
2518 }{+\invertedradius}%
2519 }%
2520 \fi%
2521 \repeatpgfmathloop%
2522 }%
2523 }%
2524 \inheritanchorborder[from=and gate CDH]%
2525 }%