lua: eliminate TagCache.set_tag()
This commit is contained in:
parent
50090e6447
commit
c3aeef4e09
@ -236,8 +236,10 @@ function node_function (node, result)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- abort early if this way is obviouslt not routable
|
-- abort early if this way is obviouslt not routable
|
||||||
function handle_initial_check(way,result,cache)
|
function handle_initial_check(way,result,cache,data)
|
||||||
return TagCache.get(way,cache,'highway') ~= nil or
|
data.speed_type = TagCache.get(way,cache,'highway')
|
||||||
|
|
||||||
|
return data.speed_type ~= nil or
|
||||||
TagCache.get(way,cache,'route') ~= nil or
|
TagCache.get(way,cache,'route') ~= nil or
|
||||||
TagCache.get(way,cache,'bridge') ~= nil
|
TagCache.get(way,cache,'bridge') ~= nil
|
||||||
end
|
end
|
||||||
@ -371,7 +373,6 @@ function handle_ferries(way,result,cache)
|
|||||||
local route = TagCache.get(way,cache,"route")
|
local route = TagCache.get(way,cache,"route")
|
||||||
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
|
||||||
TagCache.set(cache,"highway",route)
|
|
||||||
local duration = TagCache.get(way,cache,"duration")
|
local duration = TagCache.get(way,cache,"duration")
|
||||||
if duration and durationIsValid(duration) then
|
if duration and durationIsValid(duration) then
|
||||||
result.duration = max( parseDuration(duration), 1 )
|
result.duration = max( parseDuration(duration), 1 )
|
||||||
@ -389,7 +390,6 @@ function handle_movables(way,result,cache)
|
|||||||
local bridge_speed = speed_profile[bridge]
|
local bridge_speed = speed_profile[bridge]
|
||||||
local capacity_car = TagCache.get(way,cache,"capacity:car")
|
local capacity_car = TagCache.get(way,cache,"capacity:car")
|
||||||
if (bridge_speed and bridge_speed > 0) and (capacity_car ~= 0) then
|
if (bridge_speed and bridge_speed > 0) and (capacity_car ~= 0) then
|
||||||
TagCache.set(cache,"highway",bridge)
|
|
||||||
local duration = TagCache.get(way,cache,"duration")
|
local duration = TagCache.get(way,cache,"duration")
|
||||||
if duration and durationIsValid(duration) then
|
if duration and durationIsValid(duration) then
|
||||||
result.duration = max( parseDuration(duration), 1 )
|
result.duration = max( parseDuration(duration), 1 )
|
||||||
@ -690,7 +690,7 @@ function way_function(way, result)
|
|||||||
-- most steps can abort processing, meaning the way
|
-- most steps can abort processing, meaning the way
|
||||||
-- is not routable
|
-- is not routable
|
||||||
|
|
||||||
if handle_initial_check(way,result,cache) == false then return end
|
if handle_initial_check(way,result,cache,data) == false then return end
|
||||||
if handle_default_mode(way,result,cache) == false then return end
|
if handle_default_mode(way,result,cache) == false then return end
|
||||||
if handle_blocking(way,result,cache) == false then return end
|
if handle_blocking(way,result,cache) == false then return end
|
||||||
if handle_access(way,result,cache,data) == false then return end
|
if handle_access(way,result,cache,data) == false then return end
|
||||||
|
@ -24,12 +24,4 @@ function TagCache.get(way,cache,key)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function TagCache.set(cache,key,value)
|
|
||||||
if value then
|
|
||||||
cache[key] = value
|
|
||||||
else
|
|
||||||
cache[key] = ''
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return TagCache
|
return TagCache
|
97
profiles/test.lua
Normal file
97
profiles/test.lua
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
-- Enable calling our lua profile code directly from the lua command line,
|
||||||
|
-- which makes it easier to debug.
|
||||||
|
-- We simulate the normal C++ environment by defining the required globals and functions.
|
||||||
|
|
||||||
|
-- Usage:
|
||||||
|
-- > cd profiles
|
||||||
|
-- > lua5.1 debug.lua
|
||||||
|
|
||||||
|
|
||||||
|
-- for more convenient printing of tables
|
||||||
|
local pprint = require('lib/pprint')
|
||||||
|
|
||||||
|
-- globals that are normally set from C++
|
||||||
|
|
||||||
|
-- profiles code modifies this table
|
||||||
|
properties = {}
|
||||||
|
|
||||||
|
-- should match values defined in include/extractor/guidance/road_classification.hpp
|
||||||
|
road_priority_class = {
|
||||||
|
motorway = 0,
|
||||||
|
trunk = 2,
|
||||||
|
primary = 4,
|
||||||
|
secondary = 6,
|
||||||
|
tertiary = 8,
|
||||||
|
main_residential = 10,
|
||||||
|
side_residential = 11,
|
||||||
|
link_road = 14,
|
||||||
|
bike_path = 16,
|
||||||
|
foot_path = 18,
|
||||||
|
connectivity = 31,
|
||||||
|
}
|
||||||
|
|
||||||
|
-- should match values defined in include/extractor/travel_mode.hpp
|
||||||
|
mode = {
|
||||||
|
inaccessible = 0,
|
||||||
|
driving = 1,
|
||||||
|
cycling = 2,
|
||||||
|
walking = 3,
|
||||||
|
ferry = 4,
|
||||||
|
train = 5,
|
||||||
|
pushing_bike = 6,
|
||||||
|
}
|
||||||
|
|
||||||
|
-- input tags, normally extracted from OSM data
|
||||||
|
local way = {
|
||||||
|
highway = 'primary',
|
||||||
|
name = 'Main Street',
|
||||||
|
--width = '3',
|
||||||
|
--maxspeed = '30',
|
||||||
|
--['maxspeed:advisory'] = '25',
|
||||||
|
--oneway = '-1',
|
||||||
|
--service = 'alley',
|
||||||
|
--['oneway:bicycle'] = 'yes',
|
||||||
|
--junction = 'roundabout',
|
||||||
|
--['name:pronunciation'] = 'fuerloong',
|
||||||
|
--route = 'ferry',
|
||||||
|
--duration = '00:01:00',
|
||||||
|
--hov = 'designated',
|
||||||
|
--access = 'no'
|
||||||
|
}
|
||||||
|
-- tag function normally provided via C++
|
||||||
|
function way:get_value_by_key(k)
|
||||||
|
return self[k]
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Mock C++ helper functions which are called from LUA.
|
||||||
|
-- FIXME
|
||||||
|
-- Debugging LUA code that uses these will not work correctly
|
||||||
|
-- unless we reimplement themethods in LUA.
|
||||||
|
|
||||||
|
function durationIsValid(str)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
function parseDuration(str)
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
|
||||||
|
function canonicalizeStringList(str)
|
||||||
|
return str
|
||||||
|
end
|
||||||
|
|
||||||
|
-- start state of result table, normally set form C++
|
||||||
|
local result = {
|
||||||
|
road_classification = {},
|
||||||
|
forward_speed = -1,
|
||||||
|
backward_speed = -1,
|
||||||
|
}
|
||||||
|
|
||||||
|
-- the profile we want to debug
|
||||||
|
require("car")
|
||||||
|
|
||||||
|
-- call the way function
|
||||||
|
for i=0,10000,1
|
||||||
|
do
|
||||||
|
way_function(way,result)
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user