Skip to content
This repository has been archived by the owner on Mar 9, 2023. It is now read-only.

Fix lane count calculation - use Scheme structs to avoid re-reading/re-interpreting tags #111

Closed
wants to merge 49 commits into from
Closed
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
a491eef
Add a failing test for the case on the website
BudgieInWA Mar 25, 2022
bf5df9d
Rewrite driving_lane_directions to consider all tags together
BudgieInWA Mar 25, 2022
dc5de27
Add placeholder warn! calls to show how tag validation can be added t…
BudgieInWA Mar 25, 2022
f2c96fc
replace use of `is_some_and`
BudgieInWA Mar 26, 2022
fe479f4
Remove unused `#![feature(is_some_with)]`
BudgieInWA Mar 26, 2022
42ae376
Add lanes:{forward,backward} to lanes_to_tags
BudgieInWA Mar 26, 2022
e3cf57e
Calculate both_ways in driving_lane_directions too
BudgieInWA Mar 27, 2022
b032684
Convert temporary `warn!` calls into `RoadMsg` warnings.
BudgieInWA Mar 27, 2022
4a30b89
Fix misleading panic message when failing to parse data.yaml
BudgieInWA Mar 28, 2022
295e8bc
Represent in the tests that odd lane count warns about guessing
BudgieInWA Mar 28, 2022
f472da3
Avoid guessing lanes= and lanes:forward= in the tests just yet
BudgieInWA Mar 28, 2022
28300bc
guess lanes= and lanes:{forward,backward}= in more situations with bu…
BudgieInWA Mar 28, 2022
a68efd7
fmt
BudgieInWA Mar 28, 2022
c9ca0eb
Start to split parsing into schema understanding, then combining.
BudgieInWA Apr 2, 2022
0496070
wip: Experimental top down rewrite of tag parsing and road building s…
BudgieInWA Apr 2, 2022
392910c
Split into Hunch: "data with certainty" and Theory: "hunch with history"
BudgieInWA Apr 4, 2022
beec80a
Delete experimental Hunch, Theory, and Scheme code from this branch
BudgieInWA Apr 8, 2022
538a676
Fix build and tweak comments
BudgieInWA Apr 8, 2022
96d29e1
Merge remote-tracking branch 'origin/main' into rust_guess_lane_count
BudgieInWA Apr 8, 2022
57fbad0
Move driving_lane_directions to LanesScheme::new
BudgieInWA Apr 8, 2022
012319d
Enable passing test :) add TODO
BudgieInWA Apr 8, 2022
0dd3481
fmt
BudgieInWA Apr 9, 2022
768e441
Add a CentreTurnLaneScheme, add warnings and stuff.
BudgieInWA Apr 9, 2022
fabbb9d
Rename `busway.forward_direction` to `forward_side_direction` to be c…
BudgieInWA Apr 9, 2022
a14ccd7
Remove unused get_and_parse. Not needed now that...
BudgieInWA Apr 9, 2022
7b0b139
fix TODO: does it make sense to have a backward lane on the forward_s…
BudgieInWA Apr 9, 2022
fe1024f
Add comments describing the different Infer variants.
BudgieInWA Apr 9, 2022
1bfb561
remove empty impl
BudgieInWA Apr 9, 2022
ca818c7
Support LHT outputting turn:lanes:both_ways
BudgieInWA Apr 9, 2022
9f07ce1
Add use statement so doctests compile
BudgieInWA Apr 9, 2022
ec7f50d
Use new `road: lanes:` nesting for modified test
BudgieInWA Apr 10, 2022
9c88ebc
Use the new `road: lanes:` nesting for more modified tests.
BudgieInWA Apr 10, 2022
5a63091
Merge branch 'main' into rust_guess_lane_count
droogmic Apr 11, 2022
5212f2e
Fix Clippy
droogmic Apr 11, 2022
08884cb
Merge pull request #1 from droogmic/rust_guess_lane_count
BudgieInWA Apr 18, 2022
2b96964
Fix support for oneway=yes busway:<backward>=opposite_lane
BudgieInWA Apr 19, 2022
eaf0117
Merge branch 'main' into rust_guess_lane_count
BudgieInWA Apr 20, 2022
497b5c7
Fix build after merge, using new TagsToLanesMsg type
BudgieInWA Apr 20, 2022
b890bd2
fix passing 1 byte type as reference (thanks to Clippy)
BudgieInWA Apr 20, 2022
fb56a07
Skip new test in python and kotlin, because they fail
BudgieInWA Apr 20, 2022
551ab2e
add relevant tag to warning
BudgieInWA Apr 20, 2022
9c94da2
warn on calculated inconsistency, as well as direct
BudgieInWA Apr 20, 2022
7303b56
Settle on TurnLanesScheme (with #[allow(unused)])
BudgieInWA Apr 20, 2022
1267f2d
Remove commented code and TODOs
BudgieInWA Apr 20, 2022
2f36852
Remove TurnMarking as struct with bools, do we need a bitset?
BudgieInWA Apr 20, 2022
c8f2774
More succinct centre_turn_lane parsing
BudgieInWA Apr 21, 2022
41694ba
rename bothways to proper both_ways
BudgieInWA Apr 22, 2022
c0df013
rename bothways proper both_ways
BudgieInWA Apr 22, 2022
a264b3c
whitespace
BudgieInWA Apr 22, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 52 additions & 23 deletions data/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,7 @@
tags:
highway: 'road'
lanes: '3'
lanes:forward: '2'
sidewalk: 'no'
shoulder: 'no'
bus:lanes:forward: 'designated|'
Expand Down Expand Up @@ -819,6 +820,7 @@
highway: primary
busway: lane
hgv: local
lanes: '4' # FIXME: lanes is not tagged but inferring the it is hard
lanes:bus: '2'
lit: 'yes'
maxspeed: 25 mph
Expand Down Expand Up @@ -1078,39 +1080,67 @@
designated: motor_vehicle

- way_id: 898731283
comment: how should an odd number of lanes forward/backwards be split without any clues?
comment: guess that an odd number of lanes will be divided favouring the forward direction with a warning
rust:
ignore_warnings: true
tags:
highway: 'road'
lanes: '3'
sidewalk: 'both'
driving_side: 'left'
output:
- type: travel
designated: foot
- type: travel
direction: forward
designated: motor_vehicle
- type: travel
direction: forward
designated: motor_vehicle
- type: travel
direction: backward
designated: motor_vehicle
- type: travel
designated: foot
- type: travel
designated: foot
- type: travel
direction: forward
designated: motor_vehicle
- type: travel
direction: forward
designated: motor_vehicle
- type: travel
direction: backward
designated: motor_vehicle
- type: travel
designated: foot
BudgieInWA marked this conversation as resolved.
Show resolved Hide resolved

# I didn't look for a real example of this
- description: '5 lanes'
comment: guess that an odd number of lanes will be divided favouring the forward direction with a warning
rust:
ignore_warnings: true
tags:
highway: 'road'
lanes: '5'
sidewalk: 'no'
driving_side: right
output:
- type: shoulder
- type: travel
direction: backward
designated: motor_vehicle
- type: travel
direction: backward
designated: motor_vehicle
- type: travel
direction: forward
designated: motor_vehicle
- type: travel
direction: forward
designated: motor_vehicle
- type: travel
direction: forward
designated: motor_vehicle
- type: shoulder

- description: assume lanes:forward to be lanes - lanes:backward
tags:
highway: secondary
lanes: 4
lanes:backward: 1
Comment on lines +1225 to +1226
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are interpreted as integers, when they should be strings, that causes the kotlin tests to fail

sidewalk: no
driving_side: right
output:
- type: shoulder
- type: travel
direction: backward
designated: motor_vehicle
- type: travel
direction: backward
designated: motor_vehicle
Expand All @@ -1126,18 +1156,17 @@
- type: shoulder

- way_id: 335668924
description: a narrow alleyway tagged lanes=1
skip_python: true
skip_kotlin: true
tags:
highway: 'road'
highway: 'service'
lanes: '1'
sidewalk: 'no'
driving_side: right
output:
- type: shoulder
- type: travel
direction: backward
designated: motor_vehicle
- type: travel
direction: forward
direction: both
designated: motor_vehicle
- type: shoulder

Expand Down
2 changes: 1 addition & 1 deletion rust/osm2lanes/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl std::fmt::Display for TestCase {
pub fn get_tests() -> Vec<TestCase> {
let tests: Vec<TestCase> =
serde_yaml::from_reader(BufReader::new(File::open("../../data/tests.yml").unwrap()))
.expect("invalid json");
.expect("invalid yaml in data/tests.yml");
BudgieInWA marked this conversation as resolved.
Show resolved Hide resolved
let tests: Vec<TestCase> = tests
.into_iter()
.filter(|test| test.test_enabled())
Expand Down
81 changes: 57 additions & 24 deletions rust/osm2lanes/src/transform/lanes_to_tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,21 @@ pub fn lanes_to_tags(lanes: &[Lane], locale: &Locale, config: &LanesToTagsConfig
let mut tags = Tags::default();
let mut oneway = false;
tags.checked_insert("highway", "road")?; // TODO, add `highway` to `Lanes`
{
let lane_count = lanes
.iter()
.filter(|lane| {
matches!(

// Lane Count
let lane_count = lanes
.iter()
.filter(|lane| {
matches!(
lane,
Lane::Travel {
designated: LaneDesignated::Motor | LaneDesignated::Bus,
..
}
)
})
.count();
tags.checked_insert("lanes", lane_count.to_string())?;
}
})
.count();
tags.checked_insert("lanes", lane_count.to_string())?;
// Oneway
if lanes.iter().filter(|lane| lane.is_motor()).all(|lane| {
matches!(
Expand All @@ -67,6 +67,54 @@ pub fn lanes_to_tags(lanes: &[Lane], locale: &Locale, config: &LanesToTagsConfig
}) {
tags.checked_insert("oneway", "yes")?;
oneway = true;
} else {
// Forward
let forward_lanes = lanes
.iter()
.filter(|lane| {
matches!(
lane,
Lane::Travel {
designated: LaneDesignated::Motor | LaneDesignated::Bus,
direction: Some(LaneDirection::Forward),
..
}
)
})
.count();
tags.checked_insert("lanes:forward", forward_lanes.to_string())?;
// Backward
let backward_lanes = lanes
.iter()
.filter(|lane| {
matches!(
lane,
Lane::Travel {
designated: LaneDesignated::Motor | LaneDesignated::Bus,
direction: Some(LaneDirection::Backward),
..
}
)
})
.count();
tags.checked_insert("lanes:backward", backward_lanes.to_string())?;
// Both ways
if lanes.iter().any(|lane| {
matches!(
lane,
Lane::Travel {
designated: LaneDesignated::Motor,
direction: Some(LaneDirection::Both),
..
}
)
}) {
tags.checked_insert("lanes:both_ways", "1")?;
// TODO: add LHT support
BudgieInWA marked this conversation as resolved.
Show resolved Hide resolved
if lane_count >= 3 {
tags.checked_insert("turn:lanes:both_ways", "left")?;
}
}
}
// Shoulder
match (
Expand Down Expand Up @@ -212,21 +260,6 @@ pub fn lanes_to_tags(lanes: &[Lane], locale: &Locale, config: &LanesToTagsConfig
}
}

if lanes.iter().any(|lane| {
matches!(
lane,
Lane::Travel {
designated: LaneDesignated::Motor,
direction: Some(LaneDirection::Both),
..
}
)
}) {
tags.checked_insert("lanes:both_ways", "1")?;
// TODO: add LHT support
tags.checked_insert("turn:lanes:both_ways", "left")?;
}

let max_speed = {
let max_speeds: Vec<Speed> = lanes
.iter()
Expand Down
Loading