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_access_restricted = false; | ||||
|         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; | ||||
|             backward_travel_mode = TRAVEL_MODE_DEFAULT; | ||||
|         } | ||||
|         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; | ||||
|         } | ||||
|         forward_travel_mode = TRAVEL_MODE_INACCESSIBLE; | ||||
|         backward_travel_mode = TRAVEL_MODE_INACCESSIBLE; | ||||
|     } | ||||
| 
 | ||||
|     // 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_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 */ | ||||
|  | ||||
| @ -105,13 +105,6 @@ local safety_penalty            = 1.0 | ||||
| local use_public_transport      = 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) | ||||
|     if not source then | ||||
|         return 0 | ||||
| @ -191,6 +184,9 @@ function way_function (way, result) | ||||
|     return | ||||
|   end | ||||
| 
 | ||||
|   result.forward_mode = mode.cycling | ||||
|   result.backward_mode = mode.cycling | ||||
| 
 | ||||
|   -- other tags | ||||
|   local name = way:get_value_by_key("name") | ||||
|   local ref = way:get_value_by_key("ref") | ||||
| @ -237,14 +233,14 @@ function way_function (way, result) | ||||
|     if duration and durationIsValid(duration) then | ||||
|       result.duration = math.max( parseDuration(duration), 1 ) | ||||
|     end | ||||
|     result.forward_mode = mode_movable_bridge | ||||
|     result.backward_mode = mode_movable_bridge | ||||
|     result.forward_mode = mode.movable_bridge | ||||
|     result.backward_mode = mode.movable_bridge | ||||
|     result.forward_speed = bridge_speed | ||||
|     result.backward_speed = bridge_speed | ||||
|   elseif route_speeds[route] then | ||||
|     -- ferries (doesn't cover routes tagged using relations) | ||||
|     result.forward_mode = mode_ferry | ||||
|     result.backward_mode = mode_ferry | ||||
|     result.forward_mode = mode.ferry | ||||
|     result.backward_mode = mode.ferry | ||||
|     result.ignore_in_grid = true | ||||
|     if duration and durationIsValid(duration) then | ||||
|       result.duration = math.max( 1, parseDuration(duration) ) | ||||
| @ -262,8 +258,8 @@ function way_function (way, result) | ||||
|     result.forward_speed = platform_speeds[public_transport] | ||||
|     result.backward_speed = platform_speeds[public_transport] | ||||
|   elseif use_public_transport and railway and railway_speeds[railway] then | ||||
|       result.forward_mode = mode_train | ||||
|       result.backward_mode = mode_train | ||||
|       result.forward_mode = mode.train | ||||
|       result.backward_mode = mode.train | ||||
|      -- railways | ||||
|     if access and access_tag_whitelist[access] then | ||||
|       result.forward_speed = railway_speeds[railway] | ||||
| @ -293,27 +289,27 @@ function way_function (way, result) | ||||
|         -- pedestrian-only ways and areas | ||||
|         result.forward_speed = pedestrian_speeds[highway] | ||||
|         result.backward_speed = pedestrian_speeds[highway] | ||||
|         result.forward_mode = mode_pushing | ||||
|         result.backward_mode = mode_pushing | ||||
|         result.forward_mode = mode.pushing_bike | ||||
|         result.backward_mode = mode.pushing_bike | ||||
|       elseif man_made and man_made_speeds[man_made] then | ||||
|         -- man made structures | ||||
|         result.forward_speed = man_made_speeds[man_made] | ||||
|         result.backward_speed = man_made_speeds[man_made] | ||||
|         result.forward_mode = mode_pushing | ||||
|         result.backward_mode = mode_pushing | ||||
|         result.forward_mode = mode.pushing_bike | ||||
|         result.backward_mode = mode.pushing_bike | ||||
|       elseif foot == 'yes' then | ||||
|         result.forward_speed = walking_speed | ||||
|         result.backward_speed = walking_speed | ||||
|         result.forward_mode = mode_pushing | ||||
|         result.backward_mode = mode_pushing | ||||
|         result.forward_mode = mode.pushing_bike | ||||
|         result.backward_mode = mode.pushing_bike | ||||
|       elseif foot_forward == 'yes' then | ||||
|         result.forward_speed = walking_speed | ||||
|         result.forward_mode = mode_pushing | ||||
|         result.backward_mode = 0 | ||||
|         result.forward_mode = mode.pushing_bike | ||||
|         result.backward_mode = mode.inaccessible | ||||
|       elseif foot_backward == 'yes' then | ||||
|         result.forward_speed = walking_speed | ||||
|         result.forward_mode = 0 | ||||
|         result.backward_mode = mode_pushing | ||||
|         result.forward_mode = mode.inaccessible | ||||
|         result.backward_mode = mode.pushing_bike | ||||
|       end | ||||
|     end | ||||
|   end | ||||
| @ -325,48 +321,48 @@ function way_function (way, result) | ||||
|   end | ||||
| 
 | ||||
|   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 | ||||
|     -- prevent implied oneway | ||||
|   elseif onewayClass == "-1" then | ||||
|     result.forward_mode = 0 | ||||
|     result.forward_mode = mode.inaccessible | ||||
|   elseif oneway == "no" or oneway == "0" or oneway == "false" then | ||||
|     -- prevent implied oneway | ||||
|   elseif cycleway and string.find(cycleway, "opposite") == 1 then | ||||
|     if impliedOneway then | ||||
|       result.forward_mode = 0 | ||||
|       result.backward_mode = mode_normal | ||||
|       result.forward_mode = mode.inaccessible | ||||
|       result.backward_mode = mode.cycling | ||||
|       result.backward_speed = bicycle_speeds["cycleway"] | ||||
|     end | ||||
|   elseif cycleway_left and cycleway_tags[cycleway_left] and cycleway_right and cycleway_tags[cycleway_right] then | ||||
|     -- prevent implied | ||||
|   elseif cycleway_left and cycleway_tags[cycleway_left] then | ||||
|     if impliedOneway then | ||||
|       result.forward_mode = 0 | ||||
|       result.backward_mode = mode_normal | ||||
|       result.forward_mode = mode.inaccessible | ||||
|       result.backward_mode = mode.cycling | ||||
|       result.backward_speed = bicycle_speeds["cycleway"] | ||||
|     end | ||||
|   elseif cycleway_right and cycleway_tags[cycleway_right] then | ||||
|     if impliedOneway then | ||||
|       result.forward_mode = mode_normal | ||||
|       result.forward_mode = mode.cycling | ||||
|       result.backward_speed = bicycle_speeds["cycleway"] | ||||
|       result.backward_mode = 0 | ||||
|       result.backward_mode = mode.cycling | ||||
|     end | ||||
|   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 | ||||
|     result.backward_mode = 0 | ||||
|     result.backward_mode = mode.inaccessible | ||||
|   end | ||||
| 
 | ||||
|   -- pushing bikes | ||||
|   if bicycle_speeds[highway] or pedestrian_speeds[highway] 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_mode = mode_pushing | ||||
|       elseif result.forward_mode == 0 then | ||||
|         result.backward_mode = mode.pushing_bike | ||||
|       elseif result.forward_mode == mode.inaccessible then | ||||
|         result.forward_speed = walking_speed | ||||
|         result.forward_mode = mode_pushing | ||||
|         result.forward_mode = mode.pushing_bike | ||||
|       end | ||||
|     end | ||||
|   end | ||||
| @ -382,8 +378,8 @@ function way_function (way, result) | ||||
| 
 | ||||
|   -- dismount | ||||
|   if bicycle == "dismount" then | ||||
|     result.forward_mode = mode_pushing | ||||
|     result.backward_mode = mode_pushing | ||||
|     result.forward_mode = mode.pushing_bike | ||||
|     result.backward_mode = mode.pushing_bike | ||||
|     result.forward_speed = walking_speed | ||||
|     result.backward_speed = walking_speed | ||||
|   end | ||||
|  | ||||
| @ -149,11 +149,6 @@ local max = math.max | ||||
| 
 | ||||
| local speed_reduction = 0.8 | ||||
| 
 | ||||
| --modes | ||||
| local mode_normal = 1 | ||||
| local mode_ferry = 2 | ||||
| local mode_movable_bridge = 3 | ||||
| 
 | ||||
| function get_exceptions(vector) | ||||
|   for i,v in ipairs(restriction_exception_tags) do | ||||
|     vector:Add(v) | ||||
| @ -248,6 +243,9 @@ function way_function (way, result) | ||||
|     return | ||||
|   end | ||||
| 
 | ||||
|   result.forward_mode = mode.driving | ||||
|   result.backward_mode = mode.driving | ||||
| 
 | ||||
|   -- handling ferries and piers | ||||
|   local route_speed = speed_profile[route] | ||||
|   if (route_speed and route_speed > 0) then | ||||
| @ -256,8 +254,8 @@ function way_function (way, result) | ||||
|     if duration and durationIsValid(duration) then | ||||
|       result.duration = max( parseDuration(duration), 1 ) | ||||
|     end | ||||
|     result.forward_mode = mode_ferry | ||||
|     result.backward_mode = mode_ferry | ||||
|     result.forward_mode = mode.ferry | ||||
|     result.backward_mode = mode.ferry | ||||
|     result.forward_speed = route_speed | ||||
|     result.backward_speed = route_speed | ||||
|   end | ||||
| @ -271,8 +269,8 @@ function way_function (way, result) | ||||
|     if duration and durationIsValid(duration) then | ||||
|       result.duration = max( parseDuration(duration), 1 ) | ||||
|     end | ||||
|     result.forward_mode = mode_movable_bridge | ||||
|     result.backward_mode = mode_movable_bridge | ||||
|     result.forward_mode = mode.movable_bridge | ||||
|     result.backward_mode = mode.movable_bridge | ||||
|     result.forward_speed = bridge_speed | ||||
|     result.backward_speed = bridge_speed | ||||
|   end | ||||
| @ -378,14 +376,14 @@ function way_function (way, result) | ||||
|   -- Set direction according to tags on way | ||||
|   if obey_oneway then | ||||
|     if oneway == "-1" then | ||||
|       result.forward_mode = 0 | ||||
|       result.forward_mode = mode.inaccessible | ||||
|     elseif oneway == "yes" or | ||||
|     oneway == "1" or | ||||
|     oneway == "true" or | ||||
|     junction == "roundabout" or | ||||
|     (highway == "motorway_link" and oneway ~="no") or | ||||
|     (highway == "motorway" and oneway ~= "no") then | ||||
|       result.backward_mode = 0 | ||||
|       result.backward_mode = mode.inaccessible | ||||
|     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_backward = parse_maxspeed(way:get_value_by_key("maxspeed:backward")) | ||||
|   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 | ||||
|     end | ||||
|     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")) | ||||
|   -- apply bi-directional advisory speed first | ||||
|   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 | ||||
|     end | ||||
|     if 0 ~= result.backward_mode then | ||||
|     if mode.inaccessible ~= result.backward_mode then | ||||
|       result.backward_speed = advisory_speed | ||||
|     end | ||||
|   end | ||||
|   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 | ||||
|     end | ||||
|     result.forward_speed = advisory_forward | ||||
| @ -439,7 +437,7 @@ function way_function (way, result) | ||||
|     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 | ||||
|   if result.forward_speed > 0 then | ||||
| @ -461,7 +459,7 @@ function way_function (way, result) | ||||
|   end | ||||
| 
 | ||||
|   -- 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 | ||||
| 
 | ||||
| function turn_function (angle) | ||||
|  | ||||
| @ -69,10 +69,6 @@ u_turn_penalty           = 2 | ||||
| use_turn_restrictions    = false | ||||
| local fallback_names     = true | ||||
| 
 | ||||
| --modes | ||||
| local mode_normal = 1 | ||||
| local mode_ferry = 2 | ||||
| 
 | ||||
| function get_exceptions(vector) | ||||
|   for i,v in ipairs(restriction_exception_tags) do | ||||
|     vector:Add(v) | ||||
| @ -138,6 +134,9 @@ function way_function (way, result) | ||||
|     return | ||||
|   end | ||||
| 
 | ||||
|   result.forward_mode = mode.walking | ||||
|   result.backward_mode = mode.walking | ||||
| 
 | ||||
|   local name = way:get_value_by_key("name") | ||||
|   local ref = way:get_value_by_key("ref") | ||||
|   local junction = way:get_value_by_key("junction") | ||||
| @ -175,8 +174,8 @@ function way_function (way, result) | ||||
|     result.forward_speed = route_speeds[route] | ||||
|     result.backward_speed = route_speeds[route] | ||||
|   end | ||||
|     result.forward_mode = mode_ferry | ||||
|     result.backward_mode = mode_ferry | ||||
|     result.forward_mode = mode.ferry | ||||
|     result.backward_mode = mode.ferry | ||||
|   elseif railway and platform_speeds[railway] then | ||||
|     -- railway platforms (old tagging scheme) | ||||
|     result.forward_speed = platform_speeds[railway] | ||||
| @ -205,11 +204,11 @@ function way_function (way, result) | ||||
| 
 | ||||
|   -- oneway | ||||
|   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 | ||||
|     -- nothing to do | ||||
|   elseif onewayClass == "-1" then | ||||
|     result.forward_mode = 0 | ||||
|     result.forward_mode = mode.inaccessible | ||||
|   end | ||||
| 
 | ||||
|   -- surfaces | ||||
|  | ||||
| @ -6,14 +6,6 @@ | ||||
| -- Secondary road:  18km/h = 18000m/3600s = 100m/20s | ||||
| -- 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 = { | ||||
|   ["primary"] = 36, | ||||
|   ["secondary"] = 18, | ||||
| @ -68,24 +60,26 @@ function way_function (way, result) | ||||
|   if name then | ||||
|     result.name = name | ||||
|   end | ||||
|   result.forward_mode = mode.driving | ||||
|   result.backward_mode = mode.driving | ||||
| 
 | ||||
|   if duration and durationIsValid(duration) then | ||||
|     result.duration = math.max( 1, parseDuration(duration) ) | ||||
|     result.forward_mode = 2 | ||||
|     result.backward_mode = 2 | ||||
|     result.forward_mode = mode.route | ||||
|     result.backward_mode = mode.route | ||||
|   else | ||||
|     local speed_forw = speed_profile[highway] or speed_profile['default'] | ||||
|     local speed_back = speed_forw | ||||
| 
 | ||||
|     if highway == "river" then | ||||
|       local temp_speed = speed_forw | ||||
|       result.forward_mode = 3 | ||||
|       result.backward_mode = 4 | ||||
|       result.forward_mode = mode.river_up | ||||
|       result.backward_mode = mode.river_down | ||||
|       speed_forw = temp_speed*1.5 | ||||
|       speed_back = temp_speed/1.5 | ||||
|     elseif highway == "steps" then | ||||
|       result.forward_mode = 5 | ||||
|       result.backward_mode = 6 | ||||
|       result.forward_mode = mode.steps_up | ||||
|       result.backward_mode = mode.steps_down | ||||
|     end | ||||
| 
 | ||||
|     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 | ||||
|     -- nothing to do | ||||
|   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 | ||||
|     result.backward_mode = 0 | ||||
|     result.backward_mode = mode.inaccessible | ||||
|   end | ||||
| 
 | ||||
|   if junction == 'roundabout' then | ||||
|  | ||||
| @ -107,12 +107,45 @@ std::string modeToString(const extractor::TravelMode mode) | ||||
|     std::string token; | ||||
|     switch (mode) | ||||
|     { | ||||
|     case TRAVEL_MODE_DEFAULT: | ||||
|         token = "default"; | ||||
|         break; | ||||
|     case TRAVEL_MODE_INACCESSIBLE: | ||||
|         token = "inaccessible"; | ||||
|         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: | ||||
|         token = "other"; | ||||
|         break; | ||||
| @ -132,8 +165,7 @@ util::json::Object makeStepManeuver(const guidance::StepManeuver &maneuver) | ||||
|     return step_maneuver; | ||||
| } | ||||
| 
 | ||||
| util::json::Object makeRouteStep(guidance::RouteStep &&step, | ||||
|                                  util::json::Value geometry) | ||||
| util::json::Object makeRouteStep(guidance::RouteStep &&step, util::json::Value geometry) | ||||
| { | ||||
|     util::json::Object route_step; | ||||
|     route_step.values["distance"] = step.distance; | ||||
|  | ||||
| @ -67,70 +67,82 @@ void ScriptingEnvironment::InitLuaState(lua_State *lua_state) | ||||
|     util::luaAddScriptFolderToLoadPath(lua_state, file_name.c_str()); | ||||
| 
 | ||||
|     // Add our function to the state's global scope
 | ||||
|     luabind::module(lua_state) | ||||
|         [luabind::def("print", util::LUA_print<std::string>), | ||||
|          luabind::def("durationIsValid", durationIsValid), | ||||
|          luabind::def("parseDuration", parseDuration), | ||||
|          luabind::class_<SourceContainer>("sources") | ||||
|              .def(luabind::constructor<>()) | ||||
|              .def("load", &SourceContainer::loadRasterSource) | ||||
|              .def("query", &SourceContainer::getRasterDataFromSource) | ||||
|              .def("interpolate", &SourceContainer::getRasterInterpolateFromSource), | ||||
|          luabind::class_<const float>("constants") | ||||
|              .enum_("enums")[luabind::value("precision", COORDINATE_PRECISION)], | ||||
|     luabind::module( | ||||
|         lua_state)[luabind::def("print", util::LUA_print<std::string>), | ||||
|                    luabind::def("durationIsValid", durationIsValid), | ||||
|                    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") | ||||
|                        .def(luabind::constructor<>()) | ||||
|                        .def("load", &SourceContainer::loadRasterSource) | ||||
|                        .def("query", &SourceContainer::getRasterDataFromSource) | ||||
|                        .def("interpolate", &SourceContainer::getRasterInterpolateFromSource), | ||||
|                    luabind::class_<const float>("constants") | ||||
|                        .enum_("enums")[luabind::value("precision", COORDINATE_PRECISION)], | ||||
| 
 | ||||
|          luabind::class_<std::vector<std::string>>("vector") | ||||
|              .def("Add", static_cast<void (std::vector<std::string>::*)(const std::string &)>( | ||||
|                              &std::vector<std::string>::push_back)), | ||||
|                    luabind::class_<std::vector<std::string>>("vector").def( | ||||
|                        "Add", static_cast<void (std::vector<std::string>::*)(const std::string &)>( | ||||
|                                   &std::vector<std::string>::push_back)), | ||||
| 
 | ||||
|          luabind::class_<osmium::Location>("Location") | ||||
|              .def<location_member_ptr_type>("lat", &osmium::Location::lat) | ||||
|              .def<location_member_ptr_type>("lon", &osmium::Location::lon), | ||||
|                    luabind::class_<osmium::Location>("Location") | ||||
|                        .def<location_member_ptr_type>("lat", &osmium::Location::lat) | ||||
|                        .def<location_member_ptr_type>("lon", &osmium::Location::lon), | ||||
| 
 | ||||
|          luabind::class_<osmium::Node>("Node") | ||||
|              // .def<node_member_ptr_type>("tags", &osmium::Node::tags)
 | ||||
|              .def("location", &osmium::Node::location) | ||||
|              .def("get_value_by_key", &osmium::Node::get_value_by_key) | ||||
|              .def("get_value_by_key", &get_value_by_key<osmium::Node>) | ||||
|              .def("id", &osmium::Node::id), | ||||
|                    luabind::class_<osmium::Node>("Node") | ||||
|                        // .def<node_member_ptr_type>("tags", &osmium::Node::tags)
 | ||||
|                        .def("location", &osmium::Node::location) | ||||
|                        .def("get_value_by_key", &osmium::Node::get_value_by_key) | ||||
|                        .def("get_value_by_key", &get_value_by_key<osmium::Node>) | ||||
|                        .def("id", &osmium::Node::id), | ||||
| 
 | ||||
|          luabind::class_<ExtractionNode>("ResultNode") | ||||
|              .def_readwrite("traffic_lights", &ExtractionNode::traffic_lights) | ||||
|              .def_readwrite("barrier", &ExtractionNode::barrier), | ||||
|                    luabind::class_<ExtractionNode>("ResultNode") | ||||
|                        .def_readwrite("traffic_lights", &ExtractionNode::traffic_lights) | ||||
|                        .def_readwrite("barrier", &ExtractionNode::barrier), | ||||
| 
 | ||||
|          luabind::class_<ExtractionWay>("ResultWay") | ||||
|              // .def(luabind::constructor<>())
 | ||||
|              .def_readwrite("forward_speed", &ExtractionWay::forward_speed) | ||||
|              .def_readwrite("backward_speed", &ExtractionWay::backward_speed) | ||||
|              .def_readwrite("name", &ExtractionWay::name) | ||||
|              .def_readwrite("roundabout", &ExtractionWay::roundabout) | ||||
|              .def_readwrite("is_access_restricted", &ExtractionWay::is_access_restricted) | ||||
|              .def_readwrite("is_startpoint", &ExtractionWay::is_startpoint) | ||||
|              .def_readwrite("duration", &ExtractionWay::duration) | ||||
|              .property("forward_mode", &ExtractionWay::get_forward_mode, | ||||
|                        &ExtractionWay::set_forward_mode) | ||||
|              .property("backward_mode", &ExtractionWay::get_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") | ||||
|              .def("get_value_by_key", &osmium::Way::get_value_by_key) | ||||
|              .def("get_value_by_key", &get_value_by_key<osmium::Way>) | ||||
|              .def("id", &osmium::Way::id), | ||||
|          luabind::class_<InternalExtractorEdge>("EdgeSource") | ||||
|              .def_readonly("source_coordinate", &InternalExtractorEdge::source_coordinate) | ||||
|              .def_readwrite("weight_data", &InternalExtractorEdge::weight_data), | ||||
|          luabind::class_<InternalExtractorEdge::WeightData>("WeightData") | ||||
|              .def_readwrite("speed", &InternalExtractorEdge::WeightData::speed), | ||||
|          luabind::class_<ExternalMemoryNode>("EdgeTarget") | ||||
|              .property("lon", &lonToDouble<ExternalMemoryNode>) | ||||
|              .property("lat", &latToDouble<ExternalMemoryNode>), | ||||
|          luabind::class_<util::Coordinate>("Coordinate") | ||||
|              .property("lon", &lonToDouble<util::Coordinate>) | ||||
|              .property("lat", &latToDouble<util::Coordinate>), | ||||
|          luabind::class_<RasterDatum>("RasterDatum") | ||||
|              .def_readonly("datum", &RasterDatum::datum) | ||||
|              .def("invalid_data", &RasterDatum::get_invalid)]; | ||||
|                    luabind::class_<ExtractionWay>("ResultWay") | ||||
|                        // .def(luabind::constructor<>())
 | ||||
|                        .def_readwrite("forward_speed", &ExtractionWay::forward_speed) | ||||
|                        .def_readwrite("backward_speed", &ExtractionWay::backward_speed) | ||||
|                        .def_readwrite("name", &ExtractionWay::name) | ||||
|                        .def_readwrite("roundabout", &ExtractionWay::roundabout) | ||||
|                        .def_readwrite("is_access_restricted", &ExtractionWay::is_access_restricted) | ||||
|                        .def_readwrite("is_startpoint", &ExtractionWay::is_startpoint) | ||||
|                        .def_readwrite("duration", &ExtractionWay::duration) | ||||
|                        .property("forward_mode", &ExtractionWay::get_forward_mode, | ||||
|                                  &ExtractionWay::set_forward_mode) | ||||
|                        .property("backward_mode", &ExtractionWay::get_backward_mode, | ||||
|                                  &ExtractionWay::set_backward_mode), | ||||
|                    luabind::class_<osmium::Way>("Way") | ||||
|                        .def("get_value_by_key", &osmium::Way::get_value_by_key) | ||||
|                        .def("get_value_by_key", &get_value_by_key<osmium::Way>) | ||||
|                        .def("id", &osmium::Way::id), | ||||
|                    luabind::class_<InternalExtractorEdge>("EdgeSource") | ||||
|                        .def_readonly("source_coordinate", &InternalExtractorEdge::source_coordinate) | ||||
|                        .def_readwrite("weight_data", &InternalExtractorEdge::weight_data), | ||||
|                    luabind::class_<InternalExtractorEdge::WeightData>("WeightData") | ||||
|                        .def_readwrite("speed", &InternalExtractorEdge::WeightData::speed), | ||||
|                    luabind::class_<ExternalMemoryNode>("EdgeTarget") | ||||
|                        .property("lon", &lonToDouble<ExternalMemoryNode>) | ||||
|                        .property("lat", &latToDouble<ExternalMemoryNode>), | ||||
|                    luabind::class_<util::Coordinate>("Coordinate") | ||||
|                        .property("lon", &lonToDouble<util::Coordinate>) | ||||
|                        .property("lat", &latToDouble<util::Coordinate>), | ||||
|                    luabind::class_<RasterDatum>("RasterDatum") | ||||
|                        .def_readonly("datum", &RasterDatum::datum) | ||||
|                        .def("invalid_data", &RasterDatum::get_invalid)]; | ||||
| 
 | ||||
|     if (0 != luaL_dofile(lua_state, file_name.c_str())) | ||||
|     { | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user