From ad801fa786f26ba79c2226ed2f8f56a6521f2d3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Sat, 15 Feb 2014 23:37:41 +0100 Subject: [PATCH] Use parameter tolerances in Path#slipt() Required because CurveLocation objects as returned by Path#getLocationAt() have some imprecision in their #parameter values. Fixes #401. --- src/path/Path.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/path/Path.js b/src/path/Path.js index e4d004d3..82d0ef21 100644 --- a/src/path/Path.js +++ b/src/path/Path.js @@ -1068,15 +1068,17 @@ var Path = PathItem.extend(/** @lends Path# */{ index = arg.index; parameter = arg.parameter; } - if (parameter >= 1) { + var tolerance = /*#=*/ Numerical.TOLERANCE; + if (parameter >= 1 - tolerance) { // t == 1 is the same as t == 0 and index ++ index++; parameter--; } var curves = this.getCurves(); + paper.console.log(index, parameter); if (index >= 0 && index < curves.length) { // Only divide curves if we're not on an existing segment already. - if (parameter > 0) { + if (parameter > tolerance) { // Divide the curve with the index at given parameter. // Increase because dividing adds more segments to the path. curves[index++].divide(parameter, true); @@ -1344,13 +1346,13 @@ var Path = PathItem.extend(/** @lends Path# */{ var start = length, curve = curves[i]; length += curve.getLength(); - if (length >= offset) { + if (length > offset) { // Found the segment within which the length lies return curve.getLocationAt(offset - start); } } - // It may be that through impreciseness of getLength, that the end - // of the curves was missed: + // It may be that through imprecision of getLength, that the end of the + // last curve was missed: if (offset <= this.getLength()) return new CurveLocation(curves[curves.length - 1], 1); return null;