mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -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
|
// Keep the curves list in sync all the time in case it was requested
|
||||||
// already.
|
// already.
|
||||||
if (curves) {
|
if (curves) {
|
||||||
var start = from,
|
var total = this._countCurves(),
|
||||||
to = Math.min(from + amount, 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) {
|
if (segs._curves) {
|
||||||
// Reuse removed curves.
|
// Reuse removed curves.
|
||||||
curves.splice.apply(curves, [from, 0].concat(segs._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() {
|
equals(function() {
|
||||||
return path.segments[2].remove();
|
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() {
|
equals(function() {
|
||||||
return path.curves.length;
|
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]);
|
||||||
|
|
||||||
|
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() {
|
test('Splitting a straight path should produce segments without handles', function() {
|
||||||
|
|
Loading…
Reference in a new issue