summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/asymptote/three.asy
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/asymptote/three.asy')
-rw-r--r--Master/texmf-dist/asymptote/three.asy47
1 files changed, 20 insertions, 27 deletions
diff --git a/Master/texmf-dist/asymptote/three.asy b/Master/texmf-dist/asymptote/three.asy
index 75f758dd353..5fc0d2f1096 100644
--- a/Master/texmf-dist/asymptote/three.asy
+++ b/Master/texmf-dist/asymptote/three.asy
@@ -1065,7 +1065,7 @@ triple dir(path3 p)
triple dir(path3 p, path3 h)
{
- return 0.5*(dir(p)+dir(h));
+ return unit(dir(p)+dir(h));
}
// return the point on path3 p at arclength L
@@ -1880,6 +1880,14 @@ transform3 align(triple u)
return c >= 0 ? identity(4) : diagonal(1,-1,-1,1);
}
+// Align Label with normal in direction dir.
+Label align(Label L, triple dir)
+{
+ Label L=L.copy();
+ L.transform3(align(unit(dir)));
+ return L;
+}
+
// return a rotation that maps X,Y to the projection plane.
transform3 transform3(projection P=currentprojection)
{
@@ -2554,25 +2562,6 @@ private string Format(transform3 t, string sep=" ")
Format(t[0][3])+sep+Format(t[1][3])+sep+Format(t[2][3]);
}
-void writeJavaScript(string name, string preamble, string script)
-{
- file out=output(name);
- write(out,preamble);
- if(script != "") {
- write(out,endl);
- file in=input(script);
- while(true) {
- string line=in;
- if(eof(in)) break;
- write(out,line,endl);
- }
- }
- close(out);
- if(settings.verbose > 1) write("Wrote "+name);
- if(!settings.inlinetex)
- file3.push(name);
-}
-
pair viewportmargin(pair lambda)
{
return maxbound(0.5*(viewportsize-lambda),viewportmargin);
@@ -2593,7 +2582,7 @@ string embed3D(string prefix, string label=prefix, string text=label,
if(script == "") script=defaultembed3Dscript;
if(P.infinity) {
- if(viewplanesize==0) {
+ if(viewplanesize == 0) {
triple lambda=max3(f)-min3(f);
pair margin=viewportmargin((lambda.x,lambda.y));
viewplanesize=(max(lambda.x+2*margin.x,lambda.y+2*margin.y))/P.zoom;
@@ -2645,6 +2634,7 @@ struct scene
pair viewportmargin;
transform3 T=identity4;
picture pic2;
+ bool keepAspect=true;
void operator init(frame f, real width, real height,
projection P=currentprojection) {
@@ -2660,6 +2650,7 @@ struct scene
projection P=currentprojection) {
real xsize3=pic.xsize3, ysize3=pic.ysize3, zsize3=pic.zsize3;
bool warn=true;
+ this.keepAspect=keepAspect;
if(xsize3 == 0 && ysize3 == 0 && zsize3 == 0) {
xsize3=ysize3=zsize3=max(xsize,ysize);
@@ -2678,18 +2669,18 @@ struct scene
if(!P.absolute) {
this.P=t*P;
+ if(this.P.autoadjust || this.P.infinity)
+ adjusted=adjusted | this.P.adjust(m,M);
if(this.P.center && settings.render != 0) {
triple target=0.5*(m+M);
this.P.target=target;
this.P.calculate();
}
- if(this.P.autoadjust || this.P.infinity)
- adjusted=adjusted | this.P.adjust(m,M);
}
bool scale=xsize != 0 || ysize != 0;
bool scaleAdjust=scale && this.P.autoadjust;
- bool noAdjust=(this.P.absolute || !scaleAdjust);
+ bool noAdjust=this.P.absolute || !scaleAdjust;
if(pic.bounds3.exact && noAdjust)
this.P.bboxonly=false;
@@ -2812,9 +2803,11 @@ object embed(string prefix=outprefix(), string label=prefix,
triple m=min3(S.f);
triple M=max3(S.f);
triple lambda=M-m;
- S.viewportmargin=viewportmargin((lambda.x,lambda.y));
- S.width=ceil(lambda.x+2*S.viewportmargin.x);
- S.height=ceil(lambda.y+2*S.viewportmargin.y);
+ if(S.keepAspect) {
+ S.viewportmargin=viewportmargin((lambda.x,lambda.y));
+ S.width=ceil(lambda.x+2*S.viewportmargin.x);
+ S.height=ceil(lambda.y+2*S.viewportmargin.y);
+ }
orthoshift=(-0.5(m.x+M.x),-0.5*(m.y+M.y),0);
S.f=shift(orthoshift)*S.f; // Eye will be at (0,0,0)
inv=inverse(modelview);