diff options
Diffstat (limited to 'graphics/asymptote/base')
-rw-r--r-- | graphics/asymptote/base/bezulate.asy | 2 | ||||
-rw-r--r-- | graphics/asymptote/base/contour.asy | 31 | ||||
-rw-r--r-- | graphics/asymptote/base/palette.asy | 10 | ||||
-rw-r--r-- | graphics/asymptote/base/plain_boxes.asy | 3 | ||||
-rw-r--r-- | graphics/asymptote/base/rationalSimplex.asy | 71 | ||||
-rw-r--r-- | graphics/asymptote/base/simplex.asy | 54 | ||||
-rw-r--r-- | graphics/asymptote/base/three.asy | 14 |
7 files changed, 103 insertions, 82 deletions
diff --git a/graphics/asymptote/base/bezulate.asy b/graphics/asymptote/base/bezulate.asy index 756ee00ac3..e09b86ed25 100644 --- a/graphics/asymptote/base/bezulate.asy +++ b/graphics/asymptote/base/bezulate.asy @@ -1,6 +1,6 @@ // Bezier triangulation routines written by Orest Shardt, 2008. -private real fuzz=sqrtEpsilon; +private real fuzz=1e-6; real duplicateFuzz=1e-3; // Work around font errors. real maxrefinements=10; diff --git a/graphics/asymptote/base/contour.asy b/graphics/asymptote/base/contour.asy index f2ee0e78fe..8c6dbba86b 100644 --- a/graphics/asymptote/base/contour.asy +++ b/graphics/asymptote/base/contour.asy @@ -176,7 +176,8 @@ private void collect(pair[][][] points, real[] c) } // Join path segments. -private guide[][] connect(pair[][][] points, real[] c, interpolate join) +private guide[][] connect(picture pic, pair[][][] points, real[] c, + interpolate join) { // set up return value guide[][] result=new guide[c.length][]; @@ -189,13 +190,13 @@ private guide[][] connect(pair[][][] points, real[] c, interpolate join) if(pts.length > 0) { if(pts.length > 1 && abs(pts[0]-pts[pts.length-1]) < eps) { guide[] g=sequence(new guide(int i) { - return pts[i]; + return (pic.scale.x.T(pts[i].x), pic.scale.y.T(pts[i].y)); },pts.length-1); g.push(cycle); gd=join(...g); } else gd=join(...sequence(new guide(int i) { - return pts[i]; + return (pic.scale.x.T(pts[i].x), pic.scale.y.T(pts[i].y)); },pts.length)); } resultcnt[i]=gd; @@ -211,7 +212,7 @@ private guide[][] connect(pair[][][] points, real[] c, interpolate join) // midpoint: optional array containing values of f at cell midpoints // c: array of contour values // join: interpolation operator (e.g. operator -- or operator ..) -guide[][] contour(pair[][] z, real[][] f, +guide[][] contour(picture pic=currentpicture, pair[][] z, real[][] f, real[][] midpoint=new real[][], real[] c, interpolate join=operator --) { @@ -445,7 +446,7 @@ guide[][] contour(pair[][] z, real[][] f, collect(points,c); // Required to join remaining case1 cycles. - return connect(points,c,join); + return connect(pic,points,c,join); } // Return contour guides for a 2D data array on a uniform lattice @@ -454,8 +455,8 @@ guide[][] contour(pair[][] z, real[][] f, // a,b: diagonally opposite vertices of rectangular domain // c: array of contour values // join: interpolation operator (e.g. operator -- or operator ..) -guide[][] contour(real[][] f, real[][] midpoint=new real[][], - pair a, pair b, real[] c, +guide[][] contour(picture pic=currentpicture, real[][] f, + real[][] midpoint=new real[][], pair a, pair b, real[] c, interpolate join=operator --) { int nx=f.length-1; @@ -473,7 +474,7 @@ guide[][] contour(real[][] f, real[][] midpoint=new real[][], zi[j]=(xi,interp(a.y,b.y,j/ny)); } } - return contour(z,f,midpoint,c,join); + return contour(pic,z,f,midpoint,c,join); } // return contour guides for a real-valued function @@ -482,8 +483,8 @@ guide[][] contour(real[][] f, real[][] midpoint=new real[][], // c: array of contour values // nx,ny: number of subdivisions in x and y directions (determines accuracy) // join: interpolation operator (e.g. operator -- or operator ..) -guide[][] contour(real f(real, real), pair a, pair b, - real[] c, int nx=ngraph, int ny=nx, +guide[][] contour(picture pic=currentpicture, real f(real, real), pair a, + pair b, real[] c, int nx=ngraph, int ny=nx, interpolate join=operator --) { // evaluate function at points and midpoints @@ -501,7 +502,7 @@ guide[][] contour(real f(real, real), pair a, pair b, } } - return contour(dat,midpoint,a,b,c,join); + return contour(pic,dat,midpoint,a,b,c,join); } void draw(picture pic=currentpicture, Label[] L=new Label[], @@ -648,14 +649,14 @@ private void addseg(pair[][] gds, segment seg) return; } -guide[][] contour(real f(pair), pair a, pair b, +guide[][] contour(picture pic=currentpicture, real f(pair), pair a, pair b, real[] c, int nx=ngraph, int ny=nx, interpolate join=operator --) { - return contour(new real(real x, real y) {return f((x,y));},a,b,c,nx,ny,join); + return contour(pic,new real(real x, real y) {return f((x,y));},a,b,c,nx,ny,join); } -guide[][] contour(pair[] z, real[] f, real[] c, interpolate join=operator --) +guide[][] contour(picture pic=currentpicture, pair[] z, real[] f, real[] c, interpolate join=operator --) { if(z.length != f.length) abort("z and f arrays have different lengths"); @@ -678,5 +679,5 @@ guide[][] contour(pair[] z, real[] f, real[] c, interpolate join=operator --) collect(points,c); - return connect(points,c,join); + return connect(pic,points,c,join); } diff --git a/graphics/asymptote/base/palette.asy b/graphics/asymptote/base/palette.asy index e3d6218312..9923e5b3aa 100644 --- a/graphics/asymptote/base/palette.asy +++ b/graphics/asymptote/base/palette.asy @@ -190,8 +190,8 @@ bounds image(picture pic=currentpicture, pair[] z, real[] f, real rmax=pic.scale.z.T(bounds.max); palette=adjust(pic,m,M,rmin,rmax,palette); - rmin=max(rmin,m); - rmax=min(rmax,M); + rmin=max(rmin,pic.scale.z.T(m)); + rmax=min(rmax,pic.scale.z.T(M)); // Crop data to allowed range and scale if(range != Full || pic.scale.z.scale.T != identity || @@ -201,6 +201,12 @@ bounds image(picture pic=currentpicture, pair[] z, real[] f, real M=bounds.max; f=map(new real(real x) {return T(min(max(x,m),M));},f); } + if(pic.scale.x.scale.T != identity || pic.scale.x.postscale.T != identity || + pic.scale.y.scale.T != identity || pic.scale.y.postscale.T != identity) { + scalefcn Tx=pic.scale.x.T; + scalefcn Ty=pic.scale.y.T; + z=map(new pair(pair z) {return (Tx(z.x),Ty(z.y));},z); + } int[] edges={0,0,1}; int N=palette.length-1; diff --git a/graphics/asymptote/base/plain_boxes.asy b/graphics/asymptote/base/plain_boxes.asy index c675ab4cde..50501a4089 100644 --- a/graphics/asymptote/base/plain_boxes.asy +++ b/graphics/asymptote/base/plain_boxes.asy @@ -20,7 +20,6 @@ path roundbox(frame dest, frame src=dest, real xmargin=0, real ymargin=xmargin, pair m=min(src); pair M=max(src); pair bound=M-m; - int sign=filltype == NoFill ? 1 : -1; real a=bound.x+2*xmargin; real b=bound.y+2*ymargin; real ds=0; @@ -90,7 +89,7 @@ object object(Label L, envelope e, real xmargin=0, real ymargin=xmargin, L0.position(0); L0.p(p); add(F.f,L0); - F.g=e(F.f,xmargin,ymargin,p,filltype); + F.g=e(F.f,xmargin,ymargin,p,filltype,above); return F; } diff --git a/graphics/asymptote/base/rationalSimplex.asy b/graphics/asymptote/base/rationalSimplex.asy index 6070c7cbdb..3a376ba2dd 100644 --- a/graphics/asymptote/base/rationalSimplex.asy +++ b/graphics/asymptote/base/rationalSimplex.asy @@ -38,6 +38,7 @@ struct simplex { rational[] xStandard; rational cost; rational[] d; + bool dual=false; int m,n; int J; @@ -72,7 +73,7 @@ struct simplex { int iterate(rational[][] E, int N, int[] Bindices) { while(true) { - // Find first negative entry in bottom (reduced cost) row + // Bland's rule: first negative entry in reduced cost (bottom) row enters rational[] Em=E[m]; for(J=1; J <= N; ++J) if(Em[J] < 0) break; @@ -96,7 +97,7 @@ struct simplex { rational r=E[i][0]/u; if(r <= t && (r < t || Bindices[i] < Bindices[I])) { t=r; I=i; - } // Bland's rule: exiting variable has smallest minimizing index + } // Bland's rule: exiting variable has smallest minimizing subscript } } if(I == -1) @@ -113,8 +114,7 @@ struct simplex { int iterateDual(rational[][] E, int N, int[] Bindices) { while(true) { - // Find first negative entry in zeroth (basic variable) column - rational[] Em=E[m]; + // Bland's rule: negative variable with smallest subscript exits int I; for(I=0; I < m; ++I) { if(E[I][0] < 0) break; @@ -123,23 +123,30 @@ struct simplex { if(I == m) break; + for(int i=I+1; i < m; ++i) { + if(E[i][0] < 0 && Bindices[i] < Bindices[I]) + I=i; + } + + rational[] Em=E[m]; + rational[] EI=E[I]; int J=0; rational t; for(int j=1; j <= N; ++j) { - rational u=E[I][j]; + rational u=EI[j]; if(u < 0) { - t=-E[m][j]/u; + t=-Em[j]/u; J=j; break; } } for(int j=J+1; j <= N; ++j) { - rational u=E[I][j]; + rational u=EI[j]; if(u < 0) { - rational r=-E[m][j]/u; + rational r=-Em[j]/u; if(r <= t && (r < t || j < J)) { t=r; J=j; - } // Bland's rule: exiting variable has smallest minimizing index + } // Bland's rule: smallest minimizing subscript enters } } if(J == 0) @@ -159,8 +166,7 @@ struct simplex { // b is a vector of length m, and c is a vector of length n. // Can set phase1=false if the last m columns of A form the identity matrix. void operator init(rational[] c, rational[][] A, rational[] b, - bool phase1=true, bool dual=false) { - if(dual) phase1=false; + bool phase1=true) { // Phase 1 m=A.length; if(m == 0) {case=INFEASIBLE; return;} @@ -245,7 +251,7 @@ struct simplex { simplexPhase1(c,A,b,Bindices); iterate(E,n+k,Bindices); - + if(Em[0] != 0) { simplexTableau(E,Bindices); case=INFEASIBLE; @@ -280,7 +286,7 @@ struct simplex { for(int i=0; i < m; ++i) { int k=Bindices[i]; if(k > n) continue; - Bindices[ip]=k; + Bindices[ip]=k; cB[ip]=c[k-1]; rational[] Dip=D[ip]; rational[] Ei=E[i]; @@ -322,12 +328,14 @@ struct simplex { case=(dual ? iterateDual : iterate)(D,n,Bindices); simplexTableau(D,Bindices); - x=new rational[n]; - for(int j=0; j < n; ++j) - x[j]=0; + if(case != INFEASIBLE) { + x=new rational[n]; + for(int j=0; j < n; ++j) + x[j]=0; - for(int k=0; k < m; ++k) - x[Bindices[k]-1]=D[k][0]; + for(int k=0; k < m; ++k) + x[Bindices[k]-1]=D[k][0]; + } if(case == UNBOUNDED) { d=new rational[n]; @@ -366,21 +374,21 @@ struct simplex { ai[j]=Ai[j]; } } - + int k=0; bool phase1=false; - bool dual=count == m && all(c >= 0); + dual=count == m && all(c >= 0); for(int i=0; i < m; ++i) { rational[] ai=a[i]; for(int j=0; j < k; ++j) ai[n+j]=0; + int si=s[i]; if(k < count) - ai[n+k]=-s[i]; + ai[n+k]=-si; for(int j=k+1; j < count; ++j) ai[n+j]=0; - int si=s[i]; if(si == 0) phase1=true; else { ++k; @@ -391,21 +399,20 @@ struct simplex { for(int j=0; j < n+count; ++j) ai[j]=-ai[j]; } - } else if(si*bi > 0) { - if(dual && si == 1) { - b[i]=-bi; - s[i]=-1; - for(int j=0; j < n+count; ++j) - ai[j]=-ai[j]; - } else - phase1=true; - } + } else if(dual && si == 1) { + b[i]=-bi; + s[i]=-1; + for(int j=0; j < n+count; ++j) + ai[j]=-ai[j]; + } else if(si*bi > 0) + phase1=true; } } + if(dual) phase1=false; rational[] C=concat(c,array(count,rational(0))); simplexInit(C,a,b,count); - operator init(C,a,b,phase1,dual); + operator init(C,a,b,phase1); if(case != INFEASIBLE) { xStandard=copy(x); diff --git a/graphics/asymptote/base/simplex.asy b/graphics/asymptote/base/simplex.asy index c27b3236be..e6d0410b23 100644 --- a/graphics/asymptote/base/simplex.asy +++ b/graphics/asymptote/base/simplex.asy @@ -8,6 +8,7 @@ struct simplex { int case; real[] x; real cost; + bool dual=false; int m,n; int J; @@ -43,7 +44,7 @@ struct simplex { int iterate(real[][] E, int N, int[] Bindices) { while(true) { - // Find first negative entry in bottom (reduced cost) row + // Bland's rule: first negative entry in reduced cost (bottom) row enters real[] Em=E[m]; for(J=1; J <= N; ++J) if(Em[J] < 0) break; @@ -67,7 +68,7 @@ struct simplex { real r=E[i][0]/u; if(r <= t && (r < t || Bindices[i] < Bindices[I])) { t=r; I=i; - } // Bland's rule: exiting variable has smallest minimizing index + } // Bland's rule: exiting variable has smallest minimizing subscript } } if(I == -1) @@ -82,8 +83,7 @@ struct simplex { int iterateDual(real[][] E, int N, int[] Bindices) { while(true) { - // Find first negative entry in zeroth (basic variable) column - real[] Em=E[m]; + // Bland's rule: negative variable with smallest subscript exits int I; for(I=0; I < m; ++I) { if(E[I][0] < 0) break; @@ -92,23 +92,30 @@ struct simplex { if(I == m) break; + for(int i=I+1; i < m; ++i) { + if(E[i][0] < 0 && Bindices[i] < Bindices[I]) + I=i; + } + + real[] Em=E[m]; + real[] EI=E[I]; int J=0; real t; for(int j=1; j <= N; ++j) { - real u=E[I][j]; + real u=EI[j]; if(u < -EpsilonA) { - t=-E[m][j]/u; + t=-Em[j]/u; J=j; break; } } for(int j=J+1; j <= N; ++j) { - real u=E[I][j]; + real u=EI[j]; if(u < -EpsilonA) { - real r=-E[m][j]/u; - if(r <= t && (r < t || j < J)) { + real r=-Em[j]/u; + if(r < t) { t=r; J=j; - } // Bland's rule: exiting variable has smallest minimizing index + } // Bland's rule: smallest minimizing subscript enters } } if(J == 0) @@ -125,9 +132,7 @@ struct simplex { // where A is an m x n matrix, x is a vector of n non-negative numbers, // b is a vector of length m, and c is a vector of length n. // Can set phase1=false if the last m columns of A form the identity matrix. - void operator init(real[] c, real[][] A, real[] b, bool phase1=true, - bool dual=false) { - if(dual) phase1=false; + void operator init(real[] c, real[][] A, real[] b, bool phase1=true) { static real epsilon=sqrt(realEpsilon); real normA=norm(A); real epsilonA=100.0*realEpsilon*normA; @@ -324,11 +329,11 @@ struct simplex { real[] ai=a[i]; for(int j=0; j < k; ++j) ai[n+j]=0; + int si=s[i]; if(k < count) - ai[n+k]=-s[i]; + ai[n+k]=-si; for(int j=k+1; j < count; ++j) ai[n+j]=0; - int si=s[i]; if(si == 0) phase1=true; else { ++k; @@ -339,19 +344,18 @@ struct simplex { for(int j=0; j < n+count; ++j) ai[j]=-ai[j]; } - } else if(si*bi > 0) { - if(dual && si == 1) { - b[i]=-bi; - s[i]=-1; - for(int j=0; j < n+count; ++j) - ai[j]=-ai[j]; - } else - phase1=true; - } + } else if(dual && si == 1) { + b[i]=-bi; + s[i]=-1; + for(int j=0; j < n+count; ++j) + ai[j]=-ai[j]; + } else if(si*bi > 0) + phase1=true; } } - operator init(concat(c,array(count,0.0)),a,b,phase1,dual); + if(dual) phase1=false; + operator init(concat(c,array(count,0.0)),a,b,phase1); if(case == OPTIMAL && count > 0) x.delete(n,n+count-1); diff --git a/graphics/asymptote/base/three.asy b/graphics/asymptote/base/three.asy index d7a20b516c..5fc0d2f109 100644 --- a/graphics/asymptote/base/three.asy +++ b/graphics/asymptote/base/three.asy @@ -2582,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; @@ -2634,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) { @@ -2649,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,7 +2680,7 @@ struct scene 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; @@ -2801,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); |