From c1d0bd21b8437de0b0f055733c62a03c761e22ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Sun, 11 Oct 2015 16:59:03 +0200 Subject: [PATCH] Improve Curve#getParameterOf() to better handle very small curves. See #799 --- src/path/Curve.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/path/Curve.js b/src/path/Curve.js index bbeeabd2..5c579ce2 100644 --- a/src/path/Curve.js +++ b/src/path/Curve.js @@ -668,17 +668,19 @@ statics: { getParameterOf: function(v, point) { var coords = [point.x, point.y], - roots = []; + roots = [], + epsilon = /*#=*/Numerical.GEOMETRIC_EPSILON; for (var c = 0; c < 2; c++) { var count = Curve.solveCubic(v, c, coords[c], roots, 0, 1); for (var i = 0; i < count; i++) { - var t = roots[i], - pt = Curve.getPoint(v, t); - if (point.isClose(pt, /*#=*/Numerical.GEOMETRIC_EPSILON)) + var t = roots[i]; + if (point.isClose(Curve.getPoint(v, t), epsilon)) 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