Fix yet another issue with Path#curves and Path#_add()

Including a unit test to prevent regression.
This commit is contained in:
Jürg Lehni 2015-10-24 18:11:30 +02:00
parent 19e3136892
commit 648985fcd2
2 changed files with 13 additions and 7 deletions

View file

@ -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 === total ? index - 1 : index,
from = index + amount - 1 === total ? index - 1 : index,
start = from,
to = Math.min(from + amount, total);
if (segs._curves) {
@ -1367,13 +1367,13 @@ var Path = PathItem.extend(/** @lends Path# */{
last2 = path.getLastSegment();
if (first1 && first1._point.equals(last2._point)) {
first1.setHandleIn(last2._handleIn);
// Prepend all segments from path except the last one
// Prepend all segments from path except the last one.
this._add(segments.slice(0, segments.length - 1), 0);
} else {
this._add(segments.slice());
}
}
if (path.closed)
if (path._closed)
this._add([segments[0]]);
path.remove();
}

View file

@ -104,17 +104,23 @@ test('Curve list after removing a segment - 2', function() {
equals(function() {
return path.curves.length;
}, 1, 'After removing the last segment, we should be left with one curve');
}, 1, 'After removing the last segment, we should be left with one curve.');
path.addSegment([4, 4]);
path.addSegment([3, 3]);
equals(function() {
return path.curves.length;
}, 2, 'After adding a new segment at the end, we should have two curves again');
}, 2, 'After adding a new segment at the end, we should have two curves again.');
equals(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");
}, 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]]);
equals(function() {
return path.curves.length;
}, 4, 'After adding tow new segments at the end, we should have four curves now.');
});
test('Splitting a straight path should produce segments without handles', function() {