diff options
Diffstat (limited to 'Master/texmf/asymptote/plain_picture.asy')
-rw-r--r-- | Master/texmf/asymptote/plain_picture.asy | 112 |
1 files changed, 86 insertions, 26 deletions
diff --git a/Master/texmf/asymptote/plain_picture.asy b/Master/texmf/asymptote/plain_picture.asy index e13120a198c..044ba90e7a7 100644 --- a/Master/texmf/asymptote/plain_picture.asy +++ b/Master/texmf/asymptote/plain_picture.asy @@ -4,11 +4,6 @@ pair viewportsize=0; // Horizontal and vertical viewport limits. restricted bool Aspect=true; restricted bool IgnoreAspect=false; -pair size(frame f) -{ - return max(f)-min(f); -} - typedef real[][] transform3; restricted transform3 identity4=identity(4); @@ -360,6 +355,7 @@ pair point(frame f, pair dir) path[] align(path[] g, transform t=identity(), pair position, pair align, pen p=currentpen) { + if(g.length == 0) return g; pair m=min(g); pair M=max(g); pair dir=rectify(inverse(t)*-align); @@ -385,18 +381,15 @@ struct transformation { transform3 modelview; // For orientation and positioning transform3 projection; // For 3D to 2D projection bool infinity; - bool oblique; - void operator init(transform3 modelview, bool oblique=false) { + void operator init(transform3 modelview) { this.modelview=modelview; this.projection=identity4; infinity=true; - this.oblique=oblique; } void operator init(transform3 modelview, transform3 projection) { this.modelview=modelview; this.projection=projection; infinity=false; - oblique=false; } transform3 compute() { return infinity ? modelview : projection*modelview; @@ -406,7 +399,6 @@ struct transformation { T.modelview=copy(modelview); T.projection=copy(projection); T.infinity=infinity; - T.oblique=oblique; return T; } } @@ -414,11 +406,11 @@ struct transformation { struct projection { transform3 t; // projection*modelview (cached) bool infinity; - bool oblique; bool absolute=false; triple camera; // Position of camera. triple up; // A vector that should be projected to direction (0,1). triple target; // Point where camera is looking at. + triple normal; // Normal vector from target to projection plane. pair viewportshift; // Fractional viewport shift. real zoom=1; // Zoom factor. real angle; // Lens angle (for perspective projection). @@ -434,7 +426,6 @@ struct projection { T=projector(camera,up,target); t=T.compute(); infinity=T.infinity; - oblique=T.oblique; ninterpolate=infinity ? 1 : 16; } @@ -443,12 +434,14 @@ struct projection { } void operator init(triple camera, triple up=(0,0,1), triple target=(0,0,0), + triple normal=camera-target, real zoom=1, real angle=0, pair viewportshift=0, bool showtarget=true, bool autoadjust=true, bool center=false, projector projector) { this.camera=camera; this.up=up; this.target=target; + this.normal=normal; this.zoom=zoom; this.angle=angle; this.viewportshift=viewportshift; @@ -464,10 +457,10 @@ struct projection { P.t=t; P.infinity=infinity; P.absolute=absolute; - P.oblique=oblique; P.camera=camera; P.up=up; P.target=target; + P.normal=normal; P.zoom=zoom; P.angle=angle; P.viewportshift=viewportshift; @@ -1281,7 +1274,7 @@ struct picture { } - // Calculate additional scaling required if only an approximate thisture + // Calculate additional scaling required if only an approximate picture // size estimate is available. transform3 scale3(frame f, real xsize3=this.xsize3, real ysize3=this.ysize3, real zsize3=this.zsize3, @@ -1370,6 +1363,18 @@ struct picture { light,P); } + // Fit a 3D picture. + frame fit3(projection P=currentprojection) { + if(settings.render == 0) return fit(P); + if(fixed) return scaled(); + if(empty3()) return newframe; + transform3 t=scaling(xsize3,ysize3,zsize3,keepAspect); + frame f=fit3(t,null,P); + transform3 s=scale3(f,xsize3,ysize3,zsize3,keepAspect); + if(s == identity4) return f; + return fit3(s*t,null,P); + } + // In case only an approximate picture size estimate is available, return the // fitted frame slightly scaled (including labels and true size distances) // so that it precisely meets the given size specification. @@ -1567,12 +1572,24 @@ void add(picture pic=currentpicture, drawer d, bool exact=false) pic.add(d,exact); } +typedef void drawer3(frame f, transform3 t, picture pic, projection P); +void add(picture pic=currentpicture, drawer3 d, bool exact=false) +{ + pic.add(d,exact); +} + void add(picture pic=currentpicture, void d(picture,transform), bool exact=false) { pic.add(d,exact); } +void add(picture pic=currentpicture, void d(picture,transform3), + bool exact=false) +{ + pic.add(d,exact); +} + void begingroup(picture pic=currentpicture) { pic.add(new void(frame f, transform) { @@ -1628,7 +1645,7 @@ void latticeshade(picture pic=currentpicture, path[] g, bool stroke=false, p=copy(p); } pic.add(new void(frame f, transform t) { - latticeshade(f,t*g,stroke,fillrule,p,false); + latticeshade(f,t*g,stroke,fillrule,p,t,false); },true); pic.addPath(g); } @@ -1738,7 +1755,8 @@ void tensorshade(picture pic=currentpicture, path[] g, bool stroke=false, // Smoothly shade the regions between consecutive paths of a sequence using a // given array of pens: -void draw(picture pic=currentpicture, path[] g, pen[] p) +void draw(picture pic=currentpicture, path[] g, pen fillrule=currentpen, + pen[] p) { path[] G; pen[][] P; @@ -1753,7 +1771,7 @@ void draw(picture pic=currentpicture, path[] g, pen[] p) P.push(new pen[] {p[i],p[i],p[i+1],p[i+1]}); } } - tensorshade(pic,G,P); + tensorshade(pic,G,fillrule,P); } void functionshade(picture pic=currentpicture, path[] g, bool stroke=false, @@ -1842,14 +1860,14 @@ transform fixedscaling(picture pic=currentpicture, pair min, pair max, pic.keepAspect); } -// Add frame src about position to frame dest with optional grouping. +// Add frame src to frame dest about position with optional grouping. void add(frame dest, frame src, pair position, bool group=false, filltype filltype=NoFill, bool above=true) { add(dest,shift(position)*src,group,filltype,above); } -// Add frame src about position to picture dest with optional grouping. +// Add frame src to picture dest about position with optional grouping. void add(picture dest=currentpicture, frame src, pair position=0, bool group=true, filltype filltype=NoFill, bool above=true) { @@ -1883,7 +1901,14 @@ void add(picture dest=currentpicture, frame src, pair position, pair align, add(dest,align(src,align),position,group,filltype,above); } -// Like attach(picture,frame,pair) but extend picture to accommodate frame; +// Like add(frame,frame,pair) but align frame in direction align. +void add(frame dest, frame src, pair position, pair align, + bool group=true, filltype filltype=NoFill, bool above=true) +{ + add(dest,align(src,align),position,group,filltype,above); +} + +// Like add(picture,frame,pair,pair) but extend picture to accommodate frame; void attach(picture dest=currentpicture, frame src, pair position, pair align, bool group=true, filltype filltype=NoFill, bool above=true) @@ -1935,22 +1960,29 @@ void postscript(picture pic=currentpicture, string s) },true); } -void tex(picture pic=currentpicture, string s) +void postscript(picture pic=currentpicture, string s, pair min, pair max) { - pic.add(new void(frame f, transform) { - tex(f,s); + pic.add(new void(frame f, transform t) { + postscript(f,s,t*min,t*max); },true); } -void postscript(picture pic=currentpicture, string s, pair min, pair max) +void tex(picture pic=currentpicture, string s) { - pic.add(new void(frame f, transform t) { - postscript(f,s,t*min,t*max); + // Force TeX string s to be evaluated immediately (in case it is a macro). + frame g; + tex(g,s); + size(g); + pic.add(new void(frame f, transform) { + tex(f,s); },true); } void tex(picture pic=currentpicture, string s, pair min, pair max) { + frame g; + tex(g,s); + size(g); pic.add(new void(frame f, transform t) { tex(f,s,t*min,t*max); },true); @@ -1968,3 +2000,31 @@ void erase(picture pic=currentpicture) pic.uptodate=false; pic.erase(); } + +void begin(picture pic=currentpicture, string name, string id="", + bool visible=true) +{ + if(!latex() || !pdf()) return; + settings.twice=true; + if(id == "") id=string(++ocgindex); + tex(pic,"\begin{ocg}{"+name+"}{"+id+"}{"+(visible ? "1" : "0")+"}"); + layer(pic); +} + +void end(picture pic=currentpicture) +{ + if(!latex() || !pdf()) return; + tex(pic,"\end{ocg}"); + layer(pic); +} + +// For users of the LaTeX babel package. +void deactivatequote(picture pic=currentpicture) +{ + tex(pic,"\catcode`\"=12"); +} + +void activatequote(picture pic=currentpicture) +{ + tex(pic,"\catcode`\"=13"); +} |