From ec2c2e661219ed51ae31ea4e0ebf4278a2f8e94b Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Mon, 23 Jan 2017 14:17:41 -0500 Subject: [PATCH] Ensure isDegenerate can be called for all entities --- modules/osm/entity.js | 3 +++ modules/osm/node.js | 9 +++++++++ test/spec/osm/entity.js | 13 +++++++++++++ test/spec/osm/node.js | 26 ++++++++++++++++++++++++++ 4 files changed, 51 insertions(+) diff --git a/modules/osm/entity.js b/modules/osm/entity.js index 5034c8f43..1c17c3731 100644 --- a/modules/osm/entity.js +++ b/modules/osm/entity.js @@ -153,6 +153,9 @@ osmEntity.prototype = { return false; }, + isDegenerate: function() { + return true; + }, deprecatedTags: function() { var tags = _.toPairs(this.tags); diff --git a/modules/osm/node.js b/modules/osm/node.js index c5dd104cd..faad144a3 100644 --- a/modules/osm/node.js +++ b/modules/osm/node.js @@ -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) { diff --git a/test/spec/osm/entity.js b/test/spec/osm/entity.js index d1a1aa77b..2861dfa43 100644 --- a/test/spec/osm/entity.js +++ b/test/spec/osm/entity.js @@ -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; + }); + }); + }); diff --git a/test/spec/osm/node.js b/test/spec/osm/node.js index 6305a8e73..378624216 100644 --- a/test/spec/osm/node.js +++ b/test/spec/osm/node.js @@ -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'}});