mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
Use parameter tolerances in Path#slipt()
Required because CurveLocation objects as returned by Path#getLocationAt() have some imprecision in their #parameter values. Fixes #401.
This commit is contained in:
parent
2010fefcbe
commit
ad801fa786
1 changed files with 7 additions and 5 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue