mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-19 20:23:12 +00:00
Ensure isDegenerate can be called for all entities
This commit is contained in:
@@ -153,6 +153,9 @@ osmEntity.prototype = {
|
||||
return false;
|
||||
},
|
||||
|
||||
isDegenerate: function() {
|
||||
return true;
|
||||
},
|
||||
|
||||
deprecatedTags: function() {
|
||||
var tags = _.toPairs(this.tags);
|
||||
|
||||
@@ -36,6 +36,15 @@ _.extend(osmNode.prototype, {
|
||||
},
|
||||
|
||||
|
||||
isDegenerate: function() {
|
||||
return !(
|
||||
Array.isArray(this.loc) && this.loc.length === 2 &&
|
||||
this.loc[0] >= -180 && this.loc[0] <= 180 &&
|
||||
this.loc[1] >= -90 && this.loc[1] <= 90
|
||||
);
|
||||
},
|
||||
|
||||
|
||||
isIntersection: function(resolver) {
|
||||
return resolver.transient(this, 'isIntersection', function() {
|
||||
return resolver.parentWays(this).filter(function(parent) {
|
||||
|
||||
@@ -243,4 +243,17 @@ describe('iD.osmEntity', function () {
|
||||
expect(iD.Entity({tags: {'tiger:source': 'blah', 'tiger:foo': 'bar'}}).hasInterestingTags()).to.equal(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#isHighwayIntersection', function () {
|
||||
it('returns false', function () {
|
||||
expect(iD.Entity().isHighwayIntersection()).to.be.false;
|
||||
});
|
||||
});
|
||||
|
||||
describe('#isDegenerate', function () {
|
||||
it('returns true', function () {
|
||||
expect(iD.Entity().isDegenerate()).to.be.true;
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -79,6 +79,32 @@ describe('iD.osmNode', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#isDegenerate', function () {
|
||||
it('returns true if node has invalid loc', function () {
|
||||
expect(iD.Node().isDegenerate()).to.be.equal(true, 'no loc');
|
||||
expect(iD.Node({loc: ''}).isDegenerate()).to.be.equal(true, 'empty string loc');
|
||||
expect(iD.Node({loc: []}).isDegenerate()).to.be.equal(true, 'empty array loc');
|
||||
expect(iD.Node({loc: [0]}).isDegenerate()).to.be.equal(true, '1-array loc');
|
||||
expect(iD.Node({loc: [0, 0, 0]}).isDegenerate()).to.be.equal(true, '3-array loc');
|
||||
expect(iD.Node({loc: [-181, 0]}).isDegenerate()).to.be.equal(true, '< min lon');
|
||||
expect(iD.Node({loc: [181, 0]}).isDegenerate()).to.be.equal(true, '> max lon');
|
||||
expect(iD.Node({loc: [0, -91]}).isDegenerate()).to.be.equal(true, '< min lat');
|
||||
expect(iD.Node({loc: [0, 91]}).isDegenerate()).to.be.equal(true, '> max lat');
|
||||
expect(iD.Node({loc: [Infinity, 0]}).isDegenerate()).to.be.equal(true, 'Infinity lon');
|
||||
expect(iD.Node({loc: [0, Infinity]}).isDegenerate()).to.be.equal(true, 'Infinity lat');
|
||||
expect(iD.Node({loc: [NaN, 0]}).isDegenerate()).to.be.equal(true, 'NaN lon');
|
||||
expect(iD.Node({loc: [0, NaN]}).isDegenerate()).to.be.equal(true, 'NaN lat');
|
||||
});
|
||||
|
||||
it('returns false if node has valid loc', function () {
|
||||
expect(iD.Node({loc: [0, 0]}).isDegenerate()).to.be.equal(false, '2-array loc');
|
||||
expect(iD.Node({loc: [-180, 0]}).isDegenerate()).to.be.equal(false, 'min lon');
|
||||
expect(iD.Node({loc: [180, 0]}).isDegenerate()).to.be.equal(false, 'max lon');
|
||||
expect(iD.Node({loc: [0, -90]}).isDegenerate()).to.be.equal(false, 'min lat');
|
||||
expect(iD.Node({loc: [0, 90]}).isDegenerate()).to.be.equal(false, 'max lat');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#asJXON', function () {
|
||||
it('converts a node to jxon', function() {
|
||||
var node = iD.Node({id: 'n-1', loc: [-77, 38], tags: {amenity: 'cafe'}});
|
||||
|
||||
Reference in New Issue
Block a user