summaryrefslogtreecommitdiff
path: root/graphics/asymptote/base/graph.asy
diff options
context:
space:
mode:
Diffstat (limited to 'graphics/asymptote/base/graph.asy')
-rw-r--r--graphics/asymptote/base/graph.asy48
1 files changed, 23 insertions, 25 deletions
diff --git a/graphics/asymptote/base/graph.asy b/graphics/asymptote/base/graph.asy
index 1d4dfc1bfd..18821b456d 100644
--- a/graphics/asymptote/base/graph.asy
+++ b/graphics/asymptote/base/graph.asy
@@ -2186,45 +2186,43 @@ picture vectorfield(path vector(real), path g, int n, bool truesize=false,
return pic;
}
-real maxlength(pair a, pair b, int nx, int ny)
-{
- return min((b.x-a.x)/nx,(b.y-a.y)/ny);
-}
-
// return a vector field over box(a,b).
picture vectorfield(path vector(pair), pair a, pair b,
int nx=nmesh, int ny=nx, bool truesize=false,
- real maxlength=truesize ? 0 : maxlength(a,b,nx,ny),
bool cond(pair z)=null, pen p=currentpen,
arrowbar arrow=Arrow, margin margin=PenMargin)
{
picture pic;
- real dx=1/nx;
- real dy=1/ny;
+ real dx=(b.x-a.x)/(nx-1);
+ real dy=(b.y-a.y)/(ny-1);
bool all=cond == null;
real scale;
- if(maxlength > 0) {
- real size(pair z) {
- path g=vector(z);
- return abs(point(g,size(g)-1)-point(g,0));
- }
- real max=size(a);
- for(int i=0; i <= nx; ++i) {
- real x=interp(a.x,b.x,i*dx);
- for(int j=0; j <= ny; ++j)
- max=max(max,size((x,interp(a.y,b.y,j*dy))));
+ transform t=scale(dx,dy);
+ pair size(pair z) {
+ path g=t*vector(z);
+ int n=size(g);
+ pair w=n == 1 ? point(g,0) : point(g,n-1)-point(g,0);
+ return (abs(w.x),abs(w.y));
+ }
+ pair max=size(a);
+ for(int i=0; i < nx; ++i) {
+ real x=a.x+i*dx;
+ for(int j=0; j < ny; ++j) {
+ real y=a.y+j*dy;
+ max=maxbound(max,size((x,y)));
}
- scale=max > 0 ? maxlength/max : 1;
- } else scale=1;
+ }
+ scale=min(dx/max.x,dy/max.y);
- for(int i=0; i <= nx; ++i) {
- real x=interp(a.x,b.x,i*dx);
- for(int j=0; j <= ny; ++j) {
- real y=interp(a.y,b.y,j*dy);
+ for(int i=0; i < nx; ++i) {
+ real x=a.x+i*dx;
+ for(int j=0; j < ny; ++j) {
+ real y=a.y+j*dy;
pair z=(x,y);
if(all || cond(z)) {
- path g=scale(scale)*vector(z);
+ path v=scale(scale)*t*vector(z);
+ path g=size(v) == 1 ? (0,0)--v : v;
if(truesize)
draw(z,pic,g,p,arrow);
else