Refactor Intersection, Multipolygon from geo to osm

This commit is contained in:
Bryan Housel
2016-10-11 23:09:27 -04:00
parent 07fa5fcc34
commit f50e80d0b5
20 changed files with 111 additions and 106 deletions
+2 -2
View File
@@ -73,8 +73,6 @@
<script src='spec/geo/extent.js'></script>
<script src='spec/geo/geo.js'></script>
<script src='spec/geo/intersection.js'></script>
<script src='spec/geo/multipolygon.js'></script>
<script src='spec/lib/d3.combobox.js'></script>
<script src='spec/lib/d3.keybinding.js'></script>
@@ -84,6 +82,8 @@
<script src='spec/modes/add_point.js'></script>
<script src='spec/osm/entity.js'></script>
<script src='spec/osm/intersection.js'></script>
<script src='spec/osm/multipolygon.js'></script>
<script src='spec/osm/node.js'></script>
<script src='spec/osm/relation.js'></script>
<script src='spec/osm/way.js'></script>
+1 -1
View File
@@ -1,4 +1,4 @@
describe('iD.Entity', function () {
describe('iD.osmEntity', function () {
it('returns a subclass of the appropriate type', function () {
expect(iD.Entity({type: 'node'})).be.an.instanceOf(iD.Node);
expect(iD.Entity({type: 'way'})).be.an.instanceOf(iD.Way);
@@ -1,4 +1,4 @@
describe('iD.geoIntersection', function() {
describe('iD.osmIntersection', function() {
describe('highways', function() {
it('excludes non-highways', function() {
var graph = iD.Graph([
@@ -8,7 +8,7 @@ describe('iD.geoIntersection', function() {
iD.Way({id: '=', nodes: ['u', '*']}),
iD.Way({id: '-', nodes: ['*', 'w']})
]);
expect(iD.geoIntersection(graph, '*').ways).to.eql([]);
expect(iD.osmIntersection(graph, '*').ways).to.eql([]);
});
it('excludes degenerate highways', function() {
@@ -18,7 +18,7 @@ describe('iD.geoIntersection', function() {
iD.Way({id: '=', nodes: ['u', '*'], tags: {highway: 'residential'}}),
iD.Way({id: '-', nodes: ['*'], tags: {highway: 'residential'}})
]);
expect(_.map(iD.geoIntersection(graph, '*').ways, 'id')).to.eql(['=']);
expect(_.map(iD.osmIntersection(graph, '*').ways, 'id')).to.eql(['=']);
});
it('excludes coincident highways', function() {
@@ -28,7 +28,7 @@ describe('iD.geoIntersection', function() {
iD.Way({id: '=', nodes: ['u', '*'], tags: {highway: 'residential'}}),
iD.Way({id: '-', nodes: ['u', '*'], tags: {highway: 'residential'}})
]);
expect(iD.geoIntersection(graph, '*').ways).to.eql([]);
expect(iD.osmIntersection(graph, '*').ways).to.eql([]);
});
it('includes line highways', function() {
@@ -39,7 +39,7 @@ describe('iD.geoIntersection', function() {
iD.Way({id: '=', nodes: ['u', '*'], tags: {highway: 'residential'}}),
iD.Way({id: '-', nodes: ['*', 'w']})
]);
expect(_.map(iD.geoIntersection(graph, '*').ways, 'id')).to.eql(['=']);
expect(_.map(iD.osmIntersection(graph, '*').ways, 'id')).to.eql(['=']);
});
it('excludes area highways', function() {
@@ -49,7 +49,7 @@ describe('iD.geoIntersection', function() {
iD.Node({id: 'w'}),
iD.Way({id: '=', nodes: ['u', '*', 'w'], tags: {highway: 'pedestrian', area: 'yes'}})
]);
expect(iD.geoIntersection(graph, '*').ways).to.eql([]);
expect(iD.osmIntersection(graph, '*').ways).to.eql([]);
});
it('auto-splits highways at the intersection', function() {
@@ -59,7 +59,7 @@ describe('iD.geoIntersection', function() {
iD.Node({id: 'w'}),
iD.Way({id: '=', nodes: ['u', '*', 'w'], tags: {highway: 'residential'}})
]);
expect(_.map(iD.geoIntersection(graph, '*').ways, 'id')).to.eql(['=-a', '=-b']);
expect(_.map(iD.osmIntersection(graph, '*').ways, 'id')).to.eql(['=-a', '=-b']);
});
});
@@ -73,7 +73,7 @@ describe('iD.geoIntersection', function() {
iD.Way({id: '=', nodes: ['u', '*'], tags: {highway: 'residential'}}),
iD.Way({id: '-', nodes: ['*', 'w'], tags: {highway: 'residential'}})
]),
turns = iD.geoIntersection(graph, '*').turns('u');
turns = iD.osmIntersection(graph, '*').turns('u');
expect(turns.length).to.eql(2);
expect(turns[0]).to.eql({
@@ -92,7 +92,7 @@ describe('iD.geoIntersection', function() {
iD.Way({id: '=', nodes: ['u', '*'], tags: {highway: 'residential'}}),
iD.Way({id: '-', nodes: ['w', '*'], tags: {highway: 'residential'}})
]),
turns = iD.geoIntersection(graph, '*').turns('u');
turns = iD.osmIntersection(graph, '*').turns('u');
expect(turns.length).to.eql(2);
expect(turns[0]).to.eql({
@@ -116,7 +116,7 @@ describe('iD.geoIntersection', function() {
iD.Way({id: '=', nodes: ['u', '*'], tags: {highway: 'residential'}}),
iD.Way({id: '-', nodes: ['w', '*', 'x'], tags: {highway: 'residential'}})
]),
turns = iD.geoIntersection(graph, '*').turns('w');
turns = iD.osmIntersection(graph, '*').turns('w');
expect(turns.length).to.eql(3);
expect(turns[0]).to.eql({
@@ -151,7 +151,7 @@ describe('iD.geoIntersection', function() {
iD.Way({id: '=', nodes: ['u', '*'], tags: {highway: 'residential'}}),
iD.Way({id: '-', nodes: ['w', '*', 'x'], tags: {highway: 'residential'}})
]),
turns = iD.geoIntersection(graph, '*').turns('u');
turns = iD.osmIntersection(graph, '*').turns('u');
expect(turns.length).to.eql(3);
expect(turns[0]).to.eql({
@@ -181,7 +181,7 @@ describe('iD.geoIntersection', function() {
iD.Way({id: '=', nodes: ['u', '*'], tags: {highway: 'residential', oneway: 'yes'}}),
iD.Way({id: '-', nodes: ['*', 'w'], tags: {highway: 'residential'}})
]),
turns = iD.geoIntersection(graph, '*').turns('u');
turns = iD.osmIntersection(graph, '*').turns('u');
expect(turns).to.eql([{
from: {node: 'u', way: '='},
@@ -199,7 +199,7 @@ describe('iD.geoIntersection', function() {
iD.Way({id: '=', nodes: ['*', 'u'], tags: {highway: 'residential', oneway: '-1'}}),
iD.Way({id: '-', nodes: ['*', 'w'], tags: {highway: 'residential'}})
]),
turns = iD.geoIntersection(graph, '*').turns('u');
turns = iD.osmIntersection(graph, '*').turns('u');
expect(turns).to.eql([{
from: {node: 'u', way: '='},
@@ -217,7 +217,7 @@ describe('iD.geoIntersection', function() {
iD.Way({id: '=', nodes: ['*', 'u'], tags: {highway: 'residential', oneway: 'yes'}}),
iD.Way({id: '-', nodes: ['*', 'w'], tags: {highway: 'residential'}})
]);
expect(iD.geoIntersection(graph, '*').turns('u')).to.eql([]);
expect(iD.osmIntersection(graph, '*').turns('u')).to.eql([]);
});
it('omits turns from a reverse oneway forward', function() {
@@ -229,7 +229,7 @@ describe('iD.geoIntersection', function() {
iD.Way({id: '=', nodes: ['u', '*'], tags: {highway: 'residential', oneway: '-1'}}),
iD.Way({id: '-', nodes: ['*', 'w'], tags: {highway: 'residential'}})
]);
expect(iD.geoIntersection(graph, '*').turns('u')).to.eql([]);
expect(iD.osmIntersection(graph, '*').turns('u')).to.eql([]);
});
it('permits turns onto a oneway forward', function() {
@@ -241,7 +241,7 @@ describe('iD.geoIntersection', function() {
iD.Way({id: '=', nodes: ['u', '*'], tags: {highway: 'residential'}}),
iD.Way({id: '-', nodes: ['*', 'w'], tags: {highway: 'residential', oneway: 'yes'}})
]),
turns = iD.geoIntersection(graph, '*').turns('u');
turns = iD.osmIntersection(graph, '*').turns('u');
expect(turns.length).to.eql(2);
expect(turns[0]).to.eql({
@@ -260,7 +260,7 @@ describe('iD.geoIntersection', function() {
iD.Way({id: '=', nodes: ['u', '*'], tags: {highway: 'residential'}}),
iD.Way({id: '-', nodes: ['w', '*'], tags: {highway: 'residential', oneway: '-1'}})
]),
turns = iD.geoIntersection(graph, '*').turns('u');
turns = iD.osmIntersection(graph, '*').turns('u');
expect(turns.length).to.eql(2);
expect(turns[0]).to.eql({
@@ -279,7 +279,7 @@ describe('iD.geoIntersection', function() {
iD.Way({id: '=', nodes: ['u', '*'], tags: {highway: 'residential'}}),
iD.Way({id: '-', nodes: ['w', '*'], tags: {highway: 'residential', oneway: 'yes'}})
]);
expect(iD.geoIntersection(graph, '*').turns('u').length).to.eql(1);
expect(iD.osmIntersection(graph, '*').turns('u').length).to.eql(1);
});
it('omits turns onto a reverse oneway forward', function() {
@@ -291,7 +291,7 @@ describe('iD.geoIntersection', function() {
iD.Way({id: '=', nodes: ['u', '*'], tags: {highway: 'residential'}}),
iD.Way({id: '-', nodes: ['*', 'w'], tags: {highway: 'residential', oneway: '-1'}})
]);
expect(iD.geoIntersection(graph, '*').turns('u').length).to.eql(1);
expect(iD.osmIntersection(graph, '*').turns('u').length).to.eql(1);
});
it('includes U-turns', function() {
@@ -303,7 +303,7 @@ describe('iD.geoIntersection', function() {
iD.Way({id: '=', nodes: ['u', '*'], tags: {highway: 'residential'}}),
iD.Way({id: '-', nodes: ['*', 'w'], tags: {highway: 'residential'}})
]),
turns = iD.geoIntersection(graph, '*').turns('u');
turns = iD.osmIntersection(graph, '*').turns('u');
expect(turns.length).to.eql(2);
expect(turns[1]).to.eql({
@@ -328,7 +328,7 @@ describe('iD.geoIntersection', function() {
{id: '*', role: 'via', type: 'node'}
]})
]),
turns = iD.geoIntersection(graph, '*').turns('u');
turns = iD.osmIntersection(graph, '*').turns('u');
expect(turns.length).to.eql(2);
expect(turns[0]).to.eql({
@@ -357,7 +357,7 @@ describe('iD.geoIntersection', function() {
{id: '*', role: 'via', type: 'node'}
]})
]),
turns = iD.geoIntersection(graph, '*').turns('u');
turns = iD.osmIntersection(graph, '*').turns('u');
expect(turns.length).to.eql(3);
expect(turns[0]).to.eql({
@@ -398,7 +398,7 @@ describe('iD.geoIntersection', function() {
iD.Way({id: '-', nodes: ['*', 'a', 'b', 'c', '*'], tags: {highway: 'residential'}}),
iD.Way({id: '=', nodes: ['*', 'u'], tags: {highway: 'residential'}})
]),
turns = iD.geoIntersection(graph, '*').turns('u');
turns = iD.osmIntersection(graph, '*').turns('u');
expect(turns.length).to.eql(3);
expect(turns[0]).to.eql({
@@ -434,7 +434,7 @@ describe('iD.geoIntersection', function() {
iD.Way({id: '-', nodes: ['*', 'a', 'b', 'c', '*'], tags: {highway: 'residential'}}),
iD.Way({id: '=', nodes: ['*', 'u'], tags: {highway: 'residential'}})
]),
turns = iD.geoIntersection(graph, '*').turns('a');
turns = iD.osmIntersection(graph, '*').turns('a');
expect(turns.length).to.eql(3);
expect(turns[0]).to.eql({
@@ -470,7 +470,7 @@ describe('iD.geoIntersection', function() {
iD.Way({id: '-', nodes: ['*', 'a', 'b', 'c', '*'], tags: {highway: 'residential', oneway: 'yes'}}),
iD.Way({id: '=', nodes: ['*', 'u'], tags: {highway: 'residential'}})
]),
turns = iD.geoIntersection(graph, '*').turns('u');
turns = iD.osmIntersection(graph, '*').turns('u');
expect(turns.length).to.eql(2);
expect(turns[0]).to.eql({
@@ -501,7 +501,7 @@ describe('iD.geoIntersection', function() {
iD.Way({id: '-', nodes: ['*', 'a', 'b', 'c', '*'], tags: {highway: 'residential', oneway: '-1'}}),
iD.Way({id: '=', nodes: ['*', 'u'], tags: {highway: 'residential'}})
]),
turns = iD.geoIntersection(graph, '*').turns('u');
turns = iD.osmIntersection(graph, '*').turns('u');
expect(turns.length).to.eql(2);
expect(turns[0]).to.eql({
@@ -532,7 +532,7 @@ describe('iD.geoIntersection', function() {
iD.Way({id: '-', nodes: ['*', 'a', 'b', 'c', '*'], tags: {highway: 'residential', oneway: 'yes'}}),
iD.Way({id: '=', nodes: ['*', 'u'], tags: {highway: 'residential'}})
]),
turns = iD.geoIntersection(graph, '*').turns('c');
turns = iD.osmIntersection(graph, '*').turns('c');
expect(turns.length).to.eql(2);
expect(turns[0]).to.eql({
@@ -562,7 +562,7 @@ describe('iD.geoIntersection', function() {
iD.Way({id: '-', nodes: ['*', 'a', 'b', 'c', '*'], tags: {highway: 'residential', oneway: '-1'}}),
iD.Way({id: '=', nodes: ['*', 'u'], tags: {highway: 'residential'}})
]),
turns = iD.geoIntersection(graph, '*').turns('a');
turns = iD.osmIntersection(graph, '*').turns('a');
expect(turns.length).to.eql(2);
expect(turns[0]).to.eql({
@@ -1,4 +1,4 @@
describe('iD.geoSimpleMultipolygonOuterMember', function() {
describe('iD.osmSimpleMultipolygonOuterMember', function() {
it('returns the outer member of a simple multipolygon', function() {
var inner = iD.Way(),
outer = iD.Way(),
@@ -8,8 +8,8 @@ describe('iD.geoSimpleMultipolygonOuterMember', function() {
}),
graph = iD.Graph([inner, outer, relation]);
expect(iD.geoSimpleMultipolygonOuterMember(inner, graph)).to.equal(outer);
expect(iD.geoSimpleMultipolygonOuterMember(outer, graph)).to.equal(outer);
expect(iD.osmSimpleMultipolygonOuterMember(inner, graph)).to.equal(outer);
expect(iD.osmSimpleMultipolygonOuterMember(outer, graph)).to.equal(outer);
});
it('returns falsy for a complex multipolygon', function() {
@@ -23,9 +23,9 @@ describe('iD.geoSimpleMultipolygonOuterMember', function() {
}),
graph = iD.Graph([inner, outer1, outer2, relation]);
expect(iD.geoSimpleMultipolygonOuterMember(inner, graph)).not.to.be.ok;
expect(iD.geoSimpleMultipolygonOuterMember(outer1, graph)).not.to.be.ok;
expect(iD.geoSimpleMultipolygonOuterMember(outer2, graph)).not.to.be.ok;
expect(iD.osmSimpleMultipolygonOuterMember(inner, graph)).not.to.be.ok;
expect(iD.osmSimpleMultipolygonOuterMember(outer1, graph)).not.to.be.ok;
expect(iD.osmSimpleMultipolygonOuterMember(outer2, graph)).not.to.be.ok;
});
it('handles incomplete relations', function() {
@@ -36,17 +36,18 @@ describe('iD.geoSimpleMultipolygonOuterMember', function() {
}),
graph = iD.Graph([way, relation]);
expect(iD.geoSimpleMultipolygonOuterMember(way, graph)).to.be.undefined;
expect(iD.osmSimpleMultipolygonOuterMember(way, graph)).to.be.undefined;
});
});
describe('iD.geoJoinWays', function() {
describe('iD.osmJoinWays', function() {
it('returns an array of members with nodes properties', function() {
var node = iD.Node({loc: [0, 0]}),
way = iD.Way({nodes: [node.id]}),
member = {id: way.id, type: 'way'},
graph = iD.Graph([node, way]),
result = iD.geoJoinWays([member], graph);
result = iD.osmJoinWays([member], graph);
expect(result.length).to.equal(1);
expect(result[0].nodes.length).to.equal(1);
@@ -72,7 +73,7 @@ describe('iD.geoJoinWays', function() {
]})
]);
var result = iD.geoJoinWays(graph.entity('r').members, graph);
var result = iD.osmJoinWays(graph.entity('r').members, graph);
expect(_.map(result[0], 'id')).to.eql(['=', '-', '~']);
});
@@ -89,7 +90,7 @@ describe('iD.geoJoinWays', function() {
iD.Way({id: '=', nodes: ['c', 'b'], tags: {'oneway': 'yes', 'lanes:forward': 2}})
]);
var result = iD.geoJoinWays([graph.entity('-'), graph.entity('=')], graph);
var result = iD.osmJoinWays([graph.entity('-'), graph.entity('=')], graph);
expect(result[0][1].tags).to.eql({'oneway': '-1', 'lanes:backward': 2});
});
@@ -97,12 +98,12 @@ describe('iD.geoJoinWays', function() {
var node = iD.Node({loc: [0, 0]}),
member = {id: 'n', type: 'node'},
graph = iD.Graph([node]);
expect(iD.geoJoinWays([member], graph)).to.eql([]);
expect(iD.osmJoinWays([member], graph)).to.eql([]);
});
it('ignores incomplete members', function() {
var member = {id: 'w', type: 'way'},
graph = iD.Graph();
expect(iD.geoJoinWays([member], graph)).to.eql([]);
expect(iD.osmJoinWays([member], graph)).to.eql([]);
});
});
+1 -1
View File
@@ -1,4 +1,4 @@
describe('iD.Node', function () {
describe('iD.osmNode', function () {
it('returns a node', function () {
expect(iD.Node()).to.be.an.instanceOf(iD.Node);
expect(iD.Node().type).to.equal('node');
+1 -1
View File
@@ -1,4 +1,4 @@
describe('iD.Relation', function () {
describe('iD.osmRelation', function () {
if (iD.debug) {
it('freezes nodes', function () {
expect(Object.isFrozen(iD.Relation().members)).to.be.true;
+1 -1
View File
@@ -1,4 +1,4 @@
describe('iD.Way', function() {
describe('iD.osmWay', function() {
if (iD.debug) {
it('freezes nodes', function () {
expect(Object.isFrozen(iD.Way().nodes)).to.be.true;