From 688f580b951a4f601d40f79e4c37416eed14545b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Fri, 9 Oct 2015 10:34:46 +0200 Subject: [PATCH] Switch to new Curve.getParameterOf() Simpler code, but improved precision means more glitches to analyze. --- src/path/Curve.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/path/Curve.js b/src/path/Curve.js index 33bc7a68..026e6ce0 100644 --- a/src/path/Curve.js +++ b/src/path/Curve.js @@ -615,7 +615,7 @@ statics: { return Numerical.solveCubic(a, b, c, p1 - val, roots, min, max); }, - getParameterOf: function(v, point) { + getParameterOf_: function(v, point) { // Handle beginnings and end separately, as they are not detected // sometimes. var x = point.x, @@ -666,6 +666,21 @@ statics: { return null; }, + getParameterOf: function(v, point) { + 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 t = roots[i], + pt = Curve.getPoint(v, t); + if (point.isClose(pt, /*#=*/Numerical.GEOMETRIC_EPSILON)) + return t; + } + } + return null; + }, + // TODO: Find better name getPart: function(v, from, to) { var flip = from > to;