From fdd4ee8d315a26cbcc62c7c614e3cec39f48397f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Fri, 11 Nov 2011 20:55:31 +0100 Subject: [PATCH] Switch back to Kaspar Fischer's version of Curve.isFlatEnough, as it produces the best results with dashed lines. --- src/path/Curve.js | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/path/Curve.js b/src/path/Curve.js index 8341411f..fd2aef38 100644 --- a/src/path/Curve.js +++ b/src/path/Curve.js @@ -538,6 +538,7 @@ var Curve = this.Curve = Base.extend(/** @lends Curve# */{ // and optimised for cubic bezier curves. // Derive the implicit equation for line connecting first and last // control points + /* var p1x = v[0], p1y = v[1], c1x = v[2], c1y = v[3], c2x = v[4], c2y = v[5], @@ -551,7 +552,7 @@ var Curve = this.Curve = Base.extend(/** @lends Curve# */{ v2 = a * c2x + b * c2y + c; // Compute intercepts of bounding box return Math.abs((v1 * v1 + v2 * v2) / (a * (a * a + b * b))) < 0.005; - /* + */ // Inspired by Skia, but to be tested: // Calculate 1/3 (m1) and 2/3 (m2) along the line between start (p1) // and end (p2), measure distance from there the control points and @@ -559,7 +560,13 @@ var Curve = this.Curve = Base.extend(/** @lends Curve# */{ // Seems all very inaccurate, especially since the distance // measurement is just the bigger one of x / y... // TODO: Find a more accurate and still fast way to determine this. - var vx = (p2x - p1x) / 3, + /* + var p1x = v[0], p1y = v[1], + c1x = v[2], c1y = v[3], + c2x = v[4], c2y = v[5], + p2x = v[6], p2y = v[7], + + vx = (p2x - p1x) / 3, vy = (p2y - p1y) / 3, m1x = p1x + vx, m1y = p1y + vy, @@ -569,16 +576,20 @@ var Curve = this.Curve = Base.extend(/** @lends Curve# */{ Math.abs(m1x - c1x), Math.abs(m1y - c1y), Math.abs(m2x - c1x), Math.abs(m1y - c1y)) < 1 / 2; */ - /* // Thanks to Kaspar Fischer for the following: // http://www.inf.ethz.ch/personal/fischerk/pubs/bez.pdf - var ux = 3 * c1x - 2 * p1x - p2x; + var p1x = v[0], p1y = v[1], + c1x = v[2], c1y = v[3], + c2x = v[4], c2y = v[5], + p2x = v[6], p2y = v[7], + + ux = 3 * c1x - 2 * p1x - p2x, + uy = 3 * c1y - 2 * p1y - p2y, + vx = 3 * c2x - 2 * p2x - p1x, + vy = 3 * c2y - 2 * p2y - p1y; ux *= ux; - var uy = 3 * c1y - 2 * p1y - p2y; uy *= uy; - var vx = 3 * c2x - 2 * p2x - p1x; vx *= vx; - var vy = 3 * c2y - 2 * p2y - p1y; vy *= vy; if (ux < vx) ux = vx; @@ -586,7 +597,6 @@ var Curve = this.Curve = Base.extend(/** @lends Curve# */{ uy = vy; // Tolerance is 16 * tol ^ 2 return ux + uy <= 16 * Numerical.TOLERNACE * Numerical.TOLERNACE; - */ } } }, new function() { // Scope for methods that require numerical integration