more tests passing
This commit is contained in:
+53
-42
@@ -1,4 +1,5 @@
|
||||
require("lib/access")
|
||||
require("lib/maxspeed")
|
||||
|
||||
-- Begin of globals
|
||||
barrier_whitelist = { [""] = true, ["cycle_barrier"] = true, ["bollard"] = true, ["entrance"] = true, ["cattle_grid"] = true, ["border_control"] = true, ["toll_booth"] = true, ["sally_port"] = true, ["gate"] = true, ["no"] = true }
|
||||
@@ -221,115 +222,121 @@ function way_function (way)
|
||||
-- speed
|
||||
if route_speeds[route] then
|
||||
-- ferries (doesn't cover routes tagged using relations)
|
||||
way.mode = mode_ferry
|
||||
way.direction = Way.bidirectional
|
||||
way.ignore_in_grid = true
|
||||
if durationIsValid(duration) then
|
||||
way.duration = math.max( 1, parseDuration(duration) )
|
||||
else
|
||||
way.speed = route_speeds[route]
|
||||
way.backward_speed = route_speeds[route]
|
||||
end
|
||||
elseif railway and platform_speeds[railway] then
|
||||
-- railway platforms (old tagging scheme)
|
||||
way.speed = platform_speeds[railway]
|
||||
way.backward_speed = platform_speeds[railway]
|
||||
elseif platform_speeds[public_transport] then
|
||||
-- public_transport platforms (new tagging platform)
|
||||
way.speed = platform_speeds[public_transport]
|
||||
way.backward_speed = platform_speeds[public_transport]
|
||||
elseif railway and railway_speeds[railway] then
|
||||
way.mode = mode_train
|
||||
-- railways
|
||||
if access and access_tag_whitelist[access] then
|
||||
way.speed = railway_speeds[railway]
|
||||
way.backward_speed = railway_speeds[railway]
|
||||
way.direction = Way.bidirectional
|
||||
end
|
||||
elseif amenity and amenity_speeds[amenity] then
|
||||
-- parking areas
|
||||
way.speed = amenity_speeds[amenity]
|
||||
way.backward_speed = amenity_speeds[amenity]
|
||||
elseif bicycle_speeds[highway] then
|
||||
-- regular ways
|
||||
way.speed = bicycle_speeds[highway]
|
||||
way.backward_speed = bicycle_speeds[highway]
|
||||
elseif access and access_tag_whitelist[access] then
|
||||
-- unknown way, but valid access tag
|
||||
way.speed = default_speed
|
||||
way.backward_speed = default_speed
|
||||
else
|
||||
-- biking not allowed, maybe we can push our bike?
|
||||
-- essentially requires pedestrian profiling, for example foot=no mean we can't push a bike
|
||||
-- TODO: if we can push, the way should be marked as pedestrion mode, but there's no way to do it yet from lua..
|
||||
if foot ~= 'no' then
|
||||
if foot ~= 'no' and junction ~= "roundabout" then
|
||||
if pedestrian_speeds[highway] then
|
||||
-- pedestrian-only ways and areas
|
||||
way.speed = pedestrian_speeds[highway]
|
||||
way.mode = mode_pushing
|
||||
way.backward_mode = mode_pushing
|
||||
elseif man_made and man_made_speeds[man_made] then
|
||||
-- man made structures
|
||||
way.speed = man_made_speeds[man_made]
|
||||
way.mode = mode_pushing
|
||||
way.backward_mode = mode_pushing
|
||||
elseif foot == 'yes' then
|
||||
way.speed = walking_speed
|
||||
way.mode = mode_pushing
|
||||
way.backward_mode = mode_pushing
|
||||
elseif foot_forward == 'yes' then
|
||||
way.speed = walking_speed
|
||||
way.mode = mode_pushing
|
||||
way.backward_mode = 0
|
||||
elseif foot_backward == 'yes' then
|
||||
way.speed = walking_speed
|
||||
way.mode = 0
|
||||
way.backward_mode = mode_pushing
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- direction
|
||||
way.direction = Way.bidirectional
|
||||
local impliedOneway = false
|
||||
if junction == "roundabout" or highway == "motorway_link" or highway == "motorway" then
|
||||
way.direction = Way.oneway
|
||||
impliedOneway = true
|
||||
end
|
||||
|
||||
if onewayClass == "yes" or onewayClass == "1" or onewayClass == "true" then
|
||||
way.direction = Way.oneway
|
||||
way.backward_mode = 0
|
||||
elseif onewayClass == "no" or onewayClass == "0" or onewayClass == "false" then
|
||||
way.direction = Way.bidirectional
|
||||
-- prevent implied oneway
|
||||
elseif onewayClass == "-1" then
|
||||
way.direction = Way.opposite
|
||||
way.mode = 0
|
||||
elseif oneway == "no" or oneway == "0" or oneway == "false" then
|
||||
way.direction = Way.bidirectional
|
||||
-- prevent implied oneway
|
||||
elseif cycleway and string.find(cycleway, "opposite") == 1 then
|
||||
if impliedOneway then
|
||||
way.direction = Way.opposite
|
||||
else
|
||||
way.direction = Way.bidirectional
|
||||
way.mode = 0
|
||||
way.backward_mode = mode_normal
|
||||
end
|
||||
elseif cycleway_left and cycleway_tags[cycleway_left] and cycleway_right and cycleway_tags[cycleway_right] then
|
||||
way.direction = Way.bidirectional
|
||||
-- prevent implied
|
||||
elseif cycleway_left and cycleway_tags[cycleway_left] then
|
||||
if impliedOneway then
|
||||
way.direction = Way.opposite
|
||||
else
|
||||
way.direction = Way.bidirectional
|
||||
way.mode = 0
|
||||
way.backward_mode = mode_normal
|
||||
end
|
||||
elseif cycleway_right and cycleway_tags[cycleway_right] then
|
||||
if impliedOneway then
|
||||
way.direction = Way.oneway
|
||||
else
|
||||
way.direction = Way.bidirectional
|
||||
way.mode = mode_normal
|
||||
way.backward_mode = 0
|
||||
end
|
||||
elseif oneway == "-1" then
|
||||
way.direction = Way.opposite
|
||||
elseif oneway == "yes" or oneway == "1" or oneway == "true" then
|
||||
way.direction = Way.oneway
|
||||
way.mode = 0
|
||||
elseif oneway == "yes" or oneway == "1" or oneway == "true" or impliedOneway then
|
||||
way.backward_mode = 0
|
||||
end
|
||||
|
||||
|
||||
-- pushing bikes
|
||||
if bicycle_speeds[highway] or pedestrian_speeds[highway] then
|
||||
if foot ~= 'no' then
|
||||
if junction ~= "roundabout" then
|
||||
if way.direction == Way.oneway then
|
||||
way.backward_speed = walking_speed
|
||||
way.mode = mode_pushing
|
||||
elseif way.direction == Way.opposite then
|
||||
way.backward_speed = walking_speed
|
||||
way.speed = way.speed
|
||||
way.mode = mode_pushing
|
||||
end
|
||||
if foot ~= "no" and junction ~= "roundabout" then
|
||||
if way.backward_mode == 0 then
|
||||
way.backward_speed = walking_speed
|
||||
way.backward_mode = mode_pushing
|
||||
elseif way.mode == 0 then
|
||||
way.speed = walking_speed
|
||||
way.mode = mode_pushing
|
||||
end
|
||||
end
|
||||
if way.backward_speed == way.speed then
|
||||
-- TODO: no way yet to mark a way as pedestrian mode if forward/backward speeds are equal
|
||||
way.direction = Way.bidirectional
|
||||
end
|
||||
end
|
||||
|
||||
-- cycleways
|
||||
@@ -341,6 +348,14 @@ function way_function (way)
|
||||
way.speed = bicycle_speeds["cycleway"]
|
||||
end
|
||||
|
||||
-- dismount
|
||||
if bicycle == "dismount" then
|
||||
way.mode = mode_pushing
|
||||
way.backward_mode = mode_pushing
|
||||
way.speed = walking_speed
|
||||
way.backward_speed = walking_speed
|
||||
end
|
||||
|
||||
-- surfaces
|
||||
if surface then
|
||||
surface_speed = surface_speeds[surface]
|
||||
@@ -355,12 +370,8 @@ function way_function (way)
|
||||
end
|
||||
|
||||
-- maxspeed
|
||||
-- TODO: maxspeed of backward direction
|
||||
if take_minimum_of_speeds then
|
||||
if maxspeed and maxspeed>0 then
|
||||
way.speed = math.min(way.speed, maxspeed)
|
||||
end
|
||||
end
|
||||
MaxSpeed.limit( way, maxspeed, maxspeed_forward, maxspeed_backward )
|
||||
|
||||
|
||||
-- Override speed settings if explicit forward/backward maxspeeds are given
|
||||
if way.speed > 0 and maxspeed_forward ~= nil and maxspeed_forward > 0 then
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
local math = math
|
||||
|
||||
module "MaxSpeed"
|
||||
|
||||
function limit(way,max,maxf,maxb)
|
||||
if maxf and maxf>0 then
|
||||
way.speed = math.min(way.speed, maxf)
|
||||
elseif max and max>0 then
|
||||
way.speed = math.min(way.speed, max)
|
||||
end
|
||||
|
||||
if maxb and maxb>0 then
|
||||
way.backward_speed = math.min(way.backward_speed, maxb)
|
||||
elseif max and max>0 then
|
||||
way.backward_speed = math.min(way.backward_speed, max)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user