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

View File

@@ -1,4 +1,4 @@
import { geoJoinWays } from '../geo/index';
import { osmJoinWays } from '../osm/index';
export function actionAddMember(relationId, member, memberIndex) {
@@ -9,7 +9,7 @@ export function actionAddMember(relationId, member, memberIndex) {
var members = relation.indexedMembers();
members.push(member);
var joined = geoJoinWays(members, graph);
var joined = osmJoinWays(members, graph);
for (var i = 0; i < joined.length; i++) {
var segment = joined[i];
for (var j = 0; j < segment.length && segment.length >= 2; j++) {

View File

@@ -1,7 +1,6 @@
import _ from 'lodash';
import { actionDeleteWay } from './delete_way';
import { osmIsInterestingTag } from '../osm/index';
import { geoJoinWays } from '../geo/index';
import { osmIsInterestingTag, osmJoinWays } from '../osm/index';
// Join ways at the end node they share.
@@ -32,7 +31,7 @@ export function actionJoin(ids) {
}
}
var joined = geoJoinWays(ways, graph)[0];
var joined = osmJoinWays(ways, graph)[0];
survivor = survivor.update({nodes: _.map(joined.nodes, 'id')});
graph = graph.replace(survivor);
@@ -60,7 +59,7 @@ export function actionJoin(ids) {
if (ids.length < 2 || ids.length !== geometries.line.length)
return 'not_eligible';
var joined = geoJoinWays(ids.map(graph.entity, graph), graph);
var joined = osmJoinWays(ids.map(graph.entity, graph), graph);
if (joined.length > 1)
return 'not_adjacent';

View File

@@ -1,6 +1,6 @@
import _ from 'lodash';
import { geoJoinWays, geoPolygonContainsPolygon } from '../geo/index';
import { osmRelation } from '../osm/index';
import { geoPolygonContainsPolygon } from '../geo/index';
import { osmJoinWays, osmRelation } from '../osm/index';
export function actionMergePolygon(ids, newRelationId) {
@@ -31,7 +31,7 @@ export function actionMergePolygon(ids, newRelationId) {
// Each element is itself an array of objects with an id property, and has a
// locs property which is an array of the locations forming the polygon.
var polygons = entities.multipolygon.reduce(function(polygons, m) {
return polygons.concat(geoJoinWays(m.members, graph));
return polygons.concat(osmJoinWays(m.members, graph));
}, []).concat(entities.closedWay.map(function(d) {
var member = [{id: d.id}];
member.nodes = graph.childNodes(d);

View File

@@ -1,6 +1,10 @@
import { actionSplit } from './split';
import { geoInferRestriction } from '../geo/index';
import { osmRelation, osmWay } from '../osm/index';
import {
osmInferRestriction,
osmRelation,
osmWay
} from '../osm/index';
// Create a restriction relation for `turn`, which must have the following structure:
@@ -17,7 +21,7 @@ import { osmRelation, osmWay } from '../osm/index';
// (The action does not check that these entities form a valid intersection.)
//
// If `restriction` is not provided, it is automatically determined by
// geoInferRestriction.
// osmInferRestriction.
//
// If necessary, the `from` and `to` ways are split. In these cases, `from.node`
// and `to.node` are used to determine which portion of the split ways become
@@ -77,7 +81,7 @@ export function actionRestrictTurn(turn, projection, restrictionId) {
tags: {
type: 'restriction',
restriction: turn.restriction ||
geoInferRestriction(
osmInferRestriction(
graph,
turn.from,
turn.via,

View File

@@ -1,6 +1,6 @@
import _ from 'lodash';
import { osmRelation, osmWay } from '../osm/index';
import { geoIsSimpleMultipolygonOuterMember, geoSphericalDistance } from '../geo/index';
import { osmIsSimpleMultipolygonOuterMember, osmRelation, osmWay } from '../osm/index';
import { geoSphericalDistance } from '../geo/index';
import { actionAddMember } from './add_member';
import { utilWrap } from '../util/index';
@@ -79,7 +79,7 @@ export function actionSplit(nodeId, newWayIds) {
nodesA,
nodesB,
isArea = wayA.isArea(),
isOuter = geoIsSimpleMultipolygonOuterMember(wayA, graph);
isOuter = osmIsSimpleMultipolygonOuterMember(wayA, graph);
if (wayA.isClosed()) {
var nodes = wayA.nodes.slice(0, -1),

View File

@@ -1,18 +1,6 @@
import _ from 'lodash';
export { geoExtent } from './extent.js';
export {
geoIntersection,
geoTurn,
geoInferRestriction
} from './intersection.js';
export {
geoIsSimpleMultipolygonOuterMember,
geoSimpleMultipolygonOuterMember,
geoJoinWays
} from './multipolygon.js';
export { geoRawMercator } from './raw_mercator.js';

View File

@@ -3,6 +3,18 @@ export { osmNode } from './node';
export { osmRelation } from './relation';
export { osmWay } from './way';
export {
osmIntersection,
osmTurn,
osmInferRestriction
} from './intersection.js';
export {
osmIsSimpleMultipolygonOuterMember,
osmSimpleMultipolygonOuterMember,
osmJoinWays
} from './multipolygon.js';
export {
osmOneWayTags,
osmPavedTags,

View File

@@ -1,16 +1,16 @@
import _ from 'lodash';
import { geoAngle } from './index';
import { osmWay } from '../osm/index';
import { geoAngle } from '../geo/index';
import { osmWay } from './way';
export function geoTurn(turn) {
if (!(this instanceof geoTurn))
return new geoTurn(turn);
export function osmTurn(turn) {
if (!(this instanceof osmTurn))
return new osmTurn(turn);
_.extend(this, turn);
}
export function geoIntersection(graph, vertexId) {
export function osmIntersection(graph, vertexId) {
var vertex = graph.entity(vertexId),
parentWays = graph.parentWays(vertex),
coincident = [],
@@ -114,7 +114,7 @@ export function geoIntersection(graph, vertexId) {
}
});
return geoTurn(turn);
return osmTurn(turn);
}
@@ -172,7 +172,7 @@ export function geoIntersection(graph, vertexId) {
}
export function geoInferRestriction(graph, from, via, to, projection) {
export function osmInferRestriction(graph, from, via, to, projection) {
var fromWay = graph.entity(from.way),
fromNode = graph.entity(from.node),
toWay = graph.entity(to.way),

View File

@@ -4,7 +4,7 @@ import { actionReverse } from '../actions/reverse';
// For fixing up rendering of multipolygons with tags on the outer member.
// https://github.com/openstreetmap/iD/issues/613
export function geoIsSimpleMultipolygonOuterMember(entity, graph) {
export function osmIsSimpleMultipolygonOuterMember(entity, graph) {
if (entity.type !== 'way')
return false;
@@ -29,7 +29,7 @@ export function geoIsSimpleMultipolygonOuterMember(entity, graph) {
}
export function geoSimpleMultipolygonOuterMember(entity, graph) {
export function osmSimpleMultipolygonOuterMember(entity, graph) {
if (entity.type !== 'way')
return false;
@@ -66,16 +66,16 @@ export function geoSimpleMultipolygonOuterMember(entity, graph) {
// with appropriate order reversal and start/end coordinate de-duplication.
//
// Members of `array` must have, at minimum, `type` and `id` properties.
// Thus either an array of `iD.Way`s or a relation member array may be
// Thus either an array of `osmWay`s or a relation member array may be
// used.
//
// If an member has a `tags` property, its tags will be reversed via
// `iD.actionReverse` in the output.
// `actionReverse` in the output.
//
// Incomplete members (those for which `graph.hasEntity(element.id)` returns
// false) and non-way members are ignored.
//
export function geoJoinWays(array, graph) {
export function osmJoinWays(array, graph) {
var joined = [], member, current, nodes, first, last, i, how, what;
array = array.filter(function(member) {

View File

@@ -1,9 +1,9 @@
import * as d3 from 'd3';
import _ from 'lodash';
import { osmEntity } from './entity';
import { osmJoinWays } from './multipolygon';
import {
geoExtent,
geoJoinWays,
geoPolygonContainsPolygon,
geoPolygonIntersectsPolygon
} from '../geo/index';
@@ -263,8 +263,8 @@ _.extend(osmRelation.prototype, {
var outers = this.members.filter(function(m) { return 'outer' === (m.role || 'outer'); }),
inners = this.members.filter(function(m) { return 'inner' === m.role; });
outers = geoJoinWays(outers, resolver);
inners = geoJoinWays(inners, resolver);
outers = osmJoinWays(outers, resolver);
inners = osmJoinWays(inners, resolver);
outers = outers.map(function(outer) { return _.map(outer.nodes, 'loc'); });
inners = inners.map(function(inner) { return _.map(inner.nodes, 'loc'); });

View File

@@ -1,7 +1,6 @@
import * as d3 from 'd3';
import _ from 'lodash';
import { geoIsSimpleMultipolygonOuterMember } from '../geo/index';
import { osmEntity } from '../osm/index';
import { osmEntity, osmIsSimpleMultipolygonOuterMember } from '../osm/index';
import { svgPath, svgTagClasses } from './index';
@@ -45,7 +44,7 @@ export function svgAreas(projection, context) {
var entity = entities[i];
if (entity.geometry(graph) !== 'area') continue;
multipolygon = geoIsSimpleMultipolygonOuterMember(entity, graph);
multipolygon = osmIsSimpleMultipolygonOuterMember(entity, graph);
if (multipolygon) {
areas[multipolygon.id] = {
entity: multipolygon.mergeTags(entity.tags),

View File

@@ -7,8 +7,7 @@ import {
svgTagClasses
} from './index';
import { geoSimpleMultipolygonOuterMember } from '../geo/index';
import { osmEntity } from '../osm/index';
import { osmEntity, osmSimpleMultipolygonOuterMember } from '../osm/index';
import { utilDetect } from '../util/detect';
@@ -43,7 +42,7 @@ export function svgLines(projection) {
for (var i = 0; i < entities.length; i++) {
var entity = entities[i],
outer = geoSimpleMultipolygonOuterMember(entity, graph);
outer = osmSimpleMultipolygonOuterMember(entity, graph);
if (outer) {
ways.push(entity.mergeTags(outer.tags));
} else if (entity.geometry(graph) === 'line') {

View File

@@ -2,7 +2,13 @@ import * as d3 from 'd3';
import { t } from '../../util/locale';
import { behaviorHover } from '../../behavior/index';
import { osmEntity } from '../../osm/index';
import {
osmEntity,
osmIntersection,
osmInferRestriction,
osmTurn
} from '../../osm/index';
import {
actionRestrictTurn,
@@ -11,10 +17,7 @@ import {
import {
geoExtent,
geoIntersection,
geoRawMercator,
geoTurn,
geoInferRestriction
geoRawMercator
} from '../../geo/index';
import {
@@ -59,7 +62,7 @@ export function uiFieldRestrictions(field, context) {
.attr('class', 'restriction-help');
var intersection = geoIntersection(context.graph(), vertexID),
var intersection = osmIntersection(context.graph(), vertexID),
graph = intersection.graph,
vertex = graph.entity(vertexID),
filter = utilFunctor(true),
@@ -131,7 +134,7 @@ export function uiFieldRestrictions(field, context) {
if (datum instanceof osmEntity) {
fromNodeID = intersection.adjacentNodeId(datum.id);
render();
} else if (datum instanceof geoTurn) {
} else if (datum instanceof osmTurn) {
if (datum.restriction) {
context.perform(
actionUnrestrictTurn(datum, projection),
@@ -149,7 +152,7 @@ export function uiFieldRestrictions(field, context) {
function mouseover() {
var datum = d3.event.target.__data__;
if (datum instanceof geoTurn) {
if (datum instanceof osmTurn) {
var graph = context.graph(),
presets = context.presets(),
preset;
@@ -158,7 +161,7 @@ export function uiFieldRestrictions(field, context) {
preset = presets.match(graph.entity(datum.restriction), graph);
} else {
preset = presets.item('type/restriction/' +
geoInferRestriction(
osmInferRestriction(
graph,
datum.from,
datum.via,

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>

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);

View File

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

View File

@@ -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([]);
});
});

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');

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;

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;