From 7dd0b852c8560eb13c37c602e8c50e8f4f8de81d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Sat, 24 Sep 2016 14:48:42 -0400 Subject: [PATCH] Remove further unneeded GEOMETRIC_EPSILON curve-end checks. --- src/path/Curve.js | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/src/path/Curve.js b/src/path/Curve.js index 544157cb..74c8fa54 100644 --- a/src/path/Curve.js +++ b/src/path/Curve.js @@ -701,27 +701,22 @@ statics: /** @lends Curve */{ t = point.isClose(p1, epsilon) ? 0 : point.isClose(p2, epsilon) ? 1 : null; - if (t !== null) - return t; - // Solve the cubic for both x- and y-coordinates and consider all found - // solutions, testing with the larger / looser geometric epsilon. - var coords = [point.x, point.y], - roots = [], - geomEpsilon = /*#=*/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++) { - t = roots[i]; - if (point.isClose(Curve.getPoint(v, t), geomEpsilon)) - return t; + if (t === null) { + // Solve the cubic for both x- and y-coordinates and consider all + // solutions, testing with the larger / looser geometric epsilon. + var coords = [point.x, point.y], + roots = []; + 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 u = roots[i]; + if (point.isClose(Curve.getPoint(v, u), + /*#=*/Numerical.GEOMETRIC_EPSILON)) + return u; + } } } - // For very short curves (length ~ 1e-13), the above code will not - // necessarily produce any valid roots. As a fall-back, just check the - // beginnings and ends at the end so we can still return a valid result. - return point.isClose(p1, geomEpsilon) ? 0 - : point.isClose(p2, geomEpsilon) ? 1 - : null; + return t; }, getNearestTime: function(v, point) {