diff options
Diffstat (limited to 'graphics/asymptote/base/contour.asy')
-rw-r--r-- | graphics/asymptote/base/contour.asy | 74 |
1 files changed, 37 insertions, 37 deletions
diff --git a/graphics/asymptote/base/contour.asy b/graphics/asymptote/base/contour.asy index fbb4cd1c71..f2ee0e78fe 100644 --- a/graphics/asymptote/base/contour.asy +++ b/graphics/asymptote/base/contour.asy @@ -1,10 +1,10 @@ // Contour routines written by Radoslav Marinov and John Bowman. - + import graph_settings; real eps=10000*realEpsilon; -// 1 +// 1 // 6 +-------------------+ 5 // | \ / | // | \ / | @@ -16,7 +16,7 @@ real eps=10000*realEpsilon; // | / \ | // | / \ | // 7 +-------------------+ 4 or 8 -// 3 +// 3 private struct segment { @@ -76,11 +76,11 @@ private segment case3(pair p0, pair p1, pair p2, private segment checktriangle(pair p0, pair p1, pair p2, real v0, real v1, real v2, int edge=-1) { - // default null return + // default null return static segment dflt; real eps=eps*max(abs(v0),abs(v1),abs(v2)); - + if(v0 < -eps) { if(v1 < -eps) { if(v2 < -eps) return dflt; // nothing to do @@ -92,10 +92,10 @@ private segment checktriangle(pair p0, pair p1, pair p2, else return case2(p1,p0,p2,v1,v0,v2,5+edge); } else { if(v2 < -eps) return case3(p0,p1,p2,v0,v1,v2,edge); - else if(v2 <= eps) + else if(v2 <= eps) return case2(p2,p0,p1,v2,v0,v1,edge); else return case3(p1,p0,p2,v1,v0,v2,edge); - } + } } else if(v0 <= eps) { if(v1 < -eps) { if(v2 < -eps) return dflt; // nothing to do @@ -109,7 +109,7 @@ private segment checktriangle(pair p0, pair p1, pair p2, if(v2 < -eps) return case2(p0,p1,p2,v0,v1,v2,4+edge); else if(v2 <= eps) return case1(p0,p2,4+edge); else return dflt; // nothing to do - } + } } else { if(v1 < -eps) { if(v2 < -eps) return case3(p1,p0,p2,v1,v0,v2,edge); @@ -124,8 +124,8 @@ private segment checktriangle(pair p0, pair p1, pair p2, if(v2 < -eps) return case3(p0,p2,p1,v0,v2,v1); else if(v2 <= eps) return dflt; // nothing to do else return dflt; // nothing to do - } - } + } + } } // Collect connecting path segments. @@ -135,7 +135,7 @@ private void collect(pair[][][] points, real[] c) int[] reverseF(int n) {return sequence(new int(int x){return n-1-x;},n-1);} // use to reverse an array, omitting the last point int[] reverseL(int n) {return sequence(new int(int x){return n-2-x;},n-1);} - + for(int cnt=0; cnt < c.length; ++cnt) { pair[][] gdscnt=points[cnt]; for(int i=0; i < gdscnt.length; ++i) { @@ -144,11 +144,11 @@ private void collect(pair[][][] points, real[] c) for(int j=i+1; j < gdscnt.length; ++j) { pair[] gjg=gdscnt[j]; int Lj=gjg.length; - if(abs(gig[0]-gjg[0]) < eps) { + if(abs(gig[0]-gjg[0]) < eps) { gdscnt[j]=gjg[reverseF(Lj)]; gdscnt[j].append(gig); - gdscnt.delete(i); - --i; + gdscnt.delete(i); + --i; break; } else if(abs(gig[0]-gjg[Lj-1]) < eps) { gig.delete(0); @@ -169,7 +169,7 @@ private void collect(pair[][][] points, real[] c) gdscnt.delete(i); --i; break; - } + } } } } @@ -224,7 +224,7 @@ guide[][] contour(pair[][] z, real[][] f, c=sort(c); bool midpoints=midpoint.length > 0; - + segment segments[][][]=new segment[nx][ny][]; // go over region a rectangle at a time @@ -238,7 +238,7 @@ guide[][] contour(pair[][] z, real[][] f, segment[][] segmentsi=segments[i]; for(int j=0; j < ny; ++j) { segment[] segmentsij=segmentsi[j]; - + // define points pair bleft=zi[j]; pair bright=zp[j]; @@ -264,26 +264,26 @@ guide[][] contour(pair[][] z, real[][] f, int countm=0; int countz=0; int countp=0; - + void check(real vertdat) { if(vertdat < -eps) ++countm; else { - if(vertdat <= eps) ++countz; + if(vertdat <= eps) ++countz; else ++countp; } } - + check(vertdat0); check(vertdat1); check(vertdat2); check(vertdat3); - if(countm == 4) return 1; // nothing to do - if(countp == 4) return -1; // nothing to do + if(countm == 4) return 1; // nothing to do + if(countp == 4) return -1; // nothing to do if((countm == 3 || countp == 3) && countz == 1) return 0; // go through the triangles - + void addseg(segment seg) { if(seg.active) { seg.c=cnt; @@ -301,7 +301,7 @@ guide[][] contour(pair[][] z, real[][] f, vertdat0,vertdat1,vertdat4,3)); return 0; } - + void process(int l, int u) { if(l >= u) return; int i=quotient(l+u,2); @@ -313,7 +313,7 @@ guide[][] contour(pair[][] z, real[][] f, process(i+1,u); } } - + process(0,c.length); } } @@ -356,7 +356,7 @@ guide[][] contour(pair[][] z, real[][] f, } return -1; } - + int backward(int I, int J, bool first=true) { if(I >= 0 && I < nx && J >= 0 && J < ny) { segment[] segmentsIJ=segments[I][J]; @@ -380,7 +380,7 @@ guide[][] contour(pair[][] z, real[][] f, } return -1; } - + void follow(int f(int, int, bool first=true), int edge) { int I=i; int J=j; @@ -489,7 +489,7 @@ guide[][] contour(real f(real, real), pair a, pair b, // evaluate function at points and midpoints real[][] dat=new real[nx+1][ny+1]; real[][] midpoint=new real[nx+1][ny+1]; - + for(int i=0; i <= nx; ++i) { real x=interp(a.x,b.x,i/nx); real x2=interp(a.x,b.x,(i+0.5)/nx); @@ -503,7 +503,7 @@ guide[][] contour(real f(real, real), pair a, pair b, return contour(dat,midpoint,a,b,c,join); } - + void draw(picture pic=currentpicture, Label[] L=new Label[], guide[][] g, pen[] p) { @@ -576,7 +576,7 @@ pen[][] interior(picture pic=currentpicture, guide[][] g, pen[] palette) index=i; } } - } + } fillpalettei[j]=palette[index]; } fillpalette[i]=fillpalettei; @@ -620,7 +620,7 @@ void fill(picture pic=currentpicture, guide[][] g, pen[][] palette) // check existing guides and adds new segment to them if possible, // or otherwise store segment as a new guide private void addseg(pair[][] gds, segment seg) -{ +{ if(!seg.active) return; // search for a path to extend for(int i=0; i < gds.length; ++i) { @@ -629,22 +629,22 @@ private void addseg(pair[][] gds, segment seg) gd.insert(0,seg.a); return; } else if(abs(gd[gd.length-1]-seg.b) < eps) { - gd.push(seg.a); + gd.push(seg.a); return; } else if(abs(gd[0]-seg.a) < eps) { gd.insert(0,seg.b); return; - } else if(abs(gd[gd.length-1]-seg.a) < eps) { + } else if(abs(gd[gd.length-1]-seg.a) < eps) { gd.push(seg.b); return; } } - + // in case nothing is found pair[] segm; - segm=new pair[] {seg.a,seg.b}; + segm=new pair[] {seg.a,seg.b}; gds.push(segm); - + return; } @@ -664,7 +664,7 @@ guide[][] contour(pair[] z, real[] f, real[] c, interpolate join=operator --) // array to store guides found so far pair[][][] points=new pair[c.length][][]; - + for(int cnt=0; cnt < c.length; ++cnt) { pair[][] pointscnt=points[cnt]; real C=c[cnt]; |