mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2024-12-29 09:22:22 -05:00
Fix issue of faulty curves list after inserting segments at the end of open paths.
This commit is contained in:
parent
5afcca928e
commit
ae2bed9cf0
2 changed files with 12 additions and 3 deletions
|
@ -414,8 +414,11 @@ var Path = PathItem.extend(/** @lends Path# */{
|
|||
// Keep the curves list in sync all the time in case it was requested
|
||||
// already.
|
||||
if (curves) {
|
||||
var start = from,
|
||||
to = Math.min(from + amount, this._countCurves());
|
||||
var total = this._countCurves(),
|
||||
// If we're adding a new segment to the end of an open path,
|
||||
// we need to step one index down to get its curve.
|
||||
start = from === total ? from - 1 : from,
|
||||
to = Math.min(from + amount, total);
|
||||
if (segs._curves) {
|
||||
// Reuse removed curves.
|
||||
curves.splice.apply(curves, [from, 0].concat(segs._curves));
|
||||
|
|
|
@ -100,11 +100,17 @@ test('Curve list after removing a segment - 2', function() {
|
|||
|
||||
equals(function() {
|
||||
return path.segments[2].remove();
|
||||
}, true, 'Removing the paths last segment should be succesfull.');
|
||||
}, true, 'Removing the paths last segment should be successful.');
|
||||
|
||||
equals(function() {
|
||||
return path.curves.length;
|
||||
}, 1, 'After removing the last segment, we should be left with one curve');
|
||||
|
||||
path.addSegment([4, 4]);
|
||||
|
||||
equals(function() {
|
||||
return path.curves.length;
|
||||
}, 2, 'After adding a new segment at the end, we should have two curves again');
|
||||
});
|
||||
|
||||
test('Splitting a straight path should produce segments without handles', function() {
|
||||
|
|
Loading…
Reference in a new issue