X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;ds=sidebyside;f=src%2Fbezier.cpp;h=cb926974cf0210feb95dac81cd98a4cd5ec7f4e5;hb=748d002a813bbe6309dd22259bdce3278c02b0c8;hp=3fa16e35ed13cab396a7c916a43309d67d6d0e76;hpb=35f1190c8c8036ed11180656769cf0c1cbf7c2b3;p=ipdf%2Fcode.git diff --git a/src/bezier.cpp b/src/bezier.cpp index 3fa16e3..cb92697 100644 --- a/src/bezier.cpp +++ b/src/bezier.cpp @@ -54,9 +54,11 @@ static void CubicSolveSegment(vector & roots, const Real & a, const Real & Real l = a*tl*tl*tl + b*tl*tl + c*tl + d; Real u = a*tu*tu*tu + b*tu*tu + c*tu + d; if ((l < 0 && u < 0) || (l > 0 && u > 0)) - return; + Debug("Discarding segment (no roots) l = %f (%f), u = %f (%f)", Double(tl), Double(l), Double(tu), Double(u)); + //return; bool negative = (u < l); // lower point > 0, upper point < 0 + Debug("%ft^3 + %ft^2 + %ft + %f is negative (%f < %f) %d", Double(a),Double(b),Double(c),Double(d),Double(u),Double(l), negative); while (tu - tl > delta) { Real t(tu+tl); @@ -87,7 +89,7 @@ vector SolveCubic(const Real & a, const Real & b, const Real & c, const Re Real tu(max); Real tl(min); vector turns(SolveQuadratic(a*3, b*2, c)); - //Debug("%u turning points", turns.size()); + Debug("%u turning points", turns.size()); for (unsigned i = 1; i < turns.size(); ++i) { tu = turns[i]; @@ -97,23 +99,6 @@ vector SolveCubic(const Real & a, const Real & b, const Real & c, const Re tu = max; CubicSolveSegment(roots, a, b, c, d, tl, tu,delta); return roots; - /* - Real maxi(100); - Real prevRes(d); - for(int i = 0; i <= 100; ++i) - { - Real x(i); - x /= maxi; - Real y = a*(x*x*x) + b*(x*x) + c*x + d; - if (((y < Real(0)) && (prevRes > Real(0))) || ((y > Real(0)) && (prevRes < Real(0)))) - { - //Debug("Found root of %fx^3 + %fx^2 + %fx + %f at %f (%f)", a, b, c, d, x, y); - roots.push_back(x); - } - prevRes = y; - } - return roots; - */ } /** @@ -166,8 +151,8 @@ pair BezierTurningPoints(const Real & p0, const Real & p1, const Rea { return pair(0, 1); } - Real a = (3*(p1-p2) + p3 - p0); - Real b = 2*(p2 - 2*p1 + p0); + Real a = ((p1-p2)*3 + p3 - p0); + Real b = (p2 - p1*2 + p0)*2; Real c = (p1-p0); if (a == 0) { @@ -179,7 +164,7 @@ pair BezierTurningPoints(const Real & p0, const Real & p1, const Rea return pair(t, t); } //Debug("a, b, c are %f, %f, %f", Float(a), Float(b), Float(c)); - if (b*b - 4*a*c < 0) + if (b*b - a*c*4 < 0) { //Debug("No real roots"); return pair(0,1);