diff --git a/js/id/geo/intersection.js b/js/id/geo/intersection.js index 1697cc7d4..8a4722810 100644 --- a/js/id/geo/intersection.js +++ b/js/id/geo/intersection.js @@ -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'; diff --git a/test/spec/actions/restrict_turn.js b/test/spec/actions/restrict_turn.js index a147470cb..2ed2e9b20 100644 --- a/test/spec/actions/restrict_turn.js +++ b/test/spec/actions/restrict_turn.js @@ -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: '='},