Files
iD/test/spec/actions/reverse_way.js
John Firebaugh bcb4de4305 Reverse directional tags and roles when reversing a way
Reverse known direction dependent tags other than `oneway`.
We assume that correcting a backwards oneway is the primary
reason for reversing a way.

The following transforms are performed:

Keys:
      *:right=* ⟺ *:left=*
    *:forward=* ⟺ *:backward=*
   direction=up ⟺ direction=down
     incline=up ⟺ incline=down
        *=right ⟺ *=left

Relation members:
   role=forward ⟺ role=backward

In addition, numeric-valued `incline` tags are negated.

The JOSM implementation was used as a guide, but transformations that 
were of unclear benefit or adjusted tags that don't seem to be used
in practice were omitted.

References:
   http://wiki.openstreetmap.org/wiki/Forward_%26_backward,_left_%26_right
   http://wiki.openstreetmap.org/wiki/Key:direction#Steps
   http://wiki.openstreetmap.org/wiki/Key:incline
   http://wiki.openstreetmap.org/wiki/Route#Members
   http://josm.openstreetmap.de/browser/josm/trunk/src/org/openstreetmap/josm/corrector/ReverseWayTagCorrector.java

Fixes #299.
2013-01-07 16:26:56 -08:00

118 lines
4.5 KiB
JavaScript

describe("iD.actions.ReverseWay", function () {
it("reverses the order of nodes in the way", function () {
var node1 = iD.Node(),
node2 = iD.Node(),
way = iD.Way({nodes: [node1.id, node2.id]}),
graph = iD.actions.ReverseWay(way.id)(iD.Graph([node1, node2, way]));
expect(graph.entity(way.id).nodes).to.eql([node2.id, node1.id]);
});
it("preserves non-directional tags", function () {
var way = iD.Way({tags: {'highway': 'residential'}}),
graph = iD.Graph([way]);
graph = iD.actions.ReverseWay(way.id)(graph);
expect(graph.entity(way.id).tags).to.eql({'highway': 'residential'});
});
it("preserves oneway tags", function () {
var way = iD.Way({tags: {'oneway': 'yes'}}),
graph = iD.Graph([way]);
graph = iD.actions.ReverseWay(way.id)(graph);
expect(graph.entity(way.id).tags).to.eql({'oneway': 'yes'});
});
it("transforms *:right=* ⟺ *:left=*", function () {
var way = iD.Way({tags: {'cycleway:right': 'lane'}}),
graph = iD.Graph([way]);
graph = iD.actions.ReverseWay(way.id)(graph);
expect(graph.entity(way.id).tags).to.eql({'cycleway:left': 'lane'});
graph = iD.actions.ReverseWay(way.id)(graph);
expect(graph.entity(way.id).tags).to.eql({'cycleway:right': 'lane'});
});
it("transforms *:forward=* ⟺ *:backward=*", function () {
var way = iD.Way({tags: {'maxspeed:forward': '25'}}),
graph = iD.Graph([way]);
graph = iD.actions.ReverseWay(way.id)(graph);
expect(graph.entity(way.id).tags).to.eql({'maxspeed:backward': '25'});
graph = iD.actions.ReverseWay(way.id)(graph);
expect(graph.entity(way.id).tags).to.eql({'maxspeed:forward': '25'});
});
it("transforms direction=up ⟺ direction=down", function () {
var way = iD.Way({tags: {'incline': 'up'}}),
graph = iD.Graph([way]);
graph = iD.actions.ReverseWay(way.id)(graph);
expect(graph.entity(way.id).tags).to.eql({'incline': 'down'});
graph = iD.actions.ReverseWay(way.id)(graph);
expect(graph.entity(way.id).tags).to.eql({'incline': 'up'});
});
it("transforms incline=up ⟺ incline=down", function () {
var way = iD.Way({tags: {'incline': 'up'}}),
graph = iD.Graph([way]);
graph = iD.actions.ReverseWay(way.id)(graph);
expect(graph.entity(way.id).tags).to.eql({'incline': 'down'});
graph = iD.actions.ReverseWay(way.id)(graph);
expect(graph.entity(way.id).tags).to.eql({'incline': 'up'});
});
it("negates numeric-valued incline tags", function () {
var way = iD.Way({tags: {'incline': '5%'}}),
graph = iD.Graph([way]);
graph = iD.actions.ReverseWay(way.id)(graph);
expect(graph.entity(way.id).tags).to.eql({'incline': '-5%'});
graph = iD.actions.ReverseWay(way.id)(graph);
expect(graph.entity(way.id).tags).to.eql({'incline': '5%'});
way = iD.Way({tags: {'incline': '.8°'}});
graph = iD.Graph([way]);
graph = iD.actions.ReverseWay(way.id)(graph);
expect(graph.entity(way.id).tags).to.eql({'incline': '-.8°'});
});
it("transforms *=right ⟺ *=left", function () {
var way = iD.Way({tags: {'sidewalk': 'right'}}),
graph = iD.Graph([way]);
graph = iD.actions.ReverseWay(way.id)(graph);
expect(graph.entity(way.id).tags).to.eql({'sidewalk': 'left'});
graph = iD.actions.ReverseWay(way.id)(graph);
expect(graph.entity(way.id).tags).to.eql({'sidewalk': 'right'});
});
it("transforms multiple directional tags", function () {
var way = iD.Way({tags: {'maxspeed:forward': '25', 'maxspeed:backward': '30'}}),
graph = iD.Graph([way]);
graph = iD.actions.ReverseWay(way.id)(graph);
expect(graph.entity(way.id).tags).to.eql({'maxspeed:backward': '25', 'maxspeed:forward': '30'});
});
it("transforms role=forward ⟺ role=backward in member relations", function () {
var way = iD.Way({tags: {highway: 'residential'}}),
relation = iD.Relation({members: [{type: 'way', id: way.id, role: 'forward'}]}),
graph = iD.Graph([way, relation]);
graph = iD.actions.ReverseWay(way.id)(graph);
expect(graph.entity(relation.id).members[0].role).to.eql('backward');
graph = iD.actions.ReverseWay(way.id)(graph);
expect(graph.entity(relation.id).members[0].role).to.eql('forward');
});
});