mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-21 07:46:58 +02:00
Simplify; test; fix
This commit is contained in:
@@ -129,11 +129,11 @@ iD.Way = iD.Entity.extend({
|
||||
nodes: [],
|
||||
|
||||
isOneWay: function() {
|
||||
return !!(this.tags.oneway && this.tags.oneway === 'yes');
|
||||
return this.tags.oneway === 'yes';
|
||||
},
|
||||
|
||||
isClosed: function() {
|
||||
return (!this.nodes.length) || this.nodes[this.nodes.length - 1] === this.nodes[0];
|
||||
return this.nodes.length > 0 && this.nodes[this.nodes.length - 1] === this.nodes[0];
|
||||
},
|
||||
|
||||
// a way is an area if:
|
||||
@@ -143,14 +143,11 @@ iD.Way = iD.Entity.extend({
|
||||
// - doesn't have area=no
|
||||
// - doesn't have highway tag
|
||||
isArea: function() {
|
||||
return (this.tags.area && this.tags.area === 'yes') ||
|
||||
return this.tags.area === 'yes' ||
|
||||
(this.isClosed() &&
|
||||
// area-ness is disabled
|
||||
(!this.tags.area || this.tags.area !== 'no') &&
|
||||
// Tags that disable area-ness unless they are accompanied by
|
||||
// area=yes
|
||||
!this.tags.highway &&
|
||||
!this.tags.barrier);
|
||||
this.tags.area !== 'no' &&
|
||||
!this.tags.highway &&
|
||||
!this.tags.barrier);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -52,6 +52,10 @@ describe('iD.Way', function() {
|
||||
});
|
||||
|
||||
describe('#isClosed', function() {
|
||||
it('returns false when the way has no nodes', function() {
|
||||
expect(iD.Way().isClosed()).to.equal(false);
|
||||
});
|
||||
|
||||
it('returns false when the way ends are not equal', function() {
|
||||
expect(iD.Way({nodes: ['n1', 'n2']}).isClosed()).to.equal(false);
|
||||
});
|
||||
@@ -74,4 +78,26 @@ describe('iD.Way', function() {
|
||||
expect(iD.Way({tags: { oneway: 'yes' }}).isOneWay()).to.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#isArea', function() {
|
||||
it('returns false when the way has no tags', function() {
|
||||
expect(iD.Way().isArea()).to.equal(false);
|
||||
});
|
||||
|
||||
it('returns true if the way has tag area=yes', function() {
|
||||
expect(iD.Way({tags: { area: 'yes' }}).isArea()).to.equal(true);
|
||||
});
|
||||
|
||||
it('returns true if the way is closed and has no tags', function() {
|
||||
expect(iD.Way({nodes: ['n1', 'n1']}).isArea()).to.equal(true);
|
||||
});
|
||||
|
||||
it('returns false if the way is closed and has tag area=no', function() {
|
||||
expect(iD.Way({tags: { area: 'no' }, nodes: ['n1', 'n1']}).isArea()).to.equal(false);
|
||||
});
|
||||
|
||||
it('returns false if the way is closed and has highway tag', function() {
|
||||
expect(iD.Way({tags: { highway: 'residential' }, nodes: ['n1', 'n1']}).isArea()).to.equal(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user