-
-
Notifications
You must be signed in to change notification settings - Fork 4k
fix: account for road width in map matching #7643
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| local Tags = require('lib/tags') | ||
| local Set = require('lib/set') | ||
| local Measure = require('lib/measure') | ||
|
|
||
| local Guidance = {} | ||
|
|
||
|
|
@@ -77,6 +78,70 @@ local function to_number_uint(s) | |
| return nil | ||
| end | ||
|
|
||
| local function first_width(way, keys) | ||
| for _, key in ipairs(keys) do | ||
| local width = Measure.get_max_width(way:get_value_by_key(key)) | ||
| if width and width > 0 then | ||
| return width | ||
| end | ||
| end | ||
| end | ||
|
|
||
| local function sum_width_lanes(value) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be called |
||
| if not value then | ||
| return nil | ||
| end | ||
|
|
||
| local total = 0 | ||
| local found = false | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this variable actually necessary? Would it be enough to check if sum is zero or not? |
||
| for lane_width in (value .. '|'):gmatch("([^|]*)|") do | ||
| local width = Measure.get_max_width(lane_width) | ||
| if width and width > 0 then | ||
| total = total + width | ||
| found = true | ||
| end | ||
| end | ||
|
|
||
| if found then | ||
| return total | ||
| end | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this return a nil value explicitly in case the sum is zero? |
||
| end | ||
|
|
||
| local function first_width_lanes(way, keys) | ||
| for _, key in ipairs(keys) do | ||
| local width = sum_width_lanes(way:get_value_by_key(key)) | ||
| if width and width > 0 then | ||
| return width | ||
| end | ||
| end | ||
| end | ||
|
|
||
| function Guidance.get_road_width(way) | ||
| local width = first_width(way, { 'width:carriageway', 'width', 'est_width' }) | ||
| if width then | ||
| return width | ||
| end | ||
|
|
||
| local forward_width = first_width(way, { 'width:forward' }) | ||
| local backward_width = first_width(way, { 'width:backward' }) | ||
|
|
||
| if forward_width or backward_width then | ||
| return (forward_width or 0) + (backward_width or 0) | ||
| end | ||
|
|
||
| forward_width = first_width_lanes(way, { 'width:lanes:forward' }) | ||
| backward_width = first_width_lanes(way, { 'width:lanes:backward' }) | ||
|
|
||
| if forward_width or backward_width then | ||
| return (forward_width or 0) + (backward_width or 0) | ||
| end | ||
|
|
||
| width = first_width_lanes(way, { 'width:lanes' }) | ||
| if width then | ||
| return width | ||
| end | ||
| end | ||
|
|
||
| function Guidance.set_classification (highway, result, input_way) | ||
| if motorway_types[highway] then | ||
| result.road_classification.motorway_class = true | ||
|
|
@@ -140,6 +205,11 @@ function Guidance.set_classification (highway, result, input_way) | |
| result.road_classification.num_lanes = total_count | ||
| end | ||
| end | ||
|
|
||
| local road_width = Guidance.get_road_width(input_way) | ||
| if road_width then | ||
| result.road_width = road_width | ||
| end | ||
| end | ||
|
|
||
| -- returns forward,backward psv lane count | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| local Sequence = require('lib/sequence') | ||
| local Set = require('lib/set') | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this an unrelated change? |
||
|
|
||
| Measure = {} | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this maybe be called
find_first_widthto indicate that it greedily searches for the first width tag it can find?