From 748abdb9502a12b366145e78942d4a0800992074 Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Tue, 9 Jan 2018 11:41:54 -0500 Subject: [PATCH] Code formatting --- test/spec/actions/split.js | 1044 +++++++++++++++++---------------- test/spec/osm/multipolygon.js | 196 ++++--- 2 files changed, 642 insertions(+), 598 deletions(-) diff --git a/test/spec/actions/split.js b/test/spec/actions/split.js index e722929fd..d09148499 100644 --- a/test/spec/actions/split.js +++ b/test/spec/actions/split.js @@ -1,581 +1,615 @@ describe('iD.actionSplit', function () { beforeEach(function () { - iD.areaKeys = iD.Context().presets().areaKeys(); + iD.areaKeys = iD.coreContext().presets().areaKeys(); }); + describe('#disabled', function () { it('returns falsy for a non-end node of a single way', function () { - var graph = iD.Graph([ - iD.Node({id: 'a'}), - iD.Node({id: 'b'}), - iD.Node({id: 'c'}), - iD.Way({id: '-', nodes: ['a', 'b', 'c']}) - ]); + var graph = iD.coreGraph([ + iD.osmNode({id: 'a'}), + iD.osmNode({id: 'b'}), + iD.osmNode({id: 'c'}), + iD.osmWay({id: '-', nodes: ['a', 'b', 'c']}) + ]); expect(iD.actionSplit('b').disabled(graph)).not.to.be.ok; }); it('returns falsy for an intersection of two ways', function () { - var graph = iD.Graph([ - iD.Node({id: 'a'}), - iD.Node({id: 'b'}), - iD.Node({id: 'c'}), - iD.Node({id: 'c'}), - iD.Node({id: '*'}), - iD.Way({id: '-', nodes: ['a', '*', 'b']}), - iD.Way({id: '|', nodes: ['c', '*', 'd']}) - ]); + var graph = iD.coreGraph([ + iD.osmNode({id: 'a'}), + iD.osmNode({id: 'b'}), + iD.osmNode({id: 'c'}), + iD.osmNode({id: 'c'}), + iD.osmNode({id: '*'}), + iD.osmWay({id: '-', nodes: ['a', '*', 'b']}), + iD.osmWay({id: '|', nodes: ['c', '*', 'd']}) + ]); expect(iD.actionSplit('*').disabled(graph)).not.to.be.ok; }); it('returns falsy for an intersection of two ways with parent way specified', function () { - var graph = iD.Graph([ - iD.Node({id: 'a'}), - iD.Node({id: 'b'}), - iD.Node({id: 'c'}), - iD.Node({id: 'c'}), - iD.Node({id: '*'}), - iD.Way({id: '-', nodes: ['a', '*', 'b']}), - iD.Way({id: '|', nodes: ['c', '*', 'd']}) - ]); + var graph = iD.coreGraph([ + iD.osmNode({id: 'a'}), + iD.osmNode({id: 'b'}), + iD.osmNode({id: 'c'}), + iD.osmNode({id: 'c'}), + iD.osmNode({id: '*'}), + iD.osmWay({id: '-', nodes: ['a', '*', 'b']}), + iD.osmWay({id: '|', nodes: ['c', '*', 'd']}) + ]); expect(iD.actionSplit('*').limitWays(['-']).disabled(graph)).not.to.be.ok; }); it('returns falsy for a self-intersection', function () { - var graph = iD.Graph([ - iD.Node({id: 'a'}), - iD.Node({id: 'b'}), - iD.Node({id: 'c'}), - iD.Node({id: 'c'}), - iD.Way({id: '-', nodes: ['a', 'b', 'c', 'a', 'd']}) - ]); + var graph = iD.coreGraph([ + iD.osmNode({id: 'a'}), + iD.osmNode({id: 'b'}), + iD.osmNode({id: 'c'}), + iD.osmNode({id: 'c'}), + iD.osmWay({id: '-', nodes: ['a', 'b', 'c', 'a', 'd']}) + ]); expect(iD.actionSplit('a').disabled(graph)).not.to.be.ok; }); it('returns \'not_eligible\' for the first node of a single way', function () { - var graph = iD.Graph([ - iD.Node({id: 'a'}), - iD.Node({id: 'b'}), - iD.Way({id: '-', nodes: ['a', 'b']}) - ]); + var graph = iD.coreGraph([ + iD.osmNode({id: 'a'}), + iD.osmNode({id: 'b'}), + iD.osmWay({id: '-', nodes: ['a', 'b']}) + ]); expect(iD.actionSplit('a').disabled(graph)).to.equal('not_eligible'); }); it('returns \'not_eligible\' for the last node of a single way', function () { - var graph = iD.Graph([ - iD.Node({id: 'a'}), - iD.Node({id: 'b'}), - iD.Way({id: '-', nodes: ['a', 'b']}) - ]); + var graph = iD.coreGraph([ + iD.osmNode({id: 'a'}), + iD.osmNode({id: 'b'}), + iD.osmWay({id: '-', nodes: ['a', 'b']}) + ]); expect(iD.actionSplit('b').disabled(graph)).to.equal('not_eligible'); }); it('returns \'not_eligible\' for an intersection of two ways with non-parent way specified', function () { - var graph = iD.Graph([ - iD.Node({id: 'a'}), - iD.Node({id: 'b'}), - iD.Node({id: 'c'}), - iD.Node({id: 'c'}), - iD.Node({id: '*'}), - iD.Way({id: '-', nodes: ['a', '*', 'b']}), - iD.Way({id: '|', nodes: ['c', '*', 'd']}) - ]); + var graph = iD.coreGraph([ + iD.osmNode({id: 'a'}), + iD.osmNode({id: 'b'}), + iD.osmNode({id: 'c'}), + iD.osmNode({id: 'c'}), + iD.osmNode({id: '*'}), + iD.osmWay({id: '-', nodes: ['a', '*', 'b']}), + iD.osmWay({id: '|', nodes: ['c', '*', 'd']}) + ]); expect(iD.actionSplit('*').limitWays(['-', '=']).disabled(graph)).to.equal('not_eligible'); }); }); - it('creates a new way with the appropriate nodes', function () { - // Situation: - // a ---- b ---- c - // - // Split at b. - // - // Expected result: - // a ---- b ==== c - // - var graph = iD.Graph([ - iD.Node({id: 'a'}), - iD.Node({id: 'b'}), - iD.Node({id: 'c'}), - iD.Way({id: '-', nodes: ['a', 'b', 'c']}) - ]); - graph = iD.actionSplit('b', ['='])(graph); + describe('ways', function () { - expect(graph.entity('-').nodes).to.eql(['a', 'b']); - expect(graph.entity('=').nodes).to.eql(['b', 'c']); - }); - - it('copies tags to the new way', function () { - var tags = {highway: 'residential'}, - graph = iD.Graph([ - iD.Node({id: 'a'}), - iD.Node({id: 'b'}), - iD.Node({id: 'c'}), - iD.Way({id: '-', nodes: ['a', 'b', 'c'], tags: tags}) - ]); - - graph = iD.actionSplit('b', ['='])(graph); - - // Immutable tags => should be shared by identity. - expect(graph.entity('-').tags).to.equal(tags); - expect(graph.entity('=').tags).to.equal(tags); - }); - - it('splits a way at a T-junction', function () { - // Situation: - // a ---- b ---- c - // | - // d - // - // Split at b. - // - // Expected result: - // a ---- b ==== c - // | - // d - // - var graph = iD.Graph([ - iD.Node({id: 'a'}), - iD.Node({id: 'b'}), - iD.Node({id: 'c'}), - iD.Node({id: 'd'}), - iD.Way({id: '-', nodes: ['a', 'b', 'c']}), - iD.Way({id: '|', nodes: ['d', 'b']}) - ]); - - graph = iD.actionSplit('b', ['='])(graph); - - expect(graph.entity('-').nodes).to.eql(['a', 'b']); - expect(graph.entity('=').nodes).to.eql(['b', 'c']); - expect(graph.entity('|').nodes).to.eql(['d', 'b']); - }); - - it('splits multiple ways at an intersection', function () { - // Situation: - // c - // | - // a ---- * ---- b - // ¦ - // d - // - // Split at b. - // - // Expected result: - // c - // | - // a ---- * ==== b - // ¦ - // d - // - var graph = iD.Graph([ - iD.Node({id: 'a'}), - iD.Node({id: 'b'}), - iD.Node({id: 'c'}), - iD.Node({id: 'c'}), - iD.Node({id: '*'}), - iD.Way({id: '-', nodes: ['a', '*', 'b']}), - iD.Way({id: '|', nodes: ['c', '*', 'd']}) - ]); - - graph = iD.actionSplit('*', ['=', '¦'])(graph); - - expect(graph.entity('-').nodes).to.eql(['a', '*']); - expect(graph.entity('=').nodes).to.eql(['*', 'b']); - expect(graph.entity('|').nodes).to.eql(['c', '*']); - expect(graph.entity('¦').nodes).to.eql(['*', 'd']); - }); - - it('splits the specified ways at an intersection', function () { - var graph = iD.Graph([ - iD.Node({id: 'a'}), - iD.Node({id: 'b'}), - iD.Node({id: 'c'}), - iD.Node({id: 'c'}), - iD.Node({id: '*'}), - iD.Way({id: '-', nodes: ['a', '*', 'b']}), - iD.Way({id: '|', nodes: ['c', '*', 'd']}) - ]); - - var g1 = iD.actionSplit('*', ['=']).limitWays(['-'])(graph); - expect(g1.entity('-').nodes).to.eql(['a', '*']); - expect(g1.entity('=').nodes).to.eql(['*', 'b']); - expect(g1.entity('|').nodes).to.eql(['c', '*', 'd']); - - var g2 = iD.actionSplit('*', ['¦']).limitWays(['|'])(graph); - expect(g2.entity('-').nodes).to.eql(['a', '*', 'b']); - expect(g2.entity('|').nodes).to.eql(['c', '*']); - expect(g2.entity('¦').nodes).to.eql(['*', 'd']); - - var g3 = iD.actionSplit('*', ['=', '¦']).limitWays(['-', '|'])(graph); - expect(g3.entity('-').nodes).to.eql(['a', '*']); - expect(g3.entity('=').nodes).to.eql(['*', 'b']); - expect(g3.entity('|').nodes).to.eql(['c', '*']); - expect(g3.entity('¦').nodes).to.eql(['*', 'd']); - }); - - it('splits self-intersecting ways', function () { - // Situation: - // b - // / | - // / | - // c - a -- d - // - // Split at a. - // - // Expected result: - // b - // / | - // / | - // c - a == d - // - var graph = iD.Graph([ - iD.Node({id: 'a'}), - iD.Node({id: 'b'}), - iD.Node({id: 'c'}), - iD.Node({id: 'c'}), - iD.Way({id: '-', nodes: ['a', 'b', 'c', 'a', 'd']}) - ]); - - graph = iD.actionSplit('a', ['='])(graph); - - expect(graph.entity('-').nodes).to.eql(['a', 'b', 'c', 'a']); - expect(graph.entity('=').nodes).to.eql(['a', 'd']); - }); - - it('splits a closed way at the given point and its antipode', function () { - // Situation: - // a ---- b - // | | - // d ---- c - // - // Split at a. - // - // Expected result: - // a ---- b - // || | - // d ==== c - // - var graph = iD.Graph([ - iD.Node({id: 'a', loc: [0,1]}), - iD.Node({id: 'b', loc: [1,1]}), - iD.Node({id: 'c', loc: [1,0]}), - iD.Node({id: 'd', loc: [0,0]}), - iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd', 'a']}) - ]); - - var g1 = iD.actionSplit('a', ['='])(graph); - expect(g1.entity('-').nodes).to.eql(['a', 'b', 'c']); - expect(g1.entity('=').nodes).to.eql(['c', 'd', 'a']); - - var g2 = iD.actionSplit('b', ['='])(graph); - expect(g2.entity('-').nodes).to.eql(['b', 'c', 'd']); - expect(g2.entity('=').nodes).to.eql(['d', 'a', 'b']); - - var g3 = iD.actionSplit('c', ['='])(graph); - expect(g3.entity('-').nodes).to.eql(['c', 'd', 'a']); - expect(g3.entity('=').nodes).to.eql(['a', 'b', 'c']); - - var g4 = iD.actionSplit('d', ['='])(graph); - expect(g4.entity('-').nodes).to.eql(['d', 'a', 'b']); - expect(g4.entity('=').nodes).to.eql(['b', 'c', 'd']); - }); - - it('splits an area by converting it to a multipolygon', function () { - var graph = iD.Graph([ - iD.Node({id: 'a', loc: [0,1]}), - iD.Node({id: 'b', loc: [1,1]}), - iD.Node({id: 'c', loc: [1,0]}), - iD.Node({id: 'd', loc: [0,0]}), - iD.Way({id: '-', tags: {building: 'yes'}, nodes: ['a', 'b', 'c', 'd', 'a']}) - ]); - - graph = iD.actionSplit('a', ['='])(graph); - expect(graph.entity('-').tags).to.eql({}); - expect(graph.entity('=').tags).to.eql({}); - expect(graph.parentRelations(graph.entity('-'))).to.have.length(1); - - var relation = graph.parentRelations(graph.entity('-'))[0]; - expect(relation.tags).to.eql({type: 'multipolygon', building: 'yes'}); - expect(relation.members).to.eql([ - {id: '-', role: 'outer', type: 'way'}, - {id: '=', role: 'outer', type: 'way'} - ]); - }); - - it('splits only the line of a node shared by a line and an area', function () { - var graph = iD.Graph([ - iD.Node({id: 'a', loc: [0,1]}), - iD.Node({id: 'b', loc: [1,1]}), - iD.Node({id: 'c', loc: [1,0]}), - iD.Way({id: '-', nodes: ['a', 'b', 'c']}), - iD.Way({id: '=', nodes: ['a', 'b', 'c', 'a'], tags: {area: 'yes'}}) - ]); - - graph = iD.actionSplit('b', ['~'])(graph); - - expect(graph.entity('-').nodes).to.eql(['a', 'b']); - expect(graph.entity('~').nodes).to.eql(['b', 'c']); - expect(graph.entity('=').nodes).to.eql(['a', 'b', 'c', 'a']); - expect(graph.parentRelations(graph.entity('='))).to.have.length(0); - }); - - it('adds the new way to parent relations (no connections)', function () { - // Situation: - // a ---- b ---- c - // Relation: [----] - // - // Split at b. - // - // Expected result: - // a ---- b ==== c - // Relation: [----, ====] - // - var graph = iD.Graph([ - iD.Node({id: 'a'}), - iD.Node({id: 'b'}), - iD.Node({id: 'c'}), - iD.Way({id: '-', nodes: ['a', 'b', 'c']}), - iD.Relation({id: 'r', members: [{id: '-', type: 'way', role: 'forward'}]}) - ]); - - graph = iD.actionSplit('b', ['='])(graph); - - expect(graph.entity('r').members).to.eql([ - {id: '-', type: 'way', role: 'forward'}, - {id: '=', type: 'way', role: 'forward'} - ]); - }); - - it('adds the new way to parent relations (forward order)', function () { - // Situation: - // a ---- b ---- c ~~~~ d - // Relation: [----, ~~~~] - // - // Split at b. - // - // Expected result: - // a ---- b ==== c ~~~~ d - // Relation: [----, ====, ~~~~] - // - var graph = iD.Graph([ - iD.Node({id: 'a'}), - iD.Node({id: 'b'}), - iD.Node({id: 'c'}), - iD.Node({id: 'd'}), - iD.Way({id: '-', nodes: ['a', 'b', 'c']}), - iD.Way({id: '~', nodes: ['c', 'd']}), - iD.Relation({id: 'r', members: [{id: '-', type: 'way'}, {id: '~', type: 'way'}]}) - ]); - - graph = iD.actionSplit('b', ['='])(graph); - - var ids = graph.entity('r').members.map(function(m) { return m.id; }); - expect(ids).to.have.ordered.members(['-', '=', '~']); - }); - - it('adds the new way to parent relations (reverse order)', function () { - // Situation: - // a ---- b ---- c ~~~~ d - // Relation: [~~~~, ----] - // - // Split at b. - // - // Expected result: - // a ---- b ==== c ~~~~ d - // Relation: [~~~~, ====, ----] - // - var graph = iD.Graph([ - iD.Node({id: 'a'}), - iD.Node({id: 'b'}), - iD.Node({id: 'c'}), - iD.Node({id: 'd'}), - iD.Way({id: '-', nodes: ['a', 'b', 'c']}), - iD.Way({id: '~', nodes: ['c', 'd']}), - iD.Relation({id: 'r', members: [{id: '~', type: 'way'}, {id: '-', type: 'way'}]}) - ]); - - graph = iD.actionSplit('b', ['='])(graph); - - var ids = graph.entity('r').members.map(function(m) { return m.id; }); - expect(ids).to.have.ordered.members(['~', '=', '-']); - }); - - it('handles incomplete relations', function () { - var graph = iD.Graph([ - iD.Node({id: 'a'}), - iD.Node({id: 'b'}), - iD.Node({id: 'c'}), - iD.Way({id: '-', nodes: ['a', 'b', 'c']}), - iD.Relation({id: 'r', members: [{id: '~', type: 'way'}, {id: '-', type: 'way'}]}) - ]); - - graph = iD.actionSplit('b', ['='])(graph); - - var ids = graph.entity('r').members.map(function(m) { return m.id; }); - expect(ids).to.have.ordered.members(['~', '-', '=']); - }); - - it('converts simple multipolygon to a proper multipolygon', function () { - var graph = iD.Graph([ - iD.Node({id: 'a'}), - iD.Node({id: 'b'}), - iD.Node({id: 'c'}), - iD.Way({'id': '-', nodes: ['a', 'b', 'c'], tags: {natural: 'water'}}), - iD.Relation({id: 'r', members: [{id: '-', type: 'way', role: 'outer'}], tags: {type: 'multipolygon'}}) - ]); - - graph = iD.actionSplit('b', ['='])(graph); - - expect(graph.entity('-').tags).to.eql({}); - expect(graph.entity('r').tags).to.eql({type: 'multipolygon', natural: 'water'}); - var ids = graph.entity('r').members.map(function(m) { return m.id; }); - expect(ids).to.have.ordered.members(['-', '=']); - }); - - ['restriction', 'restriction:bus'].forEach(function (type) { - it('updates a restriction\'s \'from\' role', function () { + it('creates a new way with the appropriate nodes', function () { // Situation: - // a ----> b ----> c ~~~~ d - // A restriction from ---- to ~~~~ via c. + // a ---- b ---- c // // Split at b. // // Expected result: - // a ----> b ====> c ~~~~ d - // A restriction from ==== to ~~~~ via c. + // a ---- b ==== c // - var graph = iD.Graph([ - iD.Node({id: 'a'}), - iD.Node({id: 'b'}), - iD.Node({id: 'c'}), - iD.Node({id: 'd'}), - iD.Way({id: '-', nodes: ['a', 'b', 'c']}), - iD.Way({id: '~', nodes: ['c', 'd']}), - iD.Relation({id: 'r', tags: {type: type}, members: [ - {id: '-', role: 'from', type: 'way'}, - {id: '~', role: 'to', type: 'way'}, - {id: 'c', role: 'via', type: 'node'} - ]}) - ]); + var graph = iD.coreGraph([ + iD.osmNode({id: 'a'}), + iD.osmNode({id: 'b'}), + iD.osmNode({id: 'c'}), + iD.osmWay({id: '-', nodes: ['a', 'b', 'c']}) + ]); graph = iD.actionSplit('b', ['='])(graph); - expect(graph.entity('r').members).to.eql([ - {id: '=', role: 'from', type: 'way'}, - {id: '~', role: 'to', type: 'way'}, - {id: 'c', role: 'via', type: 'node'} - ]); + expect(graph.entity('-').nodes).to.eql(['a', 'b']); + expect(graph.entity('=').nodes).to.eql(['b', 'c']); }); - it('updates a restriction\'s \'to\' role', function () { + it('copies tags to the new way', function () { + var tags = {highway: 'residential'}; + var graph = iD.coreGraph([ + iD.osmNode({id: 'a'}), + iD.osmNode({id: 'b'}), + iD.osmNode({id: 'c'}), + iD.osmWay({id: '-', nodes: ['a', 'b', 'c'], tags: tags}) + ]); + + graph = iD.actionSplit('b', ['='])(graph); + + // Immutable tags => should be shared by identity. + expect(graph.entity('-').tags).to.equal(tags); + expect(graph.entity('=').tags).to.equal(tags); + }); + + it('splits a way at a T-junction', function () { // Situation: - // a ----> b ----> c ~~~~ d - // A restriction from ~~~~ to ---- via c. + // a ---- b ---- c + // | + // d // // Split at b. // // Expected result: - // a ----> b ====> c ~~~~ d - // A restriction from ~~~~ to ==== via c. + // a ---- b ==== c + // | + // d // - var graph = iD.Graph([ - iD.Node({id: 'a'}), - iD.Node({id: 'b'}), - iD.Node({id: 'c'}), - iD.Node({id: 'd'}), - iD.Way({id: '-', nodes: ['a', 'b', 'c']}), - iD.Way({id: '~', nodes: ['c', 'd']}), - iD.Relation({id: 'r', tags: {type: type}, members: [ + var graph = iD.coreGraph([ + iD.osmNode({id: 'a'}), + iD.osmNode({id: 'b'}), + iD.osmNode({id: 'c'}), + iD.osmNode({id: 'd'}), + iD.osmWay({id: '-', nodes: ['a', 'b', 'c']}), + iD.osmWay({id: '|', nodes: ['d', 'b']}) + ]); + + graph = iD.actionSplit('b', ['='])(graph); + + expect(graph.entity('-').nodes).to.eql(['a', 'b']); + expect(graph.entity('=').nodes).to.eql(['b', 'c']); + expect(graph.entity('|').nodes).to.eql(['d', 'b']); + }); + + it('splits multiple ways at an intersection', function () { + // Situation: + // c + // | + // a ---- * ---- b + // ¦ + // d + // + // Split at b. + // + // Expected result: + // c + // | + // a ---- * ==== b + // ¦ + // d + // + var graph = iD.coreGraph([ + iD.osmNode({id: 'a'}), + iD.osmNode({id: 'b'}), + iD.osmNode({id: 'c'}), + iD.osmNode({id: 'c'}), + iD.osmNode({id: '*'}), + iD.osmWay({id: '-', nodes: ['a', '*', 'b']}), + iD.osmWay({id: '|', nodes: ['c', '*', 'd']}) + ]); + + graph = iD.actionSplit('*', ['=', '¦'])(graph); + + expect(graph.entity('-').nodes).to.eql(['a', '*']); + expect(graph.entity('=').nodes).to.eql(['*', 'b']); + expect(graph.entity('|').nodes).to.eql(['c', '*']); + expect(graph.entity('¦').nodes).to.eql(['*', 'd']); + }); + + it('splits the specified ways at an intersection', function () { + var graph = iD.coreGraph([ + iD.osmNode({id: 'a'}), + iD.osmNode({id: 'b'}), + iD.osmNode({id: 'c'}), + iD.osmNode({id: 'c'}), + iD.osmNode({id: '*'}), + iD.osmWay({id: '-', nodes: ['a', '*', 'b']}), + iD.osmWay({id: '|', nodes: ['c', '*', 'd']}) + ]); + + var g1 = iD.actionSplit('*', ['=']).limitWays(['-'])(graph); + expect(g1.entity('-').nodes).to.eql(['a', '*']); + expect(g1.entity('=').nodes).to.eql(['*', 'b']); + expect(g1.entity('|').nodes).to.eql(['c', '*', 'd']); + + var g2 = iD.actionSplit('*', ['¦']).limitWays(['|'])(graph); + expect(g2.entity('-').nodes).to.eql(['a', '*', 'b']); + expect(g2.entity('|').nodes).to.eql(['c', '*']); + expect(g2.entity('¦').nodes).to.eql(['*', 'd']); + + var g3 = iD.actionSplit('*', ['=', '¦']).limitWays(['-', '|'])(graph); + expect(g3.entity('-').nodes).to.eql(['a', '*']); + expect(g3.entity('=').nodes).to.eql(['*', 'b']); + expect(g3.entity('|').nodes).to.eql(['c', '*']); + expect(g3.entity('¦').nodes).to.eql(['*', 'd']); + }); + + it('splits self-intersecting ways', function () { + // Situation: + // b + // / | + // / | + // c - a -- d + // + // Split at a. + // + // Expected result: + // b + // / | + // / | + // c - a == d + // + var graph = iD.coreGraph([ + iD.osmNode({id: 'a'}), + iD.osmNode({id: 'b'}), + iD.osmNode({id: 'c'}), + iD.osmNode({id: 'c'}), + iD.osmWay({id: '-', nodes: ['a', 'b', 'c', 'a', 'd']}) + ]); + + graph = iD.actionSplit('a', ['='])(graph); + + expect(graph.entity('-').nodes).to.eql(['a', 'b', 'c', 'a']); + expect(graph.entity('=').nodes).to.eql(['a', 'd']); + }); + + it('splits a closed way at the given point and its antipode', function () { + // Situation: + // a ---- b + // | | + // d ---- c + // + // Split at a. + // + // Expected result: + // a ---- b + // || | + // d ==== c + // + var graph = iD.coreGraph([ + iD.osmNode({id: 'a', loc: [0,1]}), + iD.osmNode({id: 'b', loc: [1,1]}), + iD.osmNode({id: 'c', loc: [1,0]}), + iD.osmNode({id: 'd', loc: [0,0]}), + iD.osmWay({id: '-', nodes: ['a', 'b', 'c', 'd', 'a']}) + ]); + + var g1 = iD.actionSplit('a', ['='])(graph); + expect(g1.entity('-').nodes).to.eql(['a', 'b', 'c']); + expect(g1.entity('=').nodes).to.eql(['c', 'd', 'a']); + + var g2 = iD.actionSplit('b', ['='])(graph); + expect(g2.entity('-').nodes).to.eql(['b', 'c', 'd']); + expect(g2.entity('=').nodes).to.eql(['d', 'a', 'b']); + + var g3 = iD.actionSplit('c', ['='])(graph); + expect(g3.entity('-').nodes).to.eql(['c', 'd', 'a']); + expect(g3.entity('=').nodes).to.eql(['a', 'b', 'c']); + + var g4 = iD.actionSplit('d', ['='])(graph); + expect(g4.entity('-').nodes).to.eql(['d', 'a', 'b']); + expect(g4.entity('=').nodes).to.eql(['b', 'c', 'd']); + }); + }); + + + describe('relations', function () { + + it('handles incomplete relations', function () { + var graph = iD.coreGraph([ + iD.osmNode({id: 'a'}), + iD.osmNode({id: 'b'}), + iD.osmNode({id: 'c'}), + iD.osmWay({id: '-', nodes: ['a', 'b', 'c']}), + iD.osmRelation({id: 'r', members: [{id: '~', type: 'way'}, {id: '-', type: 'way'}]}) + ]); + + graph = iD.actionSplit('b', ['='])(graph); + + var ids = graph.entity('r').members.map(function(m) { return m.id; }); + expect(ids).to.have.ordered.members(['~', '-', '=']); + }); + + + describe('member ordering', function () { + + it('adds the new way to parent relations (no connections)', function () { + // Situation: + // a ---- b ---- c + // Relation: [----] + // + // Split at b. + // + // Expected result: + // a ---- b ==== c + // Relation: [----, ====] + // + var graph = iD.coreGraph([ + iD.osmNode({id: 'a'}), + iD.osmNode({id: 'b'}), + iD.osmNode({id: 'c'}), + iD.osmWay({id: '-', nodes: ['a', 'b', 'c']}), + iD.osmRelation({id: 'r', members: [{id: '-', type: 'way', role: 'forward'}]}) + ]); + + graph = iD.actionSplit('b', ['='])(graph); + + expect(graph.entity('r').members).to.eql([ + {id: '-', type: 'way', role: 'forward'}, + {id: '=', type: 'way', role: 'forward'} + ]); + }); + + it('adds the new way to parent relations (forward order)', function () { + // Situation: + // a ---- b ---- c ~~~~ d + // Relation: [----, ~~~~] + // + // Split at b. + // + // Expected result: + // a ---- b ==== c ~~~~ d + // Relation: [----, ====, ~~~~] + // + var graph = iD.coreGraph([ + iD.osmNode({id: 'a'}), + iD.osmNode({id: 'b'}), + iD.osmNode({id: 'c'}), + iD.osmNode({id: 'd'}), + iD.osmWay({id: '-', nodes: ['a', 'b', 'c']}), + iD.osmWay({id: '~', nodes: ['c', 'd']}), + iD.osmRelation({id: 'r', members: [{id: '-', type: 'way'}, {id: '~', type: 'way'}]}) + ]); + + graph = iD.actionSplit('b', ['='])(graph); + + var ids = graph.entity('r').members.map(function(m) { return m.id; }); + expect(ids).to.have.ordered.members(['-', '=', '~']); + }); + + it('adds the new way to parent relations (reverse order)', function () { + // Situation: + // a ---- b ---- c ~~~~ d + // Relation: [~~~~, ----] + // + // Split at b. + // + // Expected result: + // a ---- b ==== c ~~~~ d + // Relation: [~~~~, ====, ----] + // + var graph = iD.coreGraph([ + iD.osmNode({id: 'a'}), + iD.osmNode({id: 'b'}), + iD.osmNode({id: 'c'}), + iD.osmNode({id: 'd'}), + iD.osmWay({id: '-', nodes: ['a', 'b', 'c']}), + iD.osmWay({id: '~', nodes: ['c', 'd']}), + iD.osmRelation({id: 'r', members: [{id: '~', type: 'way'}, {id: '-', type: 'way'}]}) + ]); + + graph = iD.actionSplit('b', ['='])(graph); + + var ids = graph.entity('r').members.map(function(m) { return m.id; }); + expect(ids).to.have.ordered.members(['~', '=', '-']); + }); + }); + + + describe('type = multipolygon', function () { + + it('splits an area by converting it to a multipolygon', function () { + // Situation: + // a ---- b + // | | + // d ---- c + // + // Split at a. + // + // Expected result: + // a ---- b + // || | + // d ==== c + // + var graph = iD.coreGraph([ + iD.osmNode({id: 'a', loc: [0,1]}), + iD.osmNode({id: 'b', loc: [1,1]}), + iD.osmNode({id: 'c', loc: [1,0]}), + iD.osmNode({id: 'd', loc: [0,0]}), + iD.osmWay({id: '-', tags: {building: 'yes'}, nodes: ['a', 'b', 'c', 'd', 'a']}) + ]); + + graph = iD.actionSplit('a', ['='])(graph); + expect(graph.entity('-').tags).to.eql({}); + expect(graph.entity('=').tags).to.eql({}); + expect(graph.parentRelations(graph.entity('-'))).to.have.length(1); + + var relation = graph.parentRelations(graph.entity('-'))[0]; + expect(relation.tags).to.eql({type: 'multipolygon', building: 'yes'}); + expect(relation.members).to.eql([ + {id: '-', role: 'outer', type: 'way'}, + {id: '=', role: 'outer', type: 'way'} + ]); + }); + + it('splits only the line of a node shared by a line and an area', function () { + var graph = iD.coreGraph([ + iD.osmNode({id: 'a', loc: [0,1]}), + iD.osmNode({id: 'b', loc: [1,1]}), + iD.osmNode({id: 'c', loc: [1,0]}), + iD.osmWay({id: '-', nodes: ['a', 'b', 'c']}), + iD.osmWay({id: '=', nodes: ['a', 'b', 'c', 'a'], tags: {area: 'yes'}}) + ]); + + graph = iD.actionSplit('b', ['~'])(graph); + + expect(graph.entity('-').nodes).to.eql(['a', 'b']); + expect(graph.entity('~').nodes).to.eql(['b', 'c']); + expect(graph.entity('=').nodes).to.eql(['a', 'b', 'c', 'a']); + expect(graph.parentRelations(graph.entity('='))).to.have.length(0); + }); + + it('converts simple multipolygon to a proper multipolygon', function () { + var graph = iD.coreGraph([ + iD.osmNode({id: 'a'}), + iD.osmNode({id: 'b'}), + iD.osmNode({id: 'c'}), + iD.osmWay({'id': '-', nodes: ['a', 'b', 'c'], tags: {natural: 'water'}}), + iD.osmRelation({id: 'r', members: [{id: '-', type: 'way', role: 'outer'}], tags: {type: 'multipolygon'}}) + ]); + + graph = iD.actionSplit('b', ['='])(graph); + + expect(graph.entity('-').tags).to.eql({}); + expect(graph.entity('r').tags).to.eql({type: 'multipolygon', natural: 'water'}); + var ids = graph.entity('r').members.map(function(m) { return m.id; }); + expect(ids).to.have.ordered.members(['-', '=']); + }); + }); + + + ['restriction', 'restriction:bus'].forEach(function (type) { + describe('type = ' + type, function () { + + it('updates a restriction\'s \'from\' role', function () { + // Situation: + // a ----> b ----> c ~~~~ d + // A restriction from ---- to ~~~~ via c. + // + // Split at b. + // + // Expected result: + // a ----> b ====> c ~~~~ d + // A restriction from ==== to ~~~~ via c. + // + var graph = iD.coreGraph([ + iD.osmNode({id: 'a'}), + iD.osmNode({id: 'b'}), + iD.osmNode({id: 'c'}), + iD.osmNode({id: 'd'}), + iD.osmWay({id: '-', nodes: ['a', 'b', 'c']}), + iD.osmWay({id: '~', nodes: ['c', 'd']}), + iD.osmRelation({id: 'r', tags: {type: type}, members: [ + {id: '-', role: 'from', type: 'way'}, + {id: '~', role: 'to', type: 'way'}, + {id: 'c', role: 'via', type: 'node'} + ]}) + ]); + + graph = iD.actionSplit('b', ['='])(graph); + + expect(graph.entity('r').members).to.eql([ + {id: '=', role: 'from', type: 'way'}, + {id: '~', role: 'to', type: 'way'}, + {id: 'c', role: 'via', type: 'node'} + ]); + }); + + it('updates a restriction\'s \'to\' role', function () { + // Situation: + // a ----> b ----> c ~~~~ d + // A restriction from ~~~~ to ---- via c. + // + // Split at b. + // + // Expected result: + // a ----> b ====> c ~~~~ d + // A restriction from ~~~~ to ==== via c. + // + var graph = iD.coreGraph([ + iD.osmNode({id: 'a'}), + iD.osmNode({id: 'b'}), + iD.osmNode({id: 'c'}), + iD.osmNode({id: 'd'}), + iD.osmWay({id: '-', nodes: ['a', 'b', 'c']}), + iD.osmWay({id: '~', nodes: ['c', 'd']}), + iD.osmRelation({id: 'r', tags: {type: type}, members: [ + {id: '~', role: 'from', type: 'way'}, + {id: '-', role: 'to', type: 'way'}, + {id: 'c', role: 'via', type: 'node'} + ]}) + ]); + + graph = iD.actionSplit('b', ['='])(graph); + + expect(graph.entity('r').members).to.eql([ {id: '~', role: 'from', type: 'way'}, - {id: '-', role: 'to', type: 'way'}, + {id: '=', role: 'to', type: 'way'}, {id: 'c', role: 'via', type: 'node'} - ]}) - ]); - - graph = iD.actionSplit('b', ['='])(graph); - - expect(graph.entity('r').members).to.eql([ - {id: '~', role: 'from', type: 'way'}, - {id: '=', role: 'to', type: 'way'}, - {id: 'c', role: 'via', type: 'node'} - ]); - }); + ]); + }); - it('updates both \'to\' and \'from\' roles for u-turn restrictions', function () { - // Situation: - // a ----> b ----> c ~~~~ d - // A restriction from ---- to ---- via c. - // - // Split at b. - // - // Expected result: - // a ----> b ====> c ~~~~ d - // A restriction from ==== to ==== via c. - // - var graph = iD.Graph([ - iD.Node({id: 'a'}), - iD.Node({id: 'b'}), - iD.Node({id: 'c'}), - iD.Node({id: 'd'}), - iD.Way({id: '-', nodes: ['a', 'b', 'c']}), - iD.Way({id: '~', nodes: ['c', 'd']}), - iD.Relation({id: 'r', tags: {type: type}, members: [ - {id: '-', role: 'from', type: 'way'}, - {id: '-', role: 'to', type: 'way'}, + it('updates both \'to\' and \'from\' roles for u-turn restrictions', function () { + // Situation: + // a ----> b ----> c ~~~~ d + // A restriction from ---- to ---- via c. + // + // Split at b. + // + // Expected result: + // a ----> b ====> c ~~~~ d + // A restriction from ==== to ==== via c. + // + var graph = iD.coreGraph([ + iD.osmNode({id: 'a'}), + iD.osmNode({id: 'b'}), + iD.osmNode({id: 'c'}), + iD.osmNode({id: 'd'}), + iD.osmWay({id: '-', nodes: ['a', 'b', 'c']}), + iD.osmWay({id: '~', nodes: ['c', 'd']}), + iD.osmRelation({id: 'r', tags: {type: type}, members: [ + {id: '-', role: 'from', type: 'way'}, + {id: '-', role: 'to', type: 'way'}, + {id: 'c', role: 'via', type: 'node'} + ]}) + ]); + + graph = iD.actionSplit('b', ['='])(graph); + + expect(graph.entity('r').members).to.eql([ + {id: '=', role: 'from', type: 'way'}, + {id: '=', role: 'to', type: 'way'}, {id: 'c', role: 'via', type: 'node'} - ]}) - ]); + ]); + }); - graph = iD.actionSplit('b', ['='])(graph); + it('leaves unaffected restrictions unchanged', function () { + // Situation: + // a <---- b <---- c ~~~~ d + // A restriction from ---- to ~~~~ via c. + // + // Split at b. + // + // Expected result: + // a <==== b <---- c ~~~~ d + // A restriction from ---- to ~~~~ via c. + // + var graph = iD.coreGraph([ + iD.osmNode({id: 'a'}), + iD.osmNode({id: 'b'}), + iD.osmNode({id: 'c'}), + iD.osmNode({id: 'd'}), + iD.osmWay({id: '-', nodes: ['c', 'b', 'a']}), + iD.osmWay({id: '~', nodes: ['c', 'd']}), + iD.osmRelation({id: 'r', tags: {type: type}, members: [ + {id: '-', role: 'from', type: 'way'}, + {id: '~', role: 'to', type: 'way'}, + {id: 'c', role: 'via', type: 'node'} + ]}) + ]); - expect(graph.entity('r').members).to.eql([ - {id: '=', role: 'from', type: 'way'}, - {id: '=', role: 'to', type: 'way'}, - {id: 'c', role: 'via', type: 'node'} - ]); - }); + graph = iD.actionSplit('b', ['='])(graph); - it('leaves unaffected restrictions unchanged', function () { - // Situation: - // a <---- b <---- c ~~~~ d - // A restriction from ---- to ~~~~ via c. - // - // Split at b. - // - // Expected result: - // a <==== b <---- c ~~~~ d - // A restriction from ---- to ~~~~ via c. - // - var graph = iD.Graph([ - iD.Node({id: 'a'}), - iD.Node({id: 'b'}), - iD.Node({id: 'c'}), - iD.Node({id: 'd'}), - iD.Way({id: '-', nodes: ['c', 'b', 'a']}), - iD.Way({id: '~', nodes: ['c', 'd']}), - iD.Relation({id: 'r', tags: {type: type}, members: [ + expect(graph.entity('r').members).to.eql([ {id: '-', role: 'from', type: 'way'}, {id: '~', role: 'to', type: 'way'}, {id: 'c', role: 'via', type: 'node'} - ]}) - ]); + ]); + }); + }); - graph = iD.actionSplit('b', ['='])(graph); - - expect(graph.entity('r').members).to.eql([ - {id: '-', role: 'from', type: 'way'}, - {id: '~', role: 'to', type: 'way'}, - {id: 'c', role: 'via', type: 'node'} - ]); }); }); }); diff --git a/test/spec/osm/multipolygon.js b/test/spec/osm/multipolygon.js index 6d0c9fb0b..aea1d8a68 100644 --- a/test/spec/osm/multipolygon.js +++ b/test/spec/osm/multipolygon.js @@ -1,91 +1,101 @@ describe('iD.osmIsSimpleMultipolygonOuterMember', function() { it('returns the parent relation of a simple multipolygon outer', function() { - var outer = iD.Way({tags: {'natural':'wood'}}), - relation = iD.Relation({tags: {type: 'multipolygon'}, - members: [{id: outer.id, role: 'outer'}]}), - graph = iD.Graph([outer, relation]); + var outer = iD.osmWay({tags: {'natural':'wood'}}); + var relation = iD.osmRelation( + {tags: {type: 'multipolygon'}, members: [{id: outer.id, role: 'outer'}]} + ); + var graph = iD.coreGraph([outer, relation]); expect(iD.osmIsSimpleMultipolygonOuterMember(outer, graph)).to.equal(relation); }); it('returns the parent relation of a simple multipolygon outer, assuming role outer if unspecified', function() { - var outer = iD.Way({tags: {'natural':'wood'}}), - relation = iD.Relation({tags: {type: 'multipolygon'}, - members: [{id: outer.id}]}), - graph = iD.Graph([outer, relation]); + var outer = iD.osmWay({tags: {'natural':'wood'}}); + var relation = iD.osmRelation( + {tags: {type: 'multipolygon'}, members: [{id: outer.id}]} + ); + var graph = iD.coreGraph([outer, relation]); expect(iD.osmIsSimpleMultipolygonOuterMember(outer, graph)).to.equal(relation); }); it('returns false if entity is not a way', function() { - var outer = iD.Node({tags: {'natural':'wood'}}), - relation = iD.Relation({tags: {type: 'multipolygon'}, - members: [{id: outer.id, role: 'outer'}]}), - graph = iD.Graph([outer, relation]); + var outer = iD.osmNode({tags: {'natural':'wood'}}); + var relation = iD.osmRelation( + {tags: {type: 'multipolygon'}, members: [{id: outer.id, role: 'outer'}]} + ); + var graph = iD.coreGraph([outer, relation]); expect(iD.osmIsSimpleMultipolygonOuterMember(outer, graph)).to.be.false; }); it('returns false if entity does not have interesting tags', function() { - var outer = iD.Way({tags: {'tiger:reviewed':'no'}}), - relation = iD.Relation({tags: {type: 'multipolygon'}, - members: [{id: outer.id, role: 'outer'}]}), - graph = iD.Graph([outer, relation]); + var outer = iD.osmWay({tags: {'tiger:reviewed':'no'}}); + var relation = iD.osmRelation( + {tags: {type: 'multipolygon'}, members: [{id: outer.id, role: 'outer'}]} + ); + var graph = iD.coreGraph([outer, relation]); expect(iD.osmIsSimpleMultipolygonOuterMember(outer, graph)).to.be.false; }); it('returns false if entity does not have a parent relation', function() { - var outer = iD.Way({tags: {'natural':'wood'}}), - graph = iD.Graph([outer]); + var outer = iD.osmWay({tags: {'natural':'wood'}}); + var graph = iD.coreGraph([outer]); expect(iD.osmIsSimpleMultipolygonOuterMember(outer, graph)).to.be.false; }); it('returns false if the parent is not a multipolygon', function() { - var outer = iD.Way({tags: {'natural':'wood'}}), - relation = iD.Relation({tags: {type: 'route'}, - members: [{id: outer.id, role: 'outer'}]}), - graph = iD.Graph([outer, relation]); + var outer = iD.osmWay({tags: {'natural':'wood'}}); + var relation = iD.osmRelation( + {tags: {type: 'route'}, members: [{id: outer.id, role: 'outer'}]} + ); + var graph = iD.coreGraph([outer, relation]); expect(iD.osmIsSimpleMultipolygonOuterMember(outer, graph)).to.be.false; }); it('returns false if the parent has interesting tags', function() { - var outer = iD.Way({tags: {'natural':'wood'}}), - relation = iD.Relation({tags: {natural: 'wood', type: 'multipolygon'}, - members: [{id: outer.id, role: 'outer'}]}), - graph = iD.Graph([outer, relation]); + var outer = iD.osmWay({tags: {'natural':'wood'}}); + var relation = iD.osmRelation( + {tags: {natural: 'wood', type: 'multipolygon'}, members: [{id: outer.id, role: 'outer'}]} + ); + var graph = iD.coreGraph([outer, relation]); expect(iD.osmIsSimpleMultipolygonOuterMember(outer, graph)).to.be.false; }); it('returns the parent relation of a simple multipolygon outer, ignoring uninteresting parent tags', function() { - var outer = iD.Way({tags: {'natural':'wood'}}), - relation = iD.Relation({tags: {'tiger:reviewed':'no', type: 'multipolygon'}, - members: [{id: outer.id, role: 'outer'}]}), - graph = iD.Graph([outer, relation]); + var outer = iD.osmWay({tags: {'natural':'wood'}}); + var relation = iD.osmRelation( + {tags: {'tiger:reviewed':'no', type: 'multipolygon'}, members: [{id: outer.id, role: 'outer'}]} + ); + var graph = iD.coreGraph([outer, relation]); expect(iD.osmIsSimpleMultipolygonOuterMember(outer, graph)).to.equal(relation); }); it('returns false if the parent has multiple outer ways', function() { - var outer1 = iD.Way({tags: {'natural':'wood'}}), - outer2 = iD.Way({tags: {'natural':'wood'}}), - relation = iD.Relation({tags: {type: 'multipolygon'}, - members: [{id: outer1.id, role: 'outer'}, {id: outer2.id, role: 'outer'}]}), - graph = iD.Graph([outer1, outer2, relation]); + var outer1 = iD.osmWay({tags: {'natural':'wood'}}); + var outer2 = iD.osmWay({tags: {'natural':'wood'}}); + var relation = iD.osmRelation( + {tags: {type: 'multipolygon'}, members: [{id: outer1.id, role: 'outer'}, {id: outer2.id, role: 'outer'}]} + ); + var graph = iD.coreGraph([outer1, outer2, relation]); expect(iD.osmIsSimpleMultipolygonOuterMember(outer1, graph)).to.be.false; expect(iD.osmIsSimpleMultipolygonOuterMember(outer2, graph)).to.be.false; }); it('returns false if the parent has multiple outer ways, assuming role outer if unspecified', function() { - var outer1 = iD.Way({tags: {'natural':'wood'}}), - outer2 = iD.Way({tags: {'natural':'wood'}}), - relation = iD.Relation({tags: {type: 'multipolygon'}, - members: [{id: outer1.id}, {id: outer2.id}]}), - graph = iD.Graph([outer1, outer2, relation]); + var outer1 = iD.osmWay({tags: {'natural':'wood'}}); + var outer2 = iD.osmWay({tags: {'natural':'wood'}}); + var relation = iD.osmRelation( + {tags: {type: 'multipolygon'}, members: [{id: outer1.id}, {id: outer2.id}]} + ); + var graph = iD.coreGraph([outer1, outer2, relation]); expect(iD.osmIsSimpleMultipolygonOuterMember(outer1, graph)).to.be.false; expect(iD.osmIsSimpleMultipolygonOuterMember(outer2, graph)).to.be.false; }); it('returns false if the entity is not an outer', function() { - var inner = iD.Way({tags: {'natural':'wood'}}), - relation = iD.Relation({tags: {type: 'multipolygon'}, - members: [{id: inner.id, role: 'inner'}]}), - graph = iD.Graph([inner, relation]); + var inner = iD.osmWay({tags: {'natural':'wood'}}); + var relation = iD.osmRelation( + {tags: {type: 'multipolygon'}, members: [{id: inner.id, role: 'inner'}]} + ); + var graph = iD.coreGraph([inner, relation]); expect(iD.osmIsSimpleMultipolygonOuterMember(inner, graph)).to.be.false; }); }); @@ -93,28 +103,28 @@ describe('iD.osmIsSimpleMultipolygonOuterMember', function() { describe('iD.osmSimpleMultipolygonOuterMember', function() { it('returns the outer member of a simple multipolygon', function() { - var inner = iD.Way(), - outer = iD.Way({tags: {'natural':'wood'}}), - relation = iD.Relation({tags: {type: 'multipolygon'}, members: [ - {id: outer.id, role: 'outer'}, - {id: inner.id, role: 'inner'}] - }), - graph = iD.Graph([inner, outer, relation]); + var inner = iD.osmWay(); + var outer = iD.osmWay({tags: {'natural':'wood'}}); + var relation = iD.osmRelation({tags: {type: 'multipolygon'}, members: [ + {id: outer.id, role: 'outer'}, + {id: inner.id, role: 'inner'}] + }); + var graph = iD.coreGraph([inner, outer, relation]); expect(iD.osmSimpleMultipolygonOuterMember(inner, graph)).to.equal(outer); expect(iD.osmSimpleMultipolygonOuterMember(outer, graph)).to.equal(outer); }); it('returns falsy for a complex multipolygon', function() { - var inner = iD.Way(), - outer1 = iD.Way({tags: {'natural':'wood'}}), - outer2 = iD.Way({tags: {'natural':'wood'}}), - relation = iD.Relation({tags: {type: 'multipolygon'}, members: [ - {id: outer1.id, role: 'outer'}, - {id: outer2.id, role: 'outer'}, - {id: inner.id, role: 'inner'}] - }), - graph = iD.Graph([inner, outer1, outer2, relation]); + var inner = iD.osmWay(); + var outer1 = iD.osmWay({tags: {'natural':'wood'}}); + var outer2 = iD.osmWay({tags: {'natural':'wood'}}); + var relation = iD.osmRelation({tags: {type: 'multipolygon'}, members: [ + {id: outer1.id, role: 'outer'}, + {id: outer2.id, role: 'outer'}, + {id: inner.id, role: 'inner'}] + }); + var graph = iD.coreGraph([inner, outer1, outer2, relation]); expect(iD.osmSimpleMultipolygonOuterMember(inner, graph)).not.to.be.ok; expect(iD.osmSimpleMultipolygonOuterMember(outer1, graph)).not.to.be.ok; @@ -122,12 +132,12 @@ describe('iD.osmSimpleMultipolygonOuterMember', function() { }); it('handles incomplete relations', function() { - var way = iD.Way({id: 'w'}), - relation = iD.Relation({id: 'r', tags: {type: 'multipolygon'}, members: [ - {id: 'o', role: 'outer'}, - {id: 'w', role: 'inner'}] - }), - graph = iD.Graph([way, relation]); + var way = iD.osmWay({id: 'w'}); + var relation = iD.osmRelation({id: 'r', tags: {type: 'multipolygon'}, members: [ + {id: 'o', role: 'outer'}, + {id: 'w', role: 'inner'}] + }); + var graph = iD.coreGraph([way, relation]); expect(iD.osmSimpleMultipolygonOuterMember(way, graph)).not.to.be.ok; }); @@ -136,11 +146,11 @@ describe('iD.osmSimpleMultipolygonOuterMember', 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.osmJoinWays([member], graph); + var node = iD.osmNode({loc: [0, 0]}); + var way = iD.osmWay({nodes: [node.id]}); + var member = {id: way.id, type: 'way'}; + var graph = iD.coreGraph([node, way]); + var result = iD.osmJoinWays([member], graph); expect(result.length).to.equal(1); expect(result[0].nodes.length).to.equal(1); @@ -150,16 +160,16 @@ describe('iD.osmJoinWays', function() { }); it('returns the members in the correct order', function() { - // a<===b--->c~~~>d - var graph = iD.Graph([ - iD.Node({id: 'a', loc: [0, 0]}), - iD.Node({id: 'b', loc: [0, 0]}), - iD.Node({id: 'c', loc: [0, 0]}), - iD.Node({id: 'd', loc: [0, 0]}), - iD.Way({id: '=', nodes: ['b', 'a']}), - iD.Way({id: '-', nodes: ['b', 'c']}), - iD.Way({id: '~', nodes: ['c', 'd']}), - iD.Relation({id: 'r', members: [ + // a <=== b ---> c ~~~> d + var graph = iD.coreGraph([ + iD.osmNode({id: 'a', loc: [0, 0]}), + iD.osmNode({id: 'b', loc: [0, 0]}), + iD.osmNode({id: 'c', loc: [0, 0]}), + iD.osmNode({id: 'd', loc: [0, 0]}), + iD.osmWay({id: '=', nodes: ['b', 'a']}), + iD.osmWay({id: '-', nodes: ['b', 'c']}), + iD.osmWay({id: '~', nodes: ['c', 'd']}), + iD.osmRelation({id: 'r', members: [ {id: '-', type: 'way'}, {id: '~', type: 'way'}, {id: '=', type: 'way'} @@ -176,28 +186,28 @@ describe('iD.osmJoinWays', function() { // Expected result: // a --> b --> c // tags on === reversed - var graph = iD.Graph([ - iD.Node({id: 'a'}), - iD.Node({id: 'b'}), - iD.Node({id: 'c'}), - iD.Way({id: '-', nodes: ['a', 'b']}), - iD.Way({id: '=', nodes: ['c', 'b'], tags: {'oneway': 'yes', 'lanes:forward': 2}}) - ]); + var graph = iD.coreGraph([ + iD.osmNode({id: 'a'}), + iD.osmNode({id: 'b'}), + iD.osmNode({id: 'c'}), + iD.osmWay({id: '-', nodes: ['a', 'b']}), + iD.osmWay({id: '=', nodes: ['c', 'b'], tags: {'oneway': 'yes', 'lanes:forward': 2}}) + ]); var result = iD.osmJoinWays([graph.entity('-'), graph.entity('=')], graph); expect(result[0][1].tags).to.eql({'oneway': '-1', 'lanes:backward': 2}); }); it('ignores non-way members', function() { - var node = iD.Node({loc: [0, 0]}), - member = {id: 'n', type: 'node'}, - graph = iD.Graph([node]); + var node = iD.osmNode({loc: [0, 0]}); + var member = {id: 'n', type: 'node'}; + var graph = iD.coreGraph([node]); expect(iD.osmJoinWays([member], graph)).to.eql([]); }); it('ignores incomplete members', function() { - var member = {id: 'w', type: 'way'}, - graph = iD.Graph(); + var member = {id: 'w', type: 'way'}; + var graph = iD.coreGraph(); expect(iD.osmJoinWays([member], graph)).to.eql([]); }); });