Fix issue of faulty curves list after inserting segments at the end of open paths.

This commit is contained in:
Jürg Lehni 2015-10-24 17:00:37 +02:00
parent 5afcca928e
commit ae2bed9cf0
2 changed files with 12 additions and 3 deletions

View file

@ -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));

View file

@ -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() {