mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-08-28 22:08:54 -04:00
Fix weirdness of Curve#divide() modifying the wrong Curve object.
This commit is contained in:
parent
c77165be3a
commit
b8c6eb46ad
3 changed files with 12 additions and 25 deletions
|
@ -497,12 +497,8 @@ var Curve = Base.extend(/** @lends Curve# */{
|
|||
// the end if this curve is a closing curve of a closed path,
|
||||
// as with segment2.index it would be inserted at 0.
|
||||
path.insert(segment1._index + 1, segment);
|
||||
// The way Path#_add handles curves, this curve will always
|
||||
// become the owner of the newly inserted segment.
|
||||
// TODO: I expect this.getNext() to produce the correct result,
|
||||
// but since we're inserting differently in _add (something
|
||||
// linked with CurveLocation#divide()), this is not the case...
|
||||
res = this; // this.getNext();
|
||||
// The newly inserted segment is the start of the next curve:
|
||||
res = this.getNext();
|
||||
} else {
|
||||
// otherwise create it from the result of split
|
||||
var end = segment2;
|
||||
|
|
|
@ -385,7 +385,7 @@ var Path = PathItem.extend(/** @lends Path# */{
|
|||
curves = this._curves,
|
||||
amount = segs.length,
|
||||
append = index == null,
|
||||
index = append ? segments.length : index;
|
||||
from = append ? segments.length : index;
|
||||
// Scan through segments to add first, convert if necessary and set
|
||||
// _path and _index references on them.
|
||||
for (var i = 0; i < amount; i++) {
|
||||
|
@ -395,7 +395,7 @@ var Path = PathItem.extend(/** @lends Path# */{
|
|||
if (segment._path)
|
||||
segment = segs[i] = segment.clone();
|
||||
segment._path = this;
|
||||
segment._index = index + i;
|
||||
segment._index = from + i;
|
||||
// If parts of this segment are selected, adjust the internal
|
||||
// _selectedSegmentState now
|
||||
if (segment._selectionState)
|
||||
|
@ -406,20 +406,15 @@ var Path = PathItem.extend(/** @lends Path# */{
|
|||
segments.push.apply(segments, segs);
|
||||
} else {
|
||||
// Insert somewhere else
|
||||
segments.splice.apply(segments, [index, 0].concat(segs));
|
||||
segments.splice.apply(segments, [from, 0].concat(segs));
|
||||
// Adjust the indices of the segments above.
|
||||
for (var i = index + amount, l = segments.length; i < l; i++)
|
||||
for (var i = from + amount, l = segments.length; i < l; i++)
|
||||
segments[i]._index = i;
|
||||
}
|
||||
// Keep the curves list in sync all the time in case it was requested
|
||||
// already.
|
||||
if (curves || segs._curves) {
|
||||
if (!curves)
|
||||
curves = this._curves = [];
|
||||
// We need to step one index down from the inserted segment to
|
||||
// get its curve, except for the first segment.
|
||||
var from = index > 0 ? index - 1 : index,
|
||||
start = from,
|
||||
if (curves) {
|
||||
var start = from,
|
||||
to = Math.min(from + amount, this._countCurves());
|
||||
if (segs._curves) {
|
||||
// Reuse removed curves.
|
||||
|
|
|
@ -203,15 +203,11 @@ PathItem.inject(new function() {
|
|||
// Split the curve at t, passing true for _setHandles to always
|
||||
// set the handles on the sub-curves even if the original curve
|
||||
// had no handles.
|
||||
var newCurve = curve.divide(t, true, true);
|
||||
segment = newCurve._segment1;
|
||||
curve = newCurve.getPrevious();
|
||||
segment = curve.divide(t, true, true)._segment1;
|
||||
// Keep track of segments of once straight curves, so they can
|
||||
// be set back straight at the end.
|
||||
if (noHandles)
|
||||
clearSegments.push(segment);
|
||||
// TODO: Figure out the right value for t
|
||||
t = 0; // Since it's split (might be 1 also?)
|
||||
}
|
||||
// Link the new segment with the intersection on the other curve
|
||||
var inter = segment._intersection;
|
||||
|
@ -240,10 +236,10 @@ PathItem.inject(new function() {
|
|||
} else {
|
||||
segment._intersection = loc._intersection;
|
||||
}
|
||||
// TODO: Figure out why setCurves doesn't work:
|
||||
// loc._setCurve(segment.getCurve());
|
||||
// TODO: Move setting of these values to CurveLocation
|
||||
loc._segment = segment;
|
||||
loc._parameter = t;
|
||||
loc._parameter = segment === curve._segment1 ? 0 : 1;
|
||||
loc._version = segment._path._version;
|
||||
prev = loc;
|
||||
prevT = locT;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue