In lua, replace access to speed by functions

This commit is contained in:
Frédéric Rodrigo 2018-07-17 16:56:09 +02:00
parent f928956584
commit e313429d11
3 changed files with 71 additions and 60 deletions

View File

@ -10,6 +10,7 @@ find_access_tag = require("lib/access").find_access_tag
limit = require("lib/maxspeed").limit
Utils = require("lib/utils")
Measure = require("lib/measure")
Tags = require('lib/tags')
function setup()
return {
@ -30,11 +31,11 @@ function setup()
},
default_mode = mode.driving,
default_speed = 10,
default_speed = function(way) return 10 end,
oneway_handling = true,
side_road_multiplier = 0.8,
turn_penalty = 7.5,
speed_reduction = 0.8,
speed_reduction = function(way, speed) return speed * 0.8 end,
turn_bias = 1.075,
cardinal_directions = false,
@ -136,7 +137,8 @@ function setup()
'proposed'
},
speeds = Sequence {
speeds = function(way)
local s = Sequence {
highway = {
motorway = 90,
motorway_link = 45,
@ -153,7 +155,10 @@ function setup()
living_street = 10,
service = 15
}
},
}
return Tags.get_constant_by_key_value(way, s)
end,
service_penalties = {
alley = 0.5,

View File

@ -6,6 +6,7 @@ Set = require('lib/set')
Sequence = require('lib/sequence')
Handlers = require("lib/way_handlers")
find_access_tag = require("lib/access").find_access_tag
Tags = require('lib/tags')
function setup()
local walking_speed = 5
@ -21,7 +22,7 @@ function setup()
},
default_mode = mode.walking,
default_speed = walking_speed,
default_speed = function(way) return walking_speed end,
oneway_handling = 'specific', -- respect 'oneway:foot' but not 'oneway'
barrier_blacklist = Set {
@ -72,7 +73,8 @@ function setup()
'impassable'
},
speeds = Sequence {
speeds = function(way)
local s = Sequence {
highway = {
primary = walking_speed,
primary_link = walking_speed,
@ -109,7 +111,11 @@ function setup()
leisure = {
track = walking_speed
}
},
}
print(way:id(), Tags.get_constant_by_key_value(way, s))
return Tags.get_constant_by_key_value(way, s)
end,
route_speeds = {
ferry = 5

View File

@ -274,7 +274,7 @@ function WayHandlers.speed(profile,way,result,data)
return -- abort if already set, eg. by a route
end
local key,value,speed = Tags.get_constant_by_key_value(way,profile.speeds)
local key,value,speed = profile.speeds(way)
if speed then
-- set speed by way type
@ -283,17 +283,17 @@ function WayHandlers.speed(profile,way,result,data)
else
-- Set the avg speed on ways that are marked accessible
if profile.access_tag_whitelist[data.forward_access] then
result.forward_speed = profile.default_speed
result.forward_speed = profile.default_speed(way)
elseif data.forward_access and not profile.access_tag_blacklist[data.forward_access] then
result.forward_speed = profile.default_speed -- fallback to the avg speed if access tag is not blacklisted
result.forward_speed = profile.default_speed(way) -- fallback to the avg speed if access tag is not blacklisted
elseif not data.forward_access and data.backward_access then
result.forward_mode = mode.inaccessible
end
if profile.access_tag_whitelist[data.backward_access] then
result.backward_speed = profile.default_speed
result.backward_speed = profile.default_speed(way)
elseif data.backward_access and not profile.access_tag_blacklist[data.backward_access] then
result.backward_speed = profile.default_speed -- fallback to the avg speed if access tag is not blacklisted
result.backward_speed = profile.default_speed(way) -- fallback to the avg speed if access tag is not blacklisted
elseif not data.backward_access and data.forward_access then
result.backward_mode = mode.inaccessible
end
@ -438,11 +438,11 @@ function WayHandlers.maxspeed(profile,way,result,data)
backward = WayHandlers.parse_maxspeed(backward,profile)
if forward and forward > 0 then
result.forward_speed = forward * profile.speed_reduction
result.forward_speed = profile.speed_reduction(way, forward)
end
if backward and backward > 0 then
result.backward_speed = backward * profile.speed_reduction
result.backward_speed = profile.speed_reduction(way, backward)
end
end