Fix travel mode passing from profiles up to the API
This commit is contained in:
		
							parent
							
								
									721cc32acb
								
							
						
					
					
						commit
						5626182c60
					
				| @ -31,59 +31,8 @@ struct ExtractionWay | |||||||
|         is_startpoint = true; |         is_startpoint = true; | ||||||
|         is_access_restricted = false; |         is_access_restricted = false; | ||||||
|         name.clear(); |         name.clear(); | ||||||
|         forward_travel_mode = TRAVEL_MODE_DEFAULT; |  | ||||||
|         backward_travel_mode = TRAVEL_MODE_DEFAULT; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     enum Directions |  | ||||||
|     { |  | ||||||
|         notSure = 0, |  | ||||||
|         oneway, |  | ||||||
|         bidirectional, |  | ||||||
|         opposite |  | ||||||
|     }; |  | ||||||
| 
 |  | ||||||
|     // These accessor methods exists to support the depreciated "way.direction" access
 |  | ||||||
|     // in LUA. Since the direction attribute was removed from ExtractionWay, the
 |  | ||||||
|     // accessors translate to/from the mode attributes.
 |  | ||||||
|     void set_direction(const Directions m) |  | ||||||
|     { |  | ||||||
|         if (Directions::oneway == m) |  | ||||||
|         { |  | ||||||
|             forward_travel_mode = TRAVEL_MODE_DEFAULT; |  | ||||||
|             backward_travel_mode = TRAVEL_MODE_INACCESSIBLE; |  | ||||||
|         } |  | ||||||
|         else if (Directions::opposite == m) |  | ||||||
|         { |  | ||||||
|         forward_travel_mode = TRAVEL_MODE_INACCESSIBLE; |         forward_travel_mode = TRAVEL_MODE_INACCESSIBLE; | ||||||
|             backward_travel_mode = TRAVEL_MODE_DEFAULT; |         backward_travel_mode = TRAVEL_MODE_INACCESSIBLE; | ||||||
|         } |  | ||||||
|         else if (Directions::bidirectional == m) |  | ||||||
|         { |  | ||||||
|             forward_travel_mode = TRAVEL_MODE_DEFAULT; |  | ||||||
|             backward_travel_mode = TRAVEL_MODE_DEFAULT; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     Directions get_direction() const |  | ||||||
|     { |  | ||||||
|         if (TRAVEL_MODE_INACCESSIBLE != forward_travel_mode && |  | ||||||
|             TRAVEL_MODE_INACCESSIBLE != backward_travel_mode) |  | ||||||
|         { |  | ||||||
|             return Directions::bidirectional; |  | ||||||
|         } |  | ||||||
|         else if (TRAVEL_MODE_INACCESSIBLE != forward_travel_mode) |  | ||||||
|         { |  | ||||||
|             return Directions::oneway; |  | ||||||
|         } |  | ||||||
|         else if (TRAVEL_MODE_INACCESSIBLE != backward_travel_mode) |  | ||||||
|         { |  | ||||||
|             return Directions::opposite; |  | ||||||
|         } |  | ||||||
|         else |  | ||||||
|         { |  | ||||||
|             return Directions::notSure; |  | ||||||
|         } |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     // These accessors exists because it's not possible to take the address of a bitfield,
 |     // These accessors exists because it's not possible to take the address of a bitfield,
 | ||||||
|  | |||||||
| @ -13,5 +13,18 @@ using TravelMode = unsigned char; | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| const constexpr osrm::extractor::TravelMode TRAVEL_MODE_INACCESSIBLE = 0; | const constexpr osrm::extractor::TravelMode TRAVEL_MODE_INACCESSIBLE = 0; | ||||||
| const constexpr osrm::extractor::TravelMode TRAVEL_MODE_DEFAULT = 1; | const constexpr osrm::extractor::TravelMode TRAVEL_MODE_DRIVING = 1; | ||||||
|  | const constexpr osrm::extractor::TravelMode TRAVEL_MODE_CYCLING = 2; | ||||||
|  | const constexpr osrm::extractor::TravelMode TRAVEL_MODE_WALKING = 3; | ||||||
|  | const constexpr osrm::extractor::TravelMode TRAVEL_MODE_FERRY = 4; | ||||||
|  | const constexpr osrm::extractor::TravelMode TRAVEL_MODE_TRAIN = 5; | ||||||
|  | const constexpr osrm::extractor::TravelMode TRAVEL_MODE_PUSHING_BIKE = 6; | ||||||
|  | const constexpr osrm::extractor::TravelMode TRAVEL_MODE_MOVABLE_BRIDGE = 7; | ||||||
|  | // FIXME only for testbot.lua
 | ||||||
|  | const constexpr osrm::extractor::TravelMode TRAVEL_MODE_STEPS_UP = 8; | ||||||
|  | const constexpr osrm::extractor::TravelMode TRAVEL_MODE_STEPS_DOWN = 9; | ||||||
|  | const constexpr osrm::extractor::TravelMode TRAVEL_MODE_RIVER_UP = 10; | ||||||
|  | const constexpr osrm::extractor::TravelMode TRAVEL_MODE_RIVER_DOWN = 11; | ||||||
|  | const constexpr osrm::extractor::TravelMode TRAVEL_MODE_ROUTE = 12; | ||||||
|  | 
 | ||||||
| #endif /* TRAVEL_MODE_HPP */ | #endif /* TRAVEL_MODE_HPP */ | ||||||
|  | |||||||
| @ -105,13 +105,6 @@ local safety_penalty            = 1.0 | |||||||
| local use_public_transport      = true | local use_public_transport      = true | ||||||
| local fallback_names            = true | local fallback_names            = true | ||||||
| 
 | 
 | ||||||
| --modes |  | ||||||
| local mode_normal = 1 |  | ||||||
| local mode_pushing = 2 |  | ||||||
| local mode_ferry = 3 |  | ||||||
| local mode_train = 4 |  | ||||||
| local mode_movable_bridge = 5 |  | ||||||
| 
 |  | ||||||
| local function parse_maxspeed(source) | local function parse_maxspeed(source) | ||||||
|     if not source then |     if not source then | ||||||
|         return 0 |         return 0 | ||||||
| @ -191,6 +184,9 @@ function way_function (way, result) | |||||||
|     return |     return | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|  |   result.forward_mode = mode.cycling | ||||||
|  |   result.backward_mode = mode.cycling | ||||||
|  | 
 | ||||||
|   -- other tags |   -- other tags | ||||||
|   local name = way:get_value_by_key("name") |   local name = way:get_value_by_key("name") | ||||||
|   local ref = way:get_value_by_key("ref") |   local ref = way:get_value_by_key("ref") | ||||||
| @ -237,14 +233,14 @@ function way_function (way, result) | |||||||
|     if duration and durationIsValid(duration) then |     if duration and durationIsValid(duration) then | ||||||
|       result.duration = math.max( parseDuration(duration), 1 ) |       result.duration = math.max( parseDuration(duration), 1 ) | ||||||
|     end |     end | ||||||
|     result.forward_mode = mode_movable_bridge |     result.forward_mode = mode.movable_bridge | ||||||
|     result.backward_mode = mode_movable_bridge |     result.backward_mode = mode.movable_bridge | ||||||
|     result.forward_speed = bridge_speed |     result.forward_speed = bridge_speed | ||||||
|     result.backward_speed = bridge_speed |     result.backward_speed = bridge_speed | ||||||
|   elseif route_speeds[route] then |   elseif route_speeds[route] then | ||||||
|     -- ferries (doesn't cover routes tagged using relations) |     -- ferries (doesn't cover routes tagged using relations) | ||||||
|     result.forward_mode = mode_ferry |     result.forward_mode = mode.ferry | ||||||
|     result.backward_mode = mode_ferry |     result.backward_mode = mode.ferry | ||||||
|     result.ignore_in_grid = true |     result.ignore_in_grid = true | ||||||
|     if duration and durationIsValid(duration) then |     if duration and durationIsValid(duration) then | ||||||
|       result.duration = math.max( 1, parseDuration(duration) ) |       result.duration = math.max( 1, parseDuration(duration) ) | ||||||
| @ -262,8 +258,8 @@ function way_function (way, result) | |||||||
|     result.forward_speed = platform_speeds[public_transport] |     result.forward_speed = platform_speeds[public_transport] | ||||||
|     result.backward_speed = platform_speeds[public_transport] |     result.backward_speed = platform_speeds[public_transport] | ||||||
|   elseif use_public_transport and railway and railway_speeds[railway] then |   elseif use_public_transport and railway and railway_speeds[railway] then | ||||||
|       result.forward_mode = mode_train |       result.forward_mode = mode.train | ||||||
|       result.backward_mode = mode_train |       result.backward_mode = mode.train | ||||||
|      -- railways |      -- railways | ||||||
|     if access and access_tag_whitelist[access] then |     if access and access_tag_whitelist[access] then | ||||||
|       result.forward_speed = railway_speeds[railway] |       result.forward_speed = railway_speeds[railway] | ||||||
| @ -293,27 +289,27 @@ function way_function (way, result) | |||||||
|         -- pedestrian-only ways and areas |         -- pedestrian-only ways and areas | ||||||
|         result.forward_speed = pedestrian_speeds[highway] |         result.forward_speed = pedestrian_speeds[highway] | ||||||
|         result.backward_speed = pedestrian_speeds[highway] |         result.backward_speed = pedestrian_speeds[highway] | ||||||
|         result.forward_mode = mode_pushing |         result.forward_mode = mode.pushing_bike | ||||||
|         result.backward_mode = mode_pushing |         result.backward_mode = mode.pushing_bike | ||||||
|       elseif man_made and man_made_speeds[man_made] then |       elseif man_made and man_made_speeds[man_made] then | ||||||
|         -- man made structures |         -- man made structures | ||||||
|         result.forward_speed = man_made_speeds[man_made] |         result.forward_speed = man_made_speeds[man_made] | ||||||
|         result.backward_speed = man_made_speeds[man_made] |         result.backward_speed = man_made_speeds[man_made] | ||||||
|         result.forward_mode = mode_pushing |         result.forward_mode = mode.pushing_bike | ||||||
|         result.backward_mode = mode_pushing |         result.backward_mode = mode.pushing_bike | ||||||
|       elseif foot == 'yes' then |       elseif foot == 'yes' then | ||||||
|         result.forward_speed = walking_speed |         result.forward_speed = walking_speed | ||||||
|         result.backward_speed = walking_speed |         result.backward_speed = walking_speed | ||||||
|         result.forward_mode = mode_pushing |         result.forward_mode = mode.pushing_bike | ||||||
|         result.backward_mode = mode_pushing |         result.backward_mode = mode.pushing_bike | ||||||
|       elseif foot_forward == 'yes' then |       elseif foot_forward == 'yes' then | ||||||
|         result.forward_speed = walking_speed |         result.forward_speed = walking_speed | ||||||
|         result.forward_mode = mode_pushing |         result.forward_mode = mode.pushing_bike | ||||||
|         result.backward_mode = 0 |         result.backward_mode = mode.inaccessible | ||||||
|       elseif foot_backward == 'yes' then |       elseif foot_backward == 'yes' then | ||||||
|         result.forward_speed = walking_speed |         result.forward_speed = walking_speed | ||||||
|         result.forward_mode = 0 |         result.forward_mode = mode.inaccessible | ||||||
|         result.backward_mode = mode_pushing |         result.backward_mode = mode.pushing_bike | ||||||
|       end |       end | ||||||
|     end |     end | ||||||
|   end |   end | ||||||
| @ -325,48 +321,48 @@ function way_function (way, result) | |||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|   if onewayClass == "yes" or onewayClass == "1" or onewayClass == "true" then |   if onewayClass == "yes" or onewayClass == "1" or onewayClass == "true" then | ||||||
|     result.backward_mode = 0 |     result.backward_mode = mode.inaccessible | ||||||
|   elseif onewayClass == "no" or onewayClass == "0" or onewayClass == "false" then |   elseif onewayClass == "no" or onewayClass == "0" or onewayClass == "false" then | ||||||
|     -- prevent implied oneway |     -- prevent implied oneway | ||||||
|   elseif onewayClass == "-1" then |   elseif onewayClass == "-1" then | ||||||
|     result.forward_mode = 0 |     result.forward_mode = mode.inaccessible | ||||||
|   elseif oneway == "no" or oneway == "0" or oneway == "false" then |   elseif oneway == "no" or oneway == "0" or oneway == "false" then | ||||||
|     -- prevent implied oneway |     -- prevent implied oneway | ||||||
|   elseif cycleway and string.find(cycleway, "opposite") == 1 then |   elseif cycleway and string.find(cycleway, "opposite") == 1 then | ||||||
|     if impliedOneway then |     if impliedOneway then | ||||||
|       result.forward_mode = 0 |       result.forward_mode = mode.inaccessible | ||||||
|       result.backward_mode = mode_normal |       result.backward_mode = mode.cycling | ||||||
|       result.backward_speed = bicycle_speeds["cycleway"] |       result.backward_speed = bicycle_speeds["cycleway"] | ||||||
|     end |     end | ||||||
|   elseif cycleway_left and cycleway_tags[cycleway_left] and cycleway_right and cycleway_tags[cycleway_right] then |   elseif cycleway_left and cycleway_tags[cycleway_left] and cycleway_right and cycleway_tags[cycleway_right] then | ||||||
|     -- prevent implied |     -- prevent implied | ||||||
|   elseif cycleway_left and cycleway_tags[cycleway_left] then |   elseif cycleway_left and cycleway_tags[cycleway_left] then | ||||||
|     if impliedOneway then |     if impliedOneway then | ||||||
|       result.forward_mode = 0 |       result.forward_mode = mode.inaccessible | ||||||
|       result.backward_mode = mode_normal |       result.backward_mode = mode.cycling | ||||||
|       result.backward_speed = bicycle_speeds["cycleway"] |       result.backward_speed = bicycle_speeds["cycleway"] | ||||||
|     end |     end | ||||||
|   elseif cycleway_right and cycleway_tags[cycleway_right] then |   elseif cycleway_right and cycleway_tags[cycleway_right] then | ||||||
|     if impliedOneway then |     if impliedOneway then | ||||||
|       result.forward_mode = mode_normal |       result.forward_mode = mode.cycling | ||||||
|       result.backward_speed = bicycle_speeds["cycleway"] |       result.backward_speed = bicycle_speeds["cycleway"] | ||||||
|       result.backward_mode = 0 |       result.backward_mode = mode.cycling | ||||||
|     end |     end | ||||||
|   elseif oneway == "-1" then |   elseif oneway == "-1" then | ||||||
|     result.forward_mode = 0 |     result.forward_mode = mode.inaccessible | ||||||
|   elseif oneway == "yes" or oneway == "1" or oneway == "true" or impliedOneway then |   elseif oneway == "yes" or oneway == "1" or oneway == "true" or impliedOneway then | ||||||
|     result.backward_mode = 0 |     result.backward_mode = mode.inaccessible | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|   -- pushing bikes |   -- pushing bikes | ||||||
|   if bicycle_speeds[highway] or pedestrian_speeds[highway] then |   if bicycle_speeds[highway] or pedestrian_speeds[highway] then | ||||||
|     if foot ~= "no" and junction ~= "roundabout" then |     if foot ~= "no" and junction ~= "roundabout" then | ||||||
|       if result.backward_mode == 0 then |       if result.backward_mode == mode.inaccessible then | ||||||
|         result.backward_speed = walking_speed |         result.backward_speed = walking_speed | ||||||
|         result.backward_mode = mode_pushing |         result.backward_mode = mode.pushing_bike | ||||||
|       elseif result.forward_mode == 0 then |       elseif result.forward_mode == mode.inaccessible then | ||||||
|         result.forward_speed = walking_speed |         result.forward_speed = walking_speed | ||||||
|         result.forward_mode = mode_pushing |         result.forward_mode = mode.pushing_bike | ||||||
|       end |       end | ||||||
|     end |     end | ||||||
|   end |   end | ||||||
| @ -382,8 +378,8 @@ function way_function (way, result) | |||||||
| 
 | 
 | ||||||
|   -- dismount |   -- dismount | ||||||
|   if bicycle == "dismount" then |   if bicycle == "dismount" then | ||||||
|     result.forward_mode = mode_pushing |     result.forward_mode = mode.pushing_bike | ||||||
|     result.backward_mode = mode_pushing |     result.backward_mode = mode.pushing_bike | ||||||
|     result.forward_speed = walking_speed |     result.forward_speed = walking_speed | ||||||
|     result.backward_speed = walking_speed |     result.backward_speed = walking_speed | ||||||
|   end |   end | ||||||
|  | |||||||
| @ -149,11 +149,6 @@ local max = math.max | |||||||
| 
 | 
 | ||||||
| local speed_reduction = 0.8 | local speed_reduction = 0.8 | ||||||
| 
 | 
 | ||||||
| --modes |  | ||||||
| local mode_normal = 1 |  | ||||||
| local mode_ferry = 2 |  | ||||||
| local mode_movable_bridge = 3 |  | ||||||
| 
 |  | ||||||
| function get_exceptions(vector) | function get_exceptions(vector) | ||||||
|   for i,v in ipairs(restriction_exception_tags) do |   for i,v in ipairs(restriction_exception_tags) do | ||||||
|     vector:Add(v) |     vector:Add(v) | ||||||
| @ -248,6 +243,9 @@ function way_function (way, result) | |||||||
|     return |     return | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|  |   result.forward_mode = mode.driving | ||||||
|  |   result.backward_mode = mode.driving | ||||||
|  | 
 | ||||||
|   -- handling ferries and piers |   -- handling ferries and piers | ||||||
|   local route_speed = speed_profile[route] |   local route_speed = speed_profile[route] | ||||||
|   if (route_speed and route_speed > 0) then |   if (route_speed and route_speed > 0) then | ||||||
| @ -256,8 +254,8 @@ function way_function (way, result) | |||||||
|     if duration and durationIsValid(duration) then |     if duration and durationIsValid(duration) then | ||||||
|       result.duration = max( parseDuration(duration), 1 ) |       result.duration = max( parseDuration(duration), 1 ) | ||||||
|     end |     end | ||||||
|     result.forward_mode = mode_ferry |     result.forward_mode = mode.ferry | ||||||
|     result.backward_mode = mode_ferry |     result.backward_mode = mode.ferry | ||||||
|     result.forward_speed = route_speed |     result.forward_speed = route_speed | ||||||
|     result.backward_speed = route_speed |     result.backward_speed = route_speed | ||||||
|   end |   end | ||||||
| @ -271,8 +269,8 @@ function way_function (way, result) | |||||||
|     if duration and durationIsValid(duration) then |     if duration and durationIsValid(duration) then | ||||||
|       result.duration = max( parseDuration(duration), 1 ) |       result.duration = max( parseDuration(duration), 1 ) | ||||||
|     end |     end | ||||||
|     result.forward_mode = mode_movable_bridge |     result.forward_mode = mode.movable_bridge | ||||||
|     result.backward_mode = mode_movable_bridge |     result.backward_mode = mode.movable_bridge | ||||||
|     result.forward_speed = bridge_speed |     result.forward_speed = bridge_speed | ||||||
|     result.backward_speed = bridge_speed |     result.backward_speed = bridge_speed | ||||||
|   end |   end | ||||||
| @ -378,14 +376,14 @@ function way_function (way, result) | |||||||
|   -- Set direction according to tags on way |   -- Set direction according to tags on way | ||||||
|   if obey_oneway then |   if obey_oneway then | ||||||
|     if oneway == "-1" then |     if oneway == "-1" then | ||||||
|       result.forward_mode = 0 |       result.forward_mode = mode.inaccessible | ||||||
|     elseif oneway == "yes" or |     elseif oneway == "yes" or | ||||||
|     oneway == "1" or |     oneway == "1" or | ||||||
|     oneway == "true" or |     oneway == "true" or | ||||||
|     junction == "roundabout" or |     junction == "roundabout" or | ||||||
|     (highway == "motorway_link" and oneway ~="no") or |     (highway == "motorway_link" and oneway ~="no") or | ||||||
|     (highway == "motorway" and oneway ~= "no") then |     (highway == "motorway" and oneway ~= "no") then | ||||||
|       result.backward_mode = 0 |       result.backward_mode = mode.inaccessible | ||||||
|     end |     end | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
| @ -393,7 +391,7 @@ function way_function (way, result) | |||||||
|   local maxspeed_forward = parse_maxspeed(way:get_value_by_key("maxspeed:forward")) |   local maxspeed_forward = parse_maxspeed(way:get_value_by_key("maxspeed:forward")) | ||||||
|   local maxspeed_backward = parse_maxspeed(way:get_value_by_key("maxspeed:backward")) |   local maxspeed_backward = parse_maxspeed(way:get_value_by_key("maxspeed:backward")) | ||||||
|   if maxspeed_forward and maxspeed_forward > 0 then |   if maxspeed_forward and maxspeed_forward > 0 then | ||||||
|     if 0 ~= result.forward_mode and 0 ~= result.backward_mode then |     if mode.inaccessible ~= result.forward_mode and mode.inaccessible ~= result.backward_mode then | ||||||
|       result.backward_speed = result.forward_speed |       result.backward_speed = result.forward_speed | ||||||
|     end |     end | ||||||
|     result.forward_speed = maxspeed_forward |     result.forward_speed = maxspeed_forward | ||||||
| @ -408,15 +406,15 @@ function way_function (way, result) | |||||||
|   local advisory_backward = parse_maxspeed(way:get_value_by_key("maxspeed:advisory:backward")) |   local advisory_backward = parse_maxspeed(way:get_value_by_key("maxspeed:advisory:backward")) | ||||||
|   -- apply bi-directional advisory speed first |   -- apply bi-directional advisory speed first | ||||||
|   if advisory_speed and advisory_speed > 0 then |   if advisory_speed and advisory_speed > 0 then | ||||||
|     if 0 ~= result.forward_mode then |     if mode.inaccessible ~= result.forward_mode then | ||||||
|       result.forward_speed = advisory_speed |       result.forward_speed = advisory_speed | ||||||
|     end |     end | ||||||
|     if 0 ~= result.backward_mode then |     if mode.inaccessible ~= result.backward_mode then | ||||||
|       result.backward_speed = advisory_speed |       result.backward_speed = advisory_speed | ||||||
|     end |     end | ||||||
|   end |   end | ||||||
|   if advisory_forward and advisory_forward > 0 then |   if advisory_forward and advisory_forward > 0 then | ||||||
|     if 0 ~= result.forward_mode and 0 ~= result.backward_mode then |     if mode.inaccessible ~= result.forward_mode and mode.inaccessible ~= result.backward_mode then | ||||||
|       result.backward_speed = result.forward_speed |       result.backward_speed = result.forward_speed | ||||||
|     end |     end | ||||||
|     result.forward_speed = advisory_forward |     result.forward_speed = advisory_forward | ||||||
| @ -439,7 +437,7 @@ function way_function (way, result) | |||||||
|     end |     end | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|   local is_bidirectional = result.forward_mode ~= 0 and result.backward_mode ~= 0 |   local is_bidirectional = result.forward_mode ~= mode.inaccessible and result.backward_mode ~= mode.inaccessible | ||||||
| 
 | 
 | ||||||
|   -- scale speeds to get better avg driving times |   -- scale speeds to get better avg driving times | ||||||
|   if result.forward_speed > 0 then |   if result.forward_speed > 0 then | ||||||
| @ -461,7 +459,7 @@ function way_function (way, result) | |||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|   -- only allow this road as start point if it not a ferry |   -- only allow this road as start point if it not a ferry | ||||||
|   result.is_startpoint = result.forward_mode == mode_normal or result.backward_mode == mode_normal |   result.is_startpoint = result.forward_mode == mode.driving or result.backward_mode == mode.driving | ||||||
| end | end | ||||||
| 
 | 
 | ||||||
| function turn_function (angle) | function turn_function (angle) | ||||||
|  | |||||||
| @ -69,10 +69,6 @@ u_turn_penalty           = 2 | |||||||
| use_turn_restrictions    = false | use_turn_restrictions    = false | ||||||
| local fallback_names     = true | local fallback_names     = true | ||||||
| 
 | 
 | ||||||
| --modes |  | ||||||
| local mode_normal = 1 |  | ||||||
| local mode_ferry = 2 |  | ||||||
| 
 |  | ||||||
| function get_exceptions(vector) | function get_exceptions(vector) | ||||||
|   for i,v in ipairs(restriction_exception_tags) do |   for i,v in ipairs(restriction_exception_tags) do | ||||||
|     vector:Add(v) |     vector:Add(v) | ||||||
| @ -138,6 +134,9 @@ function way_function (way, result) | |||||||
|     return |     return | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|  |   result.forward_mode = mode.walking | ||||||
|  |   result.backward_mode = mode.walking | ||||||
|  | 
 | ||||||
|   local name = way:get_value_by_key("name") |   local name = way:get_value_by_key("name") | ||||||
|   local ref = way:get_value_by_key("ref") |   local ref = way:get_value_by_key("ref") | ||||||
|   local junction = way:get_value_by_key("junction") |   local junction = way:get_value_by_key("junction") | ||||||
| @ -175,8 +174,8 @@ function way_function (way, result) | |||||||
|     result.forward_speed = route_speeds[route] |     result.forward_speed = route_speeds[route] | ||||||
|     result.backward_speed = route_speeds[route] |     result.backward_speed = route_speeds[route] | ||||||
|   end |   end | ||||||
|     result.forward_mode = mode_ferry |     result.forward_mode = mode.ferry | ||||||
|     result.backward_mode = mode_ferry |     result.backward_mode = mode.ferry | ||||||
|   elseif railway and platform_speeds[railway] then |   elseif railway and platform_speeds[railway] then | ||||||
|     -- railway platforms (old tagging scheme) |     -- railway platforms (old tagging scheme) | ||||||
|     result.forward_speed = platform_speeds[railway] |     result.forward_speed = platform_speeds[railway] | ||||||
| @ -205,11 +204,11 @@ function way_function (way, result) | |||||||
| 
 | 
 | ||||||
|   -- oneway |   -- oneway | ||||||
|   if onewayClass == "yes" or onewayClass == "1" or onewayClass == "true" then |   if onewayClass == "yes" or onewayClass == "1" or onewayClass == "true" then | ||||||
|     result.backward_mode = 0 |     result.backward_mode = mode.inaccessible | ||||||
|   elseif onewayClass == "no" or onewayClass == "0" or onewayClass == "false" then |   elseif onewayClass == "no" or onewayClass == "0" or onewayClass == "false" then | ||||||
|     -- nothing to do |     -- nothing to do | ||||||
|   elseif onewayClass == "-1" then |   elseif onewayClass == "-1" then | ||||||
|     result.forward_mode = 0 |     result.forward_mode = mode.inaccessible | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|   -- surfaces |   -- surfaces | ||||||
|  | |||||||
| @ -6,14 +6,6 @@ | |||||||
| -- Secondary road:  18km/h = 18000m/3600s = 100m/20s | -- Secondary road:  18km/h = 18000m/3600s = 100m/20s | ||||||
| -- Tertiary road:  12km/h = 12000m/3600s = 100m/30s | -- Tertiary road:  12km/h = 12000m/3600s = 100m/30s | ||||||
| 
 | 
 | ||||||
| -- modes: |  | ||||||
| -- 1: normal |  | ||||||
| -- 2: route |  | ||||||
| -- 3: river downstream |  | ||||||
| -- 4: river upstream |  | ||||||
| -- 5: steps down |  | ||||||
| -- 6: steps up |  | ||||||
| 
 |  | ||||||
| speed_profile = { | speed_profile = { | ||||||
|   ["primary"] = 36, |   ["primary"] = 36, | ||||||
|   ["secondary"] = 18, |   ["secondary"] = 18, | ||||||
| @ -68,24 +60,26 @@ function way_function (way, result) | |||||||
|   if name then |   if name then | ||||||
|     result.name = name |     result.name = name | ||||||
|   end |   end | ||||||
|  |   result.forward_mode = mode.driving | ||||||
|  |   result.backward_mode = mode.driving | ||||||
| 
 | 
 | ||||||
|   if duration and durationIsValid(duration) then |   if duration and durationIsValid(duration) then | ||||||
|     result.duration = math.max( 1, parseDuration(duration) ) |     result.duration = math.max( 1, parseDuration(duration) ) | ||||||
|     result.forward_mode = 2 |     result.forward_mode = mode.route | ||||||
|     result.backward_mode = 2 |     result.backward_mode = mode.route | ||||||
|   else |   else | ||||||
|     local speed_forw = speed_profile[highway] or speed_profile['default'] |     local speed_forw = speed_profile[highway] or speed_profile['default'] | ||||||
|     local speed_back = speed_forw |     local speed_back = speed_forw | ||||||
| 
 | 
 | ||||||
|     if highway == "river" then |     if highway == "river" then | ||||||
|       local temp_speed = speed_forw |       local temp_speed = speed_forw | ||||||
|       result.forward_mode = 3 |       result.forward_mode = mode.river_up | ||||||
|       result.backward_mode = 4 |       result.backward_mode = mode.river_down | ||||||
|       speed_forw = temp_speed*1.5 |       speed_forw = temp_speed*1.5 | ||||||
|       speed_back = temp_speed/1.5 |       speed_back = temp_speed/1.5 | ||||||
|     elseif highway == "steps" then |     elseif highway == "steps" then | ||||||
|       result.forward_mode = 5 |       result.forward_mode = mode.steps_up | ||||||
|       result.backward_mode = 6 |       result.backward_mode = mode.steps_down | ||||||
|     end |     end | ||||||
| 
 | 
 | ||||||
|     if maxspeed_forward ~= nil and maxspeed_forward > 0 then |     if maxspeed_forward ~= nil and maxspeed_forward > 0 then | ||||||
| @ -111,9 +105,9 @@ function way_function (way, result) | |||||||
|   if oneway == "no" or oneway == "0" or oneway == "false" then |   if oneway == "no" or oneway == "0" or oneway == "false" then | ||||||
|     -- nothing to do |     -- nothing to do | ||||||
|   elseif oneway == "-1" then |   elseif oneway == "-1" then | ||||||
|     result.forward_mode = 0 |     result.forward_mode = mode.inaccessible | ||||||
|   elseif oneway == "yes" or oneway == "1" or oneway == "true" or junction == "roundabout" then |   elseif oneway == "yes" or oneway == "1" or oneway == "true" or junction == "roundabout" then | ||||||
|     result.backward_mode = 0 |     result.backward_mode = mode.inaccessible | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|   if junction == 'roundabout' then |   if junction == 'roundabout' then | ||||||
|  | |||||||
| @ -107,12 +107,45 @@ std::string modeToString(const extractor::TravelMode mode) | |||||||
|     std::string token; |     std::string token; | ||||||
|     switch (mode) |     switch (mode) | ||||||
|     { |     { | ||||||
|     case TRAVEL_MODE_DEFAULT: |  | ||||||
|         token = "default"; |  | ||||||
|         break; |  | ||||||
|     case TRAVEL_MODE_INACCESSIBLE: |     case TRAVEL_MODE_INACCESSIBLE: | ||||||
|         token = "inaccessible"; |         token = "inaccessible"; | ||||||
|         break; |         break; | ||||||
|  |     case TRAVEL_MODE_DRIVING: | ||||||
|  |         token = "driving"; | ||||||
|  |         break; | ||||||
|  |     case TRAVEL_MODE_CYCLING: | ||||||
|  |         token = "cycling"; | ||||||
|  |         break; | ||||||
|  |     case TRAVEL_MODE_WALKING: | ||||||
|  |         token = "walking"; | ||||||
|  |         break; | ||||||
|  |     case TRAVEL_MODE_FERRY: | ||||||
|  |         token = "ferry"; | ||||||
|  |         break; | ||||||
|  |     case TRAVEL_MODE_TRAIN: | ||||||
|  |         token = "train"; | ||||||
|  |         break; | ||||||
|  |     case TRAVEL_MODE_PUSHING_BIKE: | ||||||
|  |         token = "pushing bike"; | ||||||
|  |         break; | ||||||
|  |     case TRAVEL_MODE_MOVABLE_BRIDGE: | ||||||
|  |         token = "movable bridge"; | ||||||
|  |         break; | ||||||
|  |     case TRAVEL_MODE_STEPS_UP: | ||||||
|  |         token = "steps up"; | ||||||
|  |         break; | ||||||
|  |     case TRAVEL_MODE_STEPS_DOWN: | ||||||
|  |         token = "steps down"; | ||||||
|  |         break; | ||||||
|  |     case TRAVEL_MODE_RIVER_UP: | ||||||
|  |         token = "river upstream"; | ||||||
|  |         break; | ||||||
|  |     case TRAVEL_MODE_RIVER_DOWN: | ||||||
|  |         token = "river downstream"; | ||||||
|  |         break; | ||||||
|  |     case TRAVEL_MODE_ROUTE: | ||||||
|  |         token = "rout"; | ||||||
|  |         break; | ||||||
|     default: |     default: | ||||||
|         token = "other"; |         token = "other"; | ||||||
|         break; |         break; | ||||||
| @ -132,8 +165,7 @@ util::json::Object makeStepManeuver(const guidance::StepManeuver &maneuver) | |||||||
|     return step_maneuver; |     return step_maneuver; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| util::json::Object makeRouteStep(guidance::RouteStep &&step, | util::json::Object makeRouteStep(guidance::RouteStep &&step, util::json::Value geometry) | ||||||
|                                  util::json::Value geometry) |  | ||||||
| { | { | ||||||
|     util::json::Object route_step; |     util::json::Object route_step; | ||||||
|     route_step.values["distance"] = step.distance; |     route_step.values["distance"] = step.distance; | ||||||
|  | |||||||
| @ -67,10 +67,24 @@ void ScriptingEnvironment::InitLuaState(lua_State *lua_state) | |||||||
|     util::luaAddScriptFolderToLoadPath(lua_state, file_name.c_str()); |     util::luaAddScriptFolderToLoadPath(lua_state, file_name.c_str()); | ||||||
| 
 | 
 | ||||||
|     // Add our function to the state's global scope
 |     // Add our function to the state's global scope
 | ||||||
|     luabind::module(lua_state) |     luabind::module( | ||||||
|         [luabind::def("print", util::LUA_print<std::string>), |         lua_state)[luabind::def("print", util::LUA_print<std::string>), | ||||||
|                    luabind::def("durationIsValid", durationIsValid), |                    luabind::def("durationIsValid", durationIsValid), | ||||||
|                    luabind::def("parseDuration", parseDuration), |                    luabind::def("parseDuration", parseDuration), | ||||||
|  |                    luabind::class_<TravelMode>("mode") | ||||||
|  |                        .enum_("enums")[luabind::value("inaccessible", TRAVEL_MODE_INACCESSIBLE), | ||||||
|  |                                        luabind::value("driving", TRAVEL_MODE_DRIVING), | ||||||
|  |                                        luabind::value("cycling", TRAVEL_MODE_CYCLING), | ||||||
|  |                                        luabind::value("walking", TRAVEL_MODE_WALKING), | ||||||
|  |                                        luabind::value("ferry", TRAVEL_MODE_FERRY), | ||||||
|  |                                        luabind::value("train", TRAVEL_MODE_TRAIN), | ||||||
|  |                                        luabind::value("pushing_bike", TRAVEL_MODE_PUSHING_BIKE), | ||||||
|  |                                        luabind::value("movable_bridge", TRAVEL_MODE_MOVABLE_BRIDGE), | ||||||
|  |                                        luabind::value("steps_up", TRAVEL_MODE_STEPS_UP), | ||||||
|  |                                        luabind::value("steps_down", TRAVEL_MODE_STEPS_DOWN), | ||||||
|  |                                        luabind::value("river_up", TRAVEL_MODE_RIVER_UP), | ||||||
|  |                                        luabind::value("river_down", TRAVEL_MODE_RIVER_DOWN), | ||||||
|  |                                        luabind::value("route", TRAVEL_MODE_ROUTE)], | ||||||
|                    luabind::class_<SourceContainer>("sources") |                    luabind::class_<SourceContainer>("sources") | ||||||
|                        .def(luabind::constructor<>()) |                        .def(luabind::constructor<>()) | ||||||
|                        .def("load", &SourceContainer::loadRasterSource) |                        .def("load", &SourceContainer::loadRasterSource) | ||||||
| @ -79,8 +93,8 @@ void ScriptingEnvironment::InitLuaState(lua_State *lua_state) | |||||||
|                    luabind::class_<const float>("constants") |                    luabind::class_<const float>("constants") | ||||||
|                        .enum_("enums")[luabind::value("precision", COORDINATE_PRECISION)], |                        .enum_("enums")[luabind::value("precision", COORDINATE_PRECISION)], | ||||||
| 
 | 
 | ||||||
|          luabind::class_<std::vector<std::string>>("vector") |                    luabind::class_<std::vector<std::string>>("vector").def( | ||||||
|              .def("Add", static_cast<void (std::vector<std::string>::*)(const std::string &)>( |                        "Add", static_cast<void (std::vector<std::string>::*)(const std::string &)>( | ||||||
|                                   &std::vector<std::string>::push_back)), |                                   &std::vector<std::string>::push_back)), | ||||||
| 
 | 
 | ||||||
|                    luabind::class_<osmium::Location>("Location") |                    luabind::class_<osmium::Location>("Location") | ||||||
| @ -110,9 +124,7 @@ void ScriptingEnvironment::InitLuaState(lua_State *lua_state) | |||||||
|                        .property("forward_mode", &ExtractionWay::get_forward_mode, |                        .property("forward_mode", &ExtractionWay::get_forward_mode, | ||||||
|                                  &ExtractionWay::set_forward_mode) |                                  &ExtractionWay::set_forward_mode) | ||||||
|                        .property("backward_mode", &ExtractionWay::get_backward_mode, |                        .property("backward_mode", &ExtractionWay::get_backward_mode, | ||||||
|                        &ExtractionWay::set_backward_mode) |                                  &ExtractionWay::set_backward_mode), | ||||||
|              .enum_("constants")[luabind::value("notSure", 0), luabind::value("oneway", 1), |  | ||||||
|                                  luabind::value("bidirectional", 2), luabind::value("opposite", 3)], |  | ||||||
|                    luabind::class_<osmium::Way>("Way") |                    luabind::class_<osmium::Way>("Way") | ||||||
|                        .def("get_value_by_key", &osmium::Way::get_value_by_key) |                        .def("get_value_by_key", &osmium::Way::get_value_by_key) | ||||||
|                        .def("get_value_by_key", &get_value_by_key<osmium::Way>) |                        .def("get_value_by_key", &get_value_by_key<osmium::Way>) | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user