Switch back to Kaspar Fischer's version of Curve.isFlatEnough, as it produces the best results with dashed lines.

This commit is contained in:
Jürg Lehni 2011-11-11 20:55:31 +01:00
parent 3dfb4d3ae5
commit fdd4ee8d31

View file

@ -538,6 +538,7 @@ var Curve = this.Curve = Base.extend(/** @lends Curve# */{
// and optimised for cubic bezier curves. // and optimised for cubic bezier curves.
// Derive the implicit equation for line connecting first and last // Derive the implicit equation for line connecting first and last
// control points // control points
/*
var p1x = v[0], p1y = v[1], var p1x = v[0], p1y = v[1],
c1x = v[2], c1y = v[3], c1x = v[2], c1y = v[3],
c2x = v[4], c2y = v[5], c2x = v[4], c2y = v[5],
@ -551,7 +552,7 @@ var Curve = this.Curve = Base.extend(/** @lends Curve# */{
v2 = a * c2x + b * c2y + c; v2 = a * c2x + b * c2y + c;
// Compute intercepts of bounding box // Compute intercepts of bounding box
return Math.abs((v1 * v1 + v2 * v2) / (a * (a * a + b * b))) < 0.005; return Math.abs((v1 * v1 + v2 * v2) / (a * (a * a + b * b))) < 0.005;
/* */
// Inspired by Skia, but to be tested: // Inspired by Skia, but to be tested:
// Calculate 1/3 (m1) and 2/3 (m2) along the line between start (p1) // 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 // 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 // Seems all very inaccurate, especially since the distance
// measurement is just the bigger one of x / y... // measurement is just the bigger one of x / y...
// TODO: Find a more accurate and still fast way to determine this. // 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, vy = (p2y - p1y) / 3,
m1x = p1x + vx, m1x = p1x + vx,
m1y = p1y + vy, 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(m1x - c1x), Math.abs(m1y - c1y),
Math.abs(m2x - c1x), Math.abs(m1y - c1y)) < 1 / 2; Math.abs(m2x - c1x), Math.abs(m1y - c1y)) < 1 / 2;
*/ */
/*
// Thanks to Kaspar Fischer for the following: // Thanks to Kaspar Fischer for the following:
// http://www.inf.ethz.ch/personal/fischerk/pubs/bez.pdf // 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; ux *= ux;
var uy = 3 * c1y - 2 * p1y - p2y;
uy *= uy; uy *= uy;
var vx = 3 * c2x - 2 * p2x - p1x;
vx *= vx; vx *= vx;
var vy = 3 * c2y - 2 * p2y - p1y;
vy *= vy; vy *= vy;
if (ux < vx) if (ux < vx)
ux = vx; ux = vx;
@ -586,7 +597,6 @@ var Curve = this.Curve = Base.extend(/** @lends Curve# */{
uy = vy; uy = vy;
// Tolerance is 16 * tol ^ 2 // Tolerance is 16 * tol ^ 2
return ux + uy <= 16 * Numerical.TOLERNACE * Numerical.TOLERNACE; return ux + uy <= 16 * Numerical.TOLERNACE * Numerical.TOLERNACE;
*/
} }
} }
}, new function() { // Scope for methods that require numerical integration }, new function() { // Scope for methods that require numerical integration