mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-04 03:45:58 -05:00
Implement Path#remove() and add tests for it.
This commit is contained in:
parent
6d4d07f2a8
commit
74cee4abef
2 changed files with 41 additions and 1 deletions
|
@ -109,7 +109,25 @@ var Path = this.Path = PathItem.extend({
|
||||||
return segment ? this._add(segment, index) : null;
|
return segment ? this._add(segment, index) : null;
|
||||||
},
|
},
|
||||||
|
|
||||||
// TODO: remove(index) / remove(segment) / remove(fromIndex, toIndex)
|
remove: function() {
|
||||||
|
if (!arguments.length) {
|
||||||
|
// remove()
|
||||||
|
this.base();
|
||||||
|
} else if (arguments.length == 1) {
|
||||||
|
if (arguments[0].point) {
|
||||||
|
// remove(segment)
|
||||||
|
arguments[0].remove();
|
||||||
|
} else {
|
||||||
|
// remove(index)
|
||||||
|
this._segments[arguments[0]].remove();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// remove(fromIndex, toIndex)
|
||||||
|
for(var i = arguments[1], l = arguments[0]; i >= l; i--)
|
||||||
|
this._segments[i].remove();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
// TODO: pointsToCurves([tolerance[, threshold[, cornerRadius[, scale]]]])
|
// TODO: pointsToCurves([tolerance[, threshold[, cornerRadius[, scale]]]])
|
||||||
// TODO: curvesToPoints([maxPointDistance[, flatness]])
|
// TODO: curvesToPoints([maxPointDistance[, flatness]])
|
||||||
// TODO: reduceSegments([flatness])
|
// TODO: reduceSegments([flatness])
|
||||||
|
|
|
@ -53,4 +53,26 @@ test('path.join(path)', function() {
|
||||||
new Segment(new Point(10, 0)), new Segment(new Point(20, 10)),
|
new Segment(new Point(10, 0)), new Segment(new Point(20, 10)),
|
||||||
new Segment(new Point(10, 5))]);
|
new Segment(new Point(10, 5))]);
|
||||||
equals(path.closed, true);
|
equals(path.closed, true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('path.remove()', function() {
|
||||||
|
var doc = new Document();
|
||||||
|
var path = new Path();
|
||||||
|
path.add(0, 0);
|
||||||
|
path.add(10, 0);
|
||||||
|
path.add(20, 0);
|
||||||
|
path.add(30, 0);
|
||||||
|
|
||||||
|
path.remove(0);
|
||||||
|
equals(path.segments.length, 3);
|
||||||
|
|
||||||
|
path.remove(path.segments[0]);
|
||||||
|
equals(path.segments.length, 2);
|
||||||
|
|
||||||
|
path.remove(0, 1);
|
||||||
|
equals(path.segments.length, 0);
|
||||||
|
|
||||||
|
path.remove();
|
||||||
|
|
||||||
|
equals(doc.activeLayer.children.length, 0);
|
||||||
});
|
});
|
Loading…
Reference in a new issue