From 3fd961a551e87f8c14a137774858dc9d09362788 Mon Sep 17 00:00:00 2001 From: Denis Koronchik Date: Thu, 14 Sep 2017 18:44:24 +0300 Subject: [PATCH] Some improvements in code --- profiles/car.lua | 32 ++++++++++++++------------------ profiles/lib/relations.lua | 17 +++-------------- 2 files changed, 17 insertions(+), 32 deletions(-) diff --git a/profiles/car.lua b/profiles/car.lua index 1394da72e..72b41acb5 100644 --- a/profiles/car.lua +++ b/profiles/car.lua @@ -403,20 +403,16 @@ function process_way(profile, way, result, relations) if result.ref then local match_res = Relations.match_to_ref(relations, result.ref) - order = match_res['order'] - matched_refs = match_res['match'] - local ref = '' - for _, k in pairs(order) do - local v = matched_refs[k] + for _, m in pairs(match_res) do if ref ~= '' then ref = ref .. '; ' end - if v then - ref = ref .. k .. ' $' .. v + if m.dir then + ref = ref .. m.ref .. ' $' .. m.dir else - ref = ref .. k + ref = ref .. m.ref end end @@ -431,35 +427,35 @@ function process_relation(profile, relation, result) function add_extra_data(m) local name = relation:get_value_by_key("name") if name then - result[m]["route_name"] = name + result[m]['route_name'] = name end local ref = relation:get_value_by_key("ref") if ref then - result[m]["route_ref"] = ref + result[m]['route_ref'] = ref end end - if t == "route" then + if t == 'route' then local route = relation:get_value_by_key("route") - if route == "road" then + if route == 'road' then for _, m in ipairs(relation:members()) do -- process case, where directions set as role local role = string.lower(m:role()) - if role == "north" or role == "south" or role == "west" or role == "east" then - result[m]["route_direction"] = role + if role == 'north' or role == 'south' or role == 'west' or role == 'east' then + result[m]['route_direction'] = role add_extra_data(m) end end end - local direction = relation:get_value_by_key("direction") + local direction = relation:get_value_by_key('direction') if direction then direction = string.lower(direction) - if direction == "north" or direction == "south" or direction == "west" or direction == "east" then + if direction == 'north' or direction == 'south' or direction == 'west' or direction == 'east' then for _, m in ipairs(relation:members()) do - if m:role() == "forward" then - result[m]["route_direction"] = direction + if m:role() == 'forward' then + result[m]['route_direction'] = direction add_extra_data(m) end end diff --git a/profiles/lib/relations.lua b/profiles/lib/relations.lua index 0215d5d20..d72fac82f 100644 --- a/profiles/lib/relations.lua +++ b/profiles/lib/relations.lua @@ -7,18 +7,6 @@ Utils = require('lib/utils') Relations = {} -function Relations.Merge(relations) - local result = {} - - for _, r in ipairs(relations) do - for k, v in pairs(r) do - result[k] = v - end - end - - return result -end - -- match ref values to relations data function Relations.match_to_ref(relations, ref) @@ -96,8 +84,9 @@ function Relations.match_to_ref(relations, ref) end local result = {} - result['order'] = order - result['match'] = result_match + for i, r in ipairs(order) do + result[i] = { ref = r, dir = result_match[r] }; + end return result end