From 16d128e5e10d541a78654b86409d5a3539f07708 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Sat, 15 Aug 2009 23:57:48 +0000 Subject: asymptote 1.83 git-svn-id: svn://tug.org/texlive/trunk@14696 c570f23f-e606-0410-a88d-b1316a301751 --- Build/source/utils/asymptote/drawsurface.cc | 57 +++++++++++++++++++---------- 1 file changed, 38 insertions(+), 19 deletions(-) (limited to 'Build/source/utils/asymptote/drawsurface.cc') diff --git a/Build/source/utils/asymptote/drawsurface.cc b/Build/source/utils/asymptote/drawsurface.cc index af6f0cd8722..1eee043df7c 100644 --- a/Build/source/utils/asymptote/drawsurface.cc +++ b/Build/source/utils/asymptote/drawsurface.cc @@ -41,20 +41,23 @@ void drawSurface::bounds(bbox3& b) for(int i=0; i < 16; ++i) c1[i]=controls[i][0]; double c0=c1[0]; - double xmin=bound(c1,min,b.empty ? c0 : min(c0,b.left)); - double xmax=bound(c1,max,b.empty ? c0 : max(c0,b.right)); + double fuzz=sqrtFuzz*norm(c1,16); + double xmin=bound(c1,min,b.empty ? c0 : min(c0,b.left),fuzz); + double xmax=bound(c1,max,b.empty ? c0 : max(c0,b.right),fuzz); for(int i=0; i < 16; ++i) c1[i]=controls[i][1]; c0=c1[0]; - double ymin=bound(c1,min,b.empty ? c0 : min(c0,b.bottom)); - double ymax=bound(c1,max,b.empty ? c0 : max(c0,b.top)); + fuzz=sqrtFuzz*norm(c1,16); + double ymin=bound(c1,min,b.empty ? c0 : min(c0,b.bottom),fuzz); + double ymax=bound(c1,max,b.empty ? c0 : max(c0,b.top),fuzz); for(int i=0; i < 16; ++i) c1[i]=controls[i][2]; c0=c1[0]; - double zmin=bound(c1,min,b.empty ? c0 : min(c0,b.lower)); - double zmax=bound(c1,max,b.empty ? c0 : max(c0,b.upper)); + fuzz=sqrtFuzz*norm(c1,16); + double zmin=bound(c1,min,b.empty ? c0 : min(c0,b.lower),fuzz); + double zmax=bound(c1,max,b.empty ? c0 : max(c0,b.upper),fuzz); Min=triple(xmin,ymin,zmin); Max=triple(xmax,ymax,zmax); @@ -63,10 +66,7 @@ void drawSurface::bounds(bbox3& b) b.add(Max); } -void drawSurface::bounds(pair &b, double (*m)(double, double), - double (*x)(const triple&, double*), - double (*y)(const triple&, double*), - double *t, bool &first) +void drawSurface::ratio(pair &b, double (*m)(double, double), bool &first) { for(int i=0; i < 16; ++i) { double *ci=controls[i]; @@ -75,11 +75,12 @@ void drawSurface::bounds(pair &b, double (*m)(double, double), if(first) { triple v=c3[0]; - b=pair(x(v,t),y(v,t)); + b=pair(xratio(v),yratio(v)); first=false; } - b=pair(bound(c3,m,x,t,b.getx()),bound(c3,m,y,t,b.gety())); + double fuzz=sqrtFuzz*norm(c3,16); + b=pair(bound(c3,m,xratio,b.getx(),fuzz),bound(c3,m,yratio,b.gety(),fuzz)); } bool drawSurface::write(prcfile *out) @@ -87,7 +88,7 @@ bool drawSurface::write(prcfile *out) if(invisible) return true; - PRCMaterial m(ambient,diffuse,emissive,specular,opacity,shininess); + PRCMaterial m(ambient,diffuse,emissive,specular,opacity,PRCshininess); out->add(new PRCBezierSurface(out,3,3,4,4,controls,m,granularity)); return true; @@ -260,10 +261,10 @@ void drawSurface::render(GLUnurbs *nurb, double size2, } static GLfloat bezier[]={0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0}; gluBeginSurface(nurb); - gluNurbsSurface(nurb,8,bezier,8,bezier,3,12,c,4,4,GL_MAP2_VERTEX_3); + gluNurbsSurface(nurb,8,bezier,8,bezier,12,3,c,4,4,GL_MAP2_VERTEX_3); if(havecolors) { static GLfloat linear[]={0.0,0.0,1.0,1.0}; - gluNurbsSurface(nurb,4,linear,4,linear,4,8,colors,2,2,GL_MAP2_COLOR_4); + gluNurbsSurface(nurb,4,linear,4,linear,8,4,colors,2,2,GL_MAP2_COLOR_4); } gluEndSurface(nurb); @@ -275,14 +276,14 @@ void drawSurface::render(GLUnurbs *nurb, double size2, glColor4fv(colors); glVertex3fv(c); if(havecolors) - glColor4fv(colors+4); - glVertex3fv(c+9); + glColor4fv(colors+8); + glVertex3fv(c+36); if(havecolors) glColor4fv(colors+12); glVertex3fv(c+45); if(havecolors) - glColor4fv(colors+8); - glVertex3fv(c+36); + glColor4fv(colors+4); + glVertex3fv(c+9); glEnd(); } @@ -296,4 +297,22 @@ drawElement *drawSurface::transformed(const array& t) return new drawSurface(t,this); } +double norm(double *a, size_t n) +{ + if(n == 0) return 0.0; + double M=fabs(a[0]); + for(size_t i=1; i < n; ++i) + M=max(M,fabs(a[i])); + return M; +} + +double norm(triple *a, size_t n) +{ + if(n == 0) return 0.0; + double M=a[0].abs2(); + for(size_t i=1; i < n; ++i) + M=max(M,a[i].abs2()); + return sqrt(M); +} + } //namespace camp -- cgit v1.2.3