Fix restriction type inference (fixes #2233)

This commit is contained in:
John Firebaugh
2014-05-21 16:28:29 -07:00
parent b77f9f3a78
commit a2a4405ed8
2 changed files with 28 additions and 9 deletions
+9 -4
View File
@@ -124,11 +124,16 @@ iD.geo.inferRestriction = function(from, via, to, projection) {
angle = angle * 180 / Math.PI;
if (angle > 158 || angle < -158)
return 'no_straight_on';
if (angle > 23)
while (angle < 0)
angle += 360;
if (angle < 23)
return 'no_u_turn';
if (angle < 158)
return 'no_right_turn';
if (angle < -22)
if (angle < 202)
return 'no_straight_on';
if (angle < 336)
return 'no_left_turn';
return 'no_u_turn';
+19 -5
View File
@@ -257,26 +257,40 @@ describe("iD.actions.RestrictTurn", function() {
var graph = iD.Graph([
iD.Node({id: 'u', loc: [-1, 0]}),
iD.Node({id: '*', loc: [ 0, 0]}),
iD.Node({id: 'w', loc: [ 0, 1]}),
iD.Node({id: 'w', loc: [ 1, 0]}),
iD.Node({id: 'x', loc: [ 0, -1]}),
iD.Way({id: '=', nodes: ['u', '*']}),
iD.Way({id: '-', nodes: ['*', 'x']}),
iD.Way({id: '~', nodes: ['*', 'w']})
]);
var r = iD.actions.RestrictTurn({
var r1 = iD.actions.RestrictTurn({
from: {node: 'u', way: '='},
via: {node: '*'},
to: {node: 'x', way: '-'}
}, projection, 'r')(graph);
expect(r.entity('r').tags.restriction).to.equal('no_right_turn');
expect(r1.entity('r').tags.restriction).to.equal('no_right_turn');
var l = iD.actions.RestrictTurn({
var r2 = iD.actions.RestrictTurn({
from: {node: 'x', way: '-'},
via: {node: '*'},
to: {node: 'w', way: '~'}
}, projection, 'r')(graph);
expect(r2.entity('r').tags.restriction).to.equal('no_right_turn');
var l1 = iD.actions.RestrictTurn({
from: {node: 'x', way: '-'},
via: {node: '*'},
to: {node: 'u', way: '='}
}, projection, 'r')(graph);
expect(l.entity('r').tags.restriction).to.equal('no_left_turn');
expect(l1.entity('r').tags.restriction).to.equal('no_left_turn');
var l2 = iD.actions.RestrictTurn({
from: {node: 'w', way: '~'},
via: {node: '*'},
to: {node: 'x', way: '-'}
}, projection, 'r')(graph);
expect(l2.entity('r').tags.restriction).to.equal('no_left_turn');
var s = iD.actions.RestrictTurn({
from: {node: 'u', way: '='},