From: W. Trevor King Date: Mon, 30 Apr 2012 18:05:45 +0000 (-0400) Subject: Factor out _two_terminal_circle() from source() and lamp() in Circ.asy. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=1a9c9b7277bdafbf389134e18bc5b0c3660dc722;p=course.git Factor out _two_terminal_circle() from source() and lamp() in Circ.asy. This will make implementing future circle-based symbols easier (for example, motors, voltmeters, ammeters, etc.). Note that we don't use `unitcircle` because that would create a closed path, and TwoTerminal fills in all closed paths. --- diff --git a/asymptote/Circ.asy b/asymptote/Circ.asy index fac3337..7f6cc91 100644 --- a/asymptote/Circ.asy +++ b/asymptote/Circ.asy @@ -507,44 +507,61 @@ TwoTerminal current(pair beg=(0,0), real ang=0, string name="", string val="", return term; } +//--- Circle-based symbols (for internal use) -- + +real circle_size=6mm; + +TwoTerminal _two_terminal_circle(pair beg=(0,0), real ang=0, string name="", + string val="") +{ + path pLine[]={}, pMisc[]={}; + real len, lchar, lcharv, r = circle_size/2; + pair c = (2r,0); + TwoTerminal term; + + len = 2*circle_size; + lchar = lcharv = r; + c = (circle_size, 0); + pLine.push((0,0)--(r,0)); + pLine.push(shift(c)*scale(r)*(E..N..W..S..E)); + pLine.push((3r,0)--(4r,0)); + term = TwoTerminal(beg, len, ang, lchar, lcharv, name, val, pLine, pMisc); + return term; +} + //--- Sources (fuentes de alimentaci'on) --- -real ssize=6mm; int AC=0,DC=1,I=2,V=3; TwoTerminal source(pair beg=(0,0), real ang=0, int type=AC, string name="", - string val="", bool draw=true) + string val="", bool draw=true) { - path pLine[]={}, pMisc[]={}; - real len, lchar, lcharv; TwoTerminal term; - if (type == AC || type == I || type == V) { - len = 2ssize; - lchar = 0.5ssize; lcharv = 0.5ssize; - pLine.push((0,0)--(.5ssize,0)); - pLine.push(shift((ssize,0))*scale(ssize/2)*(E..N..W..S..E)); - pLine.push((1.5ssize,0)--(2ssize,0)); + real s = circle_size; + term = _two_terminal_circle(beg=beg, ang=ang, name=name, val=val); if (type == AC) { - pLine.push((2ssize/3,0ssize){NE}..{E}((1/3+.5)*ssize,.2ssize)..{SE}(ssize,0)..{E}((2/3+.5)*ssize,-.2ssize)..{NE}(4ssize/3,0)); + term.pLine.push((2s/3,0){NE}..{E}((1/3+.5)*s,.2s)..{SE}(s,0)..{E}((2/3+.5)*s,-.2s)..{NE}(4s/3,0)); } else if (type == I) { - pLine.push((2ssize/3,0)--(4ssize/3,0)); - pLine.push(fullhead(pLine[3], 4ssize/15, 30)); + term.pLine.push((2s/3,0)--(4s/3,0)); + term.pLine.push(fullhead(term.pLine[3], 4s/15, 30)); } else if (type == V) { - pLine.push((1.05ssize,0)--(1.45ssize,0)); - pLine.push((1.25ssize,-.2ssize)--(1.25ssize,.2ssize)); - pLine.push((.95ssize,0)--(.55ssize,0)); + term.pLine.push((1.05s,0)--(1.45s,0)); + term.pLine.push((1.25s,-.2s)--(1.25s,.2s)); + term.pLine.push((.95s,0)--(.55s,0)); } } else if (type == DC) { - len = ssize; - lchar = 0.6ssize; lcharv = .6ssize; - pLine.push((0,0)--(0.4ssize,0)); - pLine.push((.6ssize,0)--(ssize,0)); - pLine.push((.4ssize,-.2ssize)--(.4ssize,.2ssize)); - pLine.push((.6ssize,-.6ssize)--(.6ssize,.6ssize)); + path pLine[] = {}; + real len, lchar, lcharv; + len = circle_size; + lchar = 0.6len; lcharv = .6len; + pLine.push((0,0)--(0.4len,0)); + pLine.push((.6len,0)--(len,0)); + pLine.push((.4len,-.2len)--(.4len,.2len)); + pLine.push((.6len,-.6len)--(.6len,.6len)); + term = TwoTerminal(beg, len, ang, lchar, lcharv, name, val, pLine); } - term = TwoTerminal(beg, len, ang, lchar, lcharv, name, val, pLine, pMisc); if (draw == true) term.draw(); return term; @@ -869,32 +886,25 @@ enddef; */ -real lampsize = ssize; int illuminating = 1; TwoTerminal lamp(pair beg=(0,0), real ang=0, int type=normal, string name="", string val="", bool draw=true) { - path pLine[]={}, pMisc[]={}; - real len, lchar, lcharv, r = 0.5*lampsize; - pair c = (2r,0); + real r = 0.5*circle_size; + pair c; TwoTerminal term; - len = 2*lampsize; - lchar = lcharv = r; - c = (lampsize, 0); - pLine.push((0,0)--(r,0)); - pLine.push(shift(c)*scale(r)*(E..N..W..S..E)); - pLine.push((1.5*lampsize,0)--(2*lampsize,0)); + term = _two_terminal_circle(beg=beg, ang=ang, name=name, val=val); + pair c = (2r, 0); if (type==normal) { - pLine.push((c - r*dir(45)) -- (c + r*dir(45))); - pLine.push((c - r*dir(-45)) -- (c + r*dir(-45))); + term.pLine.push((c - r*dir(45)) -- (c + r*dir(45))); + term.pLine.push((c - r*dir(-45)) -- (c + r*dir(-45))); } else if (type==illuminating) { - pLine.push((c - (r,0)) -- (c - (r/2,0))); - pLine.push((c + (r/2,0)) -- (c + (r,0))); - pLine.push(shift(c)*scale(r/2)*(E..N..W)); + term.pLine.push((c - (r,0)) -- (c - (r/2,0))); + term.pLine.push((c + (r/2,0)) -- (c + (r,0))); + term.pLine.push(shift(c)*scale(r/2)*(E..N..W)); } - term = TwoTerminal(beg, len, ang, lchar, lcharv, name, val, pLine, pMisc); if (draw == true) term.draw(); return term;