mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
Separate Path#remove(), #remove(index) & #remove(from, to) into #removeSegment(index) and #removeSegments(from, to).
This commit is contained in:
parent
5211e86e3a
commit
ea510c2403
2 changed files with 13 additions and 20 deletions
|
@ -107,24 +107,17 @@ var Path = this.Path = PathItem.extend({
|
|||
segment = Segment.read(arguments, 1);
|
||||
return segment ? this._add(segment, index) : null;
|
||||
},
|
||||
|
||||
// TODO: Port back to Sg
|
||||
removeSegment: function(index) {
|
||||
var segment = this._segments[index]
|
||||
return segment && segment.remove() ? segment : null;
|
||||
},
|
||||
|
||||
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: Port back to Sg
|
||||
removeSegments: function(from, to) {
|
||||
for(var i = to; i >= from; i--)
|
||||
this.removeSegment(i);
|
||||
},
|
||||
|
||||
isSelected: function() {
|
||||
|
|
|
@ -63,13 +63,13 @@ test('path.remove()', function() {
|
|||
path.add(20, 0);
|
||||
path.add(30, 0);
|
||||
|
||||
path.remove(0);
|
||||
path.removeSegment(0);
|
||||
equals(path.segments.length, 3);
|
||||
|
||||
path.remove(path.segments[0]);
|
||||
path.removeSegment(0);
|
||||
equals(path.segments.length, 2);
|
||||
|
||||
path.remove(0, 1);
|
||||
path.removeSegments(0, 1);
|
||||
equals(path.segments.length, 0);
|
||||
|
||||
path.remove();
|
||||
|
|
Loading…
Reference in a new issue