Fix close() for single node ways

This commit is contained in:
Bryan Housel
2017-01-12 15:56:46 +05:30
parent cadb38009a
commit f109efda7b
2 changed files with 9 additions and 5 deletions

View File

@@ -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 });
},

View File

@@ -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 () {
@@ -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 () {