From f6e726bcd68dd2f0a43d14e407794eed0b213978 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Wed, 6 Feb 2013 14:31:11 -0800 Subject: [PATCH] Join should run Reverse where necessary (fixes #652) --- js/id/actions/join.js | 6 ++++-- test/spec/actions/join.js | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/js/id/actions/join.js b/js/id/actions/join.js index 7bba4783c..267b6c75a 100644 --- a/js/id/actions/join.js +++ b/js/id/actions/join.js @@ -24,7 +24,8 @@ iD.actions.Join = function(ids) { // a <-- b ==> c // Expected result: // a <-- b <-- c - nodes = b.nodes.slice().reverse().concat(a.nodes.slice(1)); + b = iD.actions.Reverse(idB)(graph).entity(idB); + nodes = b.nodes.slice().concat(a.nodes.slice(1)); } else if (a.first() === b.last()) { // a <-- b <== c @@ -42,7 +43,8 @@ iD.actions.Join = function(ids) { // a --> b <== c // Expected result: // a --> b --> c - nodes = a.nodes.concat(b.nodes.slice().reverse().slice(1)); + b = iD.actions.Reverse(idB)(graph).entity(idB); + nodes = a.nodes.concat(b.nodes.slice().slice(1)); } graph.parentRelations(b).forEach(function (parent) { diff --git a/test/spec/actions/join.js b/test/spec/actions/join.js index 11a95bc2d..6951013d3 100644 --- a/test/spec/actions/join.js +++ b/test/spec/actions/join.js @@ -112,13 +112,14 @@ describe("iD.actions.Join", function () { 'b': iD.Node({id: 'b'}), 'c': iD.Node({id: 'c'}), '-': iD.Way({id: '-', nodes: ['b', 'a']}), - '=': iD.Way({id: '=', nodes: ['b', 'c']}) + '=': iD.Way({id: '=', nodes: ['b', 'c'], tags: {'lanes:forward': 2}}) }); graph = iD.actions.Join(['-', '='])(graph); expect(graph.entity('-').nodes).to.eql(['c', 'b', 'a']); expect(graph.entity('=')).to.be.undefined; + expect(graph.entity('-').tags).to.eql({'lanes:backward': 2}); }); it("joins a --> b <== c", function () { @@ -130,13 +131,14 @@ describe("iD.actions.Join", function () { 'b': iD.Node({id: 'b'}), 'c': iD.Node({id: 'c'}), '-': iD.Way({id: '-', nodes: ['a', 'b']}), - '=': iD.Way({id: '=', nodes: ['c', 'b']}) + '=': iD.Way({id: '=', nodes: ['c', 'b'], tags: {'lanes:forward': 2}}) }); graph = iD.actions.Join(['-', '='])(graph); expect(graph.entity('-').nodes).to.eql(['a', 'b', 'c']); expect(graph.entity('=')).to.be.undefined; + expect(graph.entity('-').tags).to.eql({'lanes:backward': 2}); }); it("merges tags", function () {