From c1d2cab5d942cb5f9e938676a1ba26ef8e919cdf Mon Sep 17 00:00:00 2001 From: Jonathan Puckey Date: Sat, 12 Feb 2011 19:10:19 +0100 Subject: [PATCH] Segment.js: fix toString and remove methods. Add test for segment.remove(). --- src/path/Segment.js | 8 ++++---- test/tests/Segment.js | 9 +++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/path/Segment.js b/src/path/Segment.js index a5ba5475..ef6e67d5 100644 --- a/src/path/Segment.js +++ b/src/path/Segment.js @@ -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() : '') + ' }'; }, diff --git a/test/tests/Segment.js b/test/tests/Segment.js index 27988cde..1380ded8 100644 --- a/test/tests/Segment.js +++ b/test/tests/Segment.js @@ -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); }); \ No newline at end of file