mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-19 14:10:14 -05:00
Remove workarounds in splitPath() thanks to improved precision of Numerical.solveCubic().
This commit is contained in:
parent
142ee6fd8a
commit
bddff95fe3
3 changed files with 18 additions and 18 deletions
|
@ -374,14 +374,16 @@ var Curve = Base.extend(/** @lends Curve# */{
|
|||
* or the curve time parameter if {@code isParameter} is {@code true}
|
||||
* @param {Boolean} [isParameter=false] pass {@code true} if {@code offset}
|
||||
* is a curve time parameter
|
||||
* @return {Curve} the second part of the divided curve
|
||||
* @return {Curve} the second part of the divided curve, if the offset
|
||||
* is within the valid range, {code null} otherwise.
|
||||
*/
|
||||
// TODO: Rename to divideAt()?
|
||||
divide: function(offset, isParameter, ignoreLinear) {
|
||||
var parameter = this._getParameter(offset, isParameter),
|
||||
tolerance = /*#=*/Numerical.TOLERANCE,
|
||||
res = null;
|
||||
if (parameter > tolerance && parameter < 1 - tolerance) {
|
||||
// Only divide if not at the beginning or end.
|
||||
if (parameter >= tolerance && parameter <= 1 - tolerance) {
|
||||
var parts = Curve.subdivide(this.getValues(), parameter),
|
||||
isLinear = ignoreLinear ? false : this.isLinear(),
|
||||
left = parts[0],
|
||||
|
|
|
@ -1197,7 +1197,7 @@ var Path = PathItem.extend(/** @lends Path# */{
|
|||
var curves = this.getCurves();
|
||||
if (index >= 0 && index < curves.length) {
|
||||
// Only divide curves if we're not on an existing segment already.
|
||||
if (parameter > tolerance) {
|
||||
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);
|
||||
|
|
|
@ -193,7 +193,7 @@ PathItem.inject(new function() {
|
|||
tMax = 1 - tMin,
|
||||
linearHandles;
|
||||
|
||||
function resetLinear() {
|
||||
function setLinear() {
|
||||
// Reset linear segments if they were part of a linear curve
|
||||
// and if we are done with the entire curve.
|
||||
for (var i = 0, l = linearHandles.length; i < l; i++)
|
||||
|
@ -211,28 +211,26 @@ PathItem.inject(new function() {
|
|||
} else {
|
||||
curve = loc._curve;
|
||||
if (linearHandles)
|
||||
resetLinear();
|
||||
setLinear();
|
||||
linearHandles = curve.isLinear() ? [
|
||||
curve._segment1._handleOut,
|
||||
curve._segment2._handleIn
|
||||
] : null;
|
||||
}
|
||||
var newCurve,
|
||||
segment;
|
||||
// Split the curve at t, while ignoring linearity of curves
|
||||
if (newCurve = curve.divide(t, true, true)) {
|
||||
var segment;
|
||||
if (t < tMin) {
|
||||
segment = curve._segment1;
|
||||
} else if (t > tMax) {
|
||||
segment = curve._segment2;
|
||||
} else {
|
||||
// Split the curve at t, while ignoring linearity of curves,
|
||||
// passing true for ignoreLinear as we don't want to have
|
||||
// parametrically linear curves reset their handles.
|
||||
var newCurve = curve.divide(t, true, true);
|
||||
segment = newCurve._segment1;
|
||||
curve = newCurve.getPrevious();
|
||||
if (linearHandles)
|
||||
linearHandles.push(segment._handleOut, segment._handleIn);
|
||||
} else {
|
||||
segment = t < tMin
|
||||
? curve._segment1
|
||||
: t > tMax
|
||||
? curve._segment2
|
||||
: curve.getPartLength(0, t) < curve.getPartLength(t, 1)
|
||||
? curve._segment1
|
||||
: curve._segment2;
|
||||
}
|
||||
// Link the new segment with the intersection on the other curve
|
||||
segment._intersection = loc.getIntersection();
|
||||
|
@ -240,7 +238,7 @@ PathItem.inject(new function() {
|
|||
prev = loc;
|
||||
}
|
||||
if (linearHandles)
|
||||
resetLinear();
|
||||
setLinear();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue