diff options
Diffstat (limited to 'Build/source/utils/asymptote/base/plain_arrows.asy')
-rw-r--r-- | Build/source/utils/asymptote/base/plain_arrows.asy | 115 |
1 files changed, 88 insertions, 27 deletions
diff --git a/Build/source/utils/asymptote/base/plain_arrows.asy b/Build/source/utils/asymptote/base/plain_arrows.asy index 490f76f777c..59b65aa4126 100644 --- a/Build/source/utils/asymptote/base/plain_arrows.asy +++ b/Build/source/utils/asymptote/base/plain_arrows.asy @@ -469,30 +469,87 @@ void draw(frame f, path g, pen p=currentpen, arrowbar arrow) add(f,pic.fit()); } -void draw(picture pic=currentpicture, Label L="", path g, align align=NoAlign, - pen p=currentpen, arrowbar arrow=None, arrowbar bar=None, - margin margin=NoMargin, Label legend="", marker marker=nomarker) -{ - Label L=L.copy(); - L.align(align); - if(marker != nomarker && !marker.above) marker.mark(pic,g); - bool drawpath=arrow(pic,g,p,margin); - if(bar(pic,g,p,margin) && drawpath) _draw(pic,g,p,margin); - if(L.s != "") { - L.p(p); - L.out(pic,g); +void draw(picture pic=currentpicture, Label L=null, path g, + align align=NoAlign, pen p=currentpen, arrowbar arrow=None, + arrowbar bar=None, margin margin=NoMargin, Label legend=null, + marker marker=nomarker) +{ + // These if statements are ordered in such a way that the most common case + // (with just a path and a pen) executes the least bytecode. + if (marker == nomarker) + { + if (arrow == None && bar == None) + { + if (margin == NoMargin && size(nib(p)) == 0) + { + pic.addExactAbove( + new void(frame f, transform t, transform T, pair, pair) { + _draw(f,t*T*g,p); + }); + pic.addPath(g,p); + + // Jumping over else clauses takes time, so test if we can return + // here. + if (L == null && legend == null) + return; + } + else // With margin or polygonal pen. + { + _draw(pic, g, p, margin); + } + } + else /* arrow or bar */ + { + // Note we are using & instead of && as both arrow and bar need to be + // called. + if (arrow(pic, g, p, margin) & bar(pic, g, p, margin)) + _draw(pic, g, p, margin); + } + + if(L != null && L.s != "") { + L=L.copy(); + L.align(align); + L.p(p); + L.out(pic,g); + } + + if(legend != null && legend.s != "") { + legend.p(p); + pic.legend.push(Legend(legend.s,legend.p,p,marker.f,marker.above)); + } } - if(legend.s != "") { - legend.p(p); - pic.legend.push(Legend(legend.s,legend.p,p,marker.f,marker.above)); + else /* marker != nomarker */ + { + if(marker != nomarker && !marker.above) marker.mark(pic,g); + + // Note we are using & instead of && as both arrow and bar need to be + // called. + if ((arrow == None || arrow(pic, g, p, margin)) & + (bar == None || bar(pic, g, p, margin))) + { + _draw(pic, g, p, margin); + } + + if(L != null && L.s != "") { + L=L.copy(); + L.align(align); + L.p(p); + L.out(pic,g); + } + + if(legend != null && legend.s != "") { + legend.p(p); + pic.legend.push(Legend(legend.s,legend.p,p,marker.f,marker.above)); + } + + if(marker != nomarker && marker.above) marker.mark(pic,g); } - if(marker != nomarker && marker.above) marker.mark(pic,g); } // Draw a fixed-size line about the user-coordinate 'origin'. -void draw(pair origin, picture pic=currentpicture, Label L="", path g, +void draw(pair origin, picture pic=currentpicture, Label L=null, path g, align align=NoAlign, pen p=currentpen, arrowbar arrow=None, - arrowbar bar=None, margin margin=NoMargin, Label legend="", + arrowbar bar=None, margin margin=NoMargin, Label legend=null, marker marker=nomarker) { picture opic; @@ -501,21 +558,22 @@ void draw(pair origin, picture pic=currentpicture, Label L="", path g, } void draw(picture pic=currentpicture, explicit path[] g, pen p=currentpen, - Label legend="", marker marker=nomarker) + Label legend=null, marker marker=nomarker) { + // This could be optimized to size and draw the entire array as a batch. for(int i=0; i < g.length-1; ++i) draw(pic,g[i],p,marker); if(g.length > 0) draw(pic,g[g.length-1],p,legend,marker); } void draw(picture pic=currentpicture, guide[] g, pen p=currentpen, - Label legend="", marker marker=nomarker) + Label legend=null, marker marker=nomarker) { draw(pic,(path[]) g,p,legend,marker); } void draw(pair origin, picture pic=currentpicture, explicit path[] g, - pen p=currentpen, Label legend="", marker marker=nomarker) + pen p=currentpen, Label legend=null, marker marker=nomarker) { picture opic; draw(opic,g,p,legend,marker); @@ -523,21 +581,23 @@ void draw(pair origin, picture pic=currentpicture, explicit path[] g, } void draw(pair origin, picture pic=currentpicture, guide[] g, pen p=currentpen, - Label legend="", marker marker=nomarker) + Label legend=null, marker marker=nomarker) { draw(origin,pic,(path[]) g,p,legend,marker); } // Align an arrow pointing to b from the direction dir. The arrow is // 'length' PostScript units long. -void arrow(picture pic=currentpicture, Label L="", pair b, pair dir, +void arrow(picture pic=currentpicture, Label L=null, pair b, pair dir, real length=arrowlength, align align=NoAlign, pen p=currentpen, arrowbar arrow=Arrow, margin margin=EndMargin) { - Label L=L.copy(); - if(L.defaultposition) L.position(0); - L.align(L.align,dir); - L.p(p); + if(L != null && L.s != "") { + L=L.copy(); + if(L.defaultposition) L.position(0); + L.align(L.align,dir); + L.p(p); + } marginT margin=margin(b--b,p); // Extract margin.begin and margin.end pair a=(margin.begin+length+margin.end)*unit(dir); draw(b,pic,L,a--(0,0),align,p,arrow,margin); @@ -562,6 +622,7 @@ frame[] fit2(picture[] pictures, picture all) } // Fit an array of pictures simultaneously using the size of the first picture. +// TODO: Remove unused arguments. frame[] fit(string prefix="", picture[] pictures, string format="", bool view=true, string options="", string script="", projection P=currentprojection) |