Improve Curve#getParameterOf() to better handle very small curves.

See #799
This commit is contained in:
Jürg Lehni 2015-10-11 16:59:03 +02:00
parent 61db3d9d01
commit c1d0bd21b8

View file

@ -668,17 +668,19 @@ statics: {
getParameterOf: function(v, point) { getParameterOf: function(v, point) {
var coords = [point.x, point.y], var coords = [point.x, point.y],
roots = []; roots = [],
epsilon = /*#=*/Numerical.GEOMETRIC_EPSILON;
for (var c = 0; c < 2; c++) { for (var c = 0; c < 2; c++) {
var count = Curve.solveCubic(v, c, coords[c], roots, 0, 1); var count = Curve.solveCubic(v, c, coords[c], roots, 0, 1);
for (var i = 0; i < count; i++) { for (var i = 0; i < count; i++) {
var t = roots[i], var t = roots[i];
pt = Curve.getPoint(v, t); if (point.isClose(Curve.getPoint(v, t), epsilon))
if (point.isClose(pt, /*#=*/Numerical.GEOMETRIC_EPSILON))
return t; return t;
} }
} }
return null; return point.isClose(new Point(v[0], v[1]), epsilon) ? 0
: point.isClose(new Point(v[6], v[7]), epsilon) ? 1
: null;
}, },
// TODO: Find better name // TODO: Find better name