Segment.js: fix toString and remove methods. Add test for segment.remove().

This commit is contained in:
Jonathan Puckey 2011-02-12 19:10:19 +01:00
parent 9b5e18c795
commit c1d2cab5d9
2 changed files with 13 additions and 4 deletions

View file

@ -115,15 +115,15 @@ Segment = Base.extend({
},
remove: function() {
if(this.segments)
return this.path.segments.unshift(this.index, 1);
if(this.path && this.path.segments)
return this.path.segments.splice(this.index, 1);
return false;
},
toString: function() {
return '{ point: ' + this.point.toString()
+ ', handleIn '+ this.handleIn.toString()
+ ', handleOut ' + this.handleOut.toString()
+ (this.handleIn ? ', handleIn '+ this.handleIn.toString() : '')
+ (this.handleOut ? ', handleOut ' + this.handleOut.toString() : '')
+ ' }';
},

View file

@ -41,4 +41,13 @@ test('segment.clone()', function(){
var clone = segment.clone();
equals(segment == clone, false);
compareSegments(segment, clone);
});
test('segment.remove()', function(){
var doc = new Doc();
var path = new Path([10, 10], [5, 5], [10, 10]);
console.log(path.segments);
path.segments[1].remove();
console.log(path.segments);
equals(path.segments.length, 2);
});