mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
Merge pull request #816 from tjunnone/issue815
Issue 815: Cannot add segment to Path after removing last segment
This commit is contained in:
commit
96e0f9ef6c
2 changed files with 26 additions and 3 deletions
|
@ -417,7 +417,7 @@ var Path = PathItem.extend(/** @lends Path# */{
|
|||
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.
|
||||
from = index + amount - 1 === total ? index - 1 : index,
|
||||
from = Math.max(index + amount - 1 === total ? index - 1 : index, 0),
|
||||
start = from,
|
||||
to = Math.min(from + amount, total);
|
||||
if (segs._curves) {
|
||||
|
|
|
@ -106,7 +106,30 @@ test('Curve list after removing a segment - 2', function() {
|
|||
return path.curves.length;
|
||||
}, 1, 'After removing the last segment, we should be left with one curve.');
|
||||
|
||||
path.addSegment([3, 3]);
|
||||
equals(function() {
|
||||
return path.segments[1].remove();
|
||||
}, true, 'Removing the paths last segment should be successful.');
|
||||
|
||||
equals(function() {
|
||||
return path.curves.length;
|
||||
}, 0, 'After removing the last segment, we should be left with no curves.');
|
||||
|
||||
equals(function() {
|
||||
return path.segments[0].remove();
|
||||
}, true, 'Removing the final remaining segment should be successful.');
|
||||
|
||||
equals(function() {
|
||||
return path.curves.length;
|
||||
}, 0, 'After removing all segments, we should be left with no curves.');
|
||||
|
||||
path.addSegment([0, 0]);
|
||||
path.addSegment([1, 1]);
|
||||
|
||||
equals(function() {
|
||||
return path.curves.length;
|
||||
}, 1, 'After adding two new segments at the end, we should have one curve again.');
|
||||
|
||||
path.addSegment([2, 2]);
|
||||
|
||||
equals(function() {
|
||||
return path.curves.length;
|
||||
|
@ -116,7 +139,7 @@ test('Curve list after removing a segment - 2', function() {
|
|||
return path.curves[1].segment1 === path.curves[0].segment2;
|
||||
}, true, "The newly created curve's first segment needs to be the same as the previous curve's second segment.");
|
||||
|
||||
path.addSegments([[4, 4], [5, 5]]);
|
||||
path.addSegments([[3, 3], [4, 4]]);
|
||||
|
||||
equals(function() {
|
||||
return path.curves.length;
|
||||
|
|
Loading…
Reference in a new issue