Only intersect lines if their lengths are not conflicting with Numerical.EPSILON comparison of the cross product in Line#intersect().

This commit is contained in:
Jürg Lehni 2011-07-30 11:38:17 +01:00
parent 7d0db22b9b
commit 7f81184848

View file

@ -760,8 +760,15 @@ var Curve = this.Curve = Base.extend(/** @lends Curve# */{
return [0.5 * (w[0].x + w[5].x)];
// Compute intersection of chord from first control point to last
// with x-axis.
if (isFlatEnough(w))
return [xAxis.intersect(new Line(w[0], w[5], true)).x];
if (isFlatEnough(w)) {
var line = new Line(w[0], w[5], true);
// Compare the line's squared length with EPSILON. If we're
// below, #intersect() will return null because of division
// by near-zero.
return [ line.vector.getLength(true) < Numerical.EPSILON
? line.point.x
: xAxis.intersect(line).x ];
}
}
// Otherwise, solve recursively after