Skip to content

Commit

Permalink
Fix close() for single node ways
Browse files Browse the repository at this point in the history
  • Loading branch information
bhousel committed Jan 12, 2017
1 parent cadb380 commit f109efd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion modules/osm/way.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ _.extend(osmWay.prototype, {
if (this.isClosed() || !this.nodes.length) return this;

var nodes = this.nodes.slice();
nodes.push(nodes[0]);
nodes = nodes.filter(noRepeatNodes);
nodes.push(nodes[0]);
return this.update({ nodes: nodes });
},

Expand Down
12 changes: 8 additions & 4 deletions test/spec/osm/way.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,10 @@ describe('iD.osmWay', function() {
});

it('closes a way', function () {
var w = iD.Way({ nodes: 'ab'.split('') });
expect(w.close().nodes.join('')).to.eql('aba');
var w1 = iD.Way({ nodes: 'ab'.split('') });
expect(w1.close().nodes.join('')).to.eql('aba', 'multiple');
var w2 = iD.Way({ nodes: 'a'.split('') });
expect(w2.close().nodes.join('')).to.eql('aa', 'single');
});

it('eliminates duplicate consecutive nodes when closing a linear way', function () {
Expand Down Expand Up @@ -461,8 +463,10 @@ describe('iD.osmWay', function() {
});

it('uncloses a circular way', function () {
var w = iD.Way({ nodes: 'aba'.split('') });
expect(w.unclose().nodes.join('')).to.eql('ab');
var w1 = iD.Way({ nodes: 'aba'.split('') });
expect(w1.unclose().nodes.join('')).to.eql('ab', 'multiple');
var w2 = iD.Way({ nodes: 'aa'.split('') });
expect(w2.unclose().nodes.join('')).to.eql('a', 'single');
});

it('eliminates duplicate consecutive nodes when unclosing a circular way', function () {
Expand Down

0 comments on commit f109efd

Please sign in to comment.