diff options
Diffstat (limited to 'Build/source/utils/asymptote/bezierpatch.h')
-rw-r--r-- | Build/source/utils/asymptote/bezierpatch.h | 84 |
1 files changed, 46 insertions, 38 deletions
diff --git a/Build/source/utils/asymptote/bezierpatch.h b/Build/source/utils/asymptote/bezierpatch.h index 5bea5868027..344df7e81af 100644 --- a/Build/source/utils/asymptote/bezierpatch.h +++ b/Build/source/utils/asymptote/bezierpatch.h @@ -14,8 +14,6 @@ namespace camp { #ifdef HAVE_GL -extern const double Fuzz4; - struct BezierPatch { vertexBuffer data; @@ -35,61 +33,71 @@ struct BezierPatch triple normal(triple left3, triple left2, triple left1, triple middle, triple right1, triple right2, triple right3) { - triple rp=right1-middle; - triple lp=left1-middle; - triple n=triple(rp.gety()*lp.getz()-rp.getz()*lp.gety(), - rp.getz()*lp.getx()-rp.getx()*lp.getz(), - rp.getx()*lp.gety()-rp.gety()*lp.getx()); + triple lp=3.0*(left1-middle); + triple rp=3.0*(right1-middle); + + triple n=cross(rp,lp); if(abs2(n) > epsilon) - return unit(n); - + return n; + triple lpp=bezierPP(middle,left1,left2); triple rpp=bezierPP(middle,right1,right2); + n=cross(rpp,lp)+cross(rp,lpp); if(abs2(n) > epsilon) - return unit(n); - + return n; + triple lppp=bezierPPP(middle,left1,left2,left3); triple rppp=bezierPPP(middle,right1,right2,right3); - - return unit(9.0*cross(rpp,lpp)+ - 3.0*(cross(rp,lppp)+cross(rppp,lp)+ - cross(rppp,lpp)+cross(rpp,lppp))+ - cross(rppp,lppp)); + + n=cross(rpp,lpp)+cross(rppp,lp)+cross(rp,lppp); + if(abs2(n) > epsilon) + return n; + + n=cross(rppp,lpp)+cross(rpp,lppp); + if(abs2(n) > epsilon) + return n; + + return cross(rppp,lppp); } - triple derivative(triple p0, triple p1, triple p2, triple p3) { - triple lp=p1-p0; - if(abs2(lp) > epsilon) - return lp; + // Return the differential of the Bezier curve p0,p1,p2,p3 at 0 + triple differential(triple p0, triple p1, triple p2, triple p3) { + triple p=p1-p0; + if(abs2(p) > epsilon) + return p; - triple lpp=bezierPP(p0,p1,p2); - if(abs2(lpp) > epsilon) - return lpp; + p=bezierPP(p0,p1,p2); + if(abs2(p) > epsilon) + return p; return bezierPPP(p0,p1,p2,p3); } - virtual double Distance(const triple *p) { + // Determine the flatness of a Bezier patch. + pair Distance(const triple *p) { triple p0=p[0]; triple p3=p[3]; triple p12=p[12]; triple p15=p[15]; + + // Check the horizontal flatness. + double h=Flatness(p0,p12,p3,p15); + // Check straightness of the horizontal edges and interior control curves. + h=max(h,Straightness(p0,p[4],p[8],p12)); + h=max(h,Straightness(p[1],p[5],p[9],p[13])); + h=max(h,Straightness(p[2],p[6],p[10],p[14])); + h=max(h,Straightness(p3,p[7],p[11],p15)); + + // Check the vertical flatness. + double v=Flatness(p0,p3,p12,p15); + // Check straightness of the vertical edges and interior control curves. + v=max(v,Straightness(p0,p[1],p[2],p3)); + v=max(v,Straightness(p[4],p[5],p[6],p[7])); + v=max(v,Straightness(p[8],p[9],p[10],p[11])); + v=max(v,Straightness(p12,p[13],p[14],p15)); - // Check the flatness of a Bezier patch. - double d=Distance2(p15,p0,normal(p3,p[2],p[1],p0,p[4],p[8],p12)); - - // Determine how straight the edges are. - d=max(d,Straightness(p0,p[1],p[2],p3)); - d=max(d,Straightness(p0,p[4],p[8],p12)); - d=max(d,Straightness(p3,p[7],p[11],p15)); - d=max(d,Straightness(p12,p[13],p[14],p15)); - - // Determine how straight the interior control curves are. - d=max(d,Straightness(p[4],p[5],p[6],p[7])); - d=max(d,Straightness(p[8],p[9],p[10],p[11])); - d=max(d,Straightness(p[1],p[5],p[9],p[13])); - return max(d,Straightness(p[2],p[6],p[10],p[14])); + return pair(h,v); } struct Split3 { |