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

Split of "#111 Fix lane count calculation" #146

Merged
merged 55 commits into from
Apr 25, 2022
Merged
Show file tree
Hide file tree
Changes from 54 commits
Commits
Show all changes
55 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
c5963f9
Merge branch 'rust_refactor_busway' into rust_guess_lane_count_target
droogmic Apr 24, 2022
5087d2d
Merge branch 'lane_count_test' into rust_guess_lane_count_target
droogmic Apr 24, 2022
31ae8d0
Merge branch 'rust_guess_lane_count' into rust_guess_lane_count_source
droogmic Apr 24, 2022
b18803d
Rework
droogmic Apr 24, 2022
38d6dec
Rework Centre Turn Lanes
droogmic Apr 24, 2022
0cba794
Merge commit '38d6dec77786193001b1cf5408021b12d060ad47' into rust_gue…
droogmic Apr 25, 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
10 changes: 8 additions & 2 deletions data/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -847,9 +847,10 @@
rust: false # see next test
tags:
highway: "road"
lanes: "3"
sidewalk: "no"
shoulder: "no"
lanes: "3"
lanes:forward: "2"
bus:lanes:forward: "designated|"
driving_side: right
road:
Expand Down Expand Up @@ -1079,6 +1080,8 @@

- way_id: 389654080
mapillary: https://www.mapillary.com/app/?pKey=331760328316020
rust:
expect_warnings: true # deprecated centre_turn_lane
# TODO: the cycleway is actually two marked lanes,
# how should we know that given the tags or what should the tags be?
tags:
Expand Down Expand Up @@ -1185,6 +1188,8 @@
- description: "3 lanes"
way_id: 898731283
comment: "guess that an odd number of lanes will be divided favouring the forward direction with a warning"
rust:
expect_warnings: true
tags:
highway: "road"
lanes: "3"
Expand All @@ -1210,6 +1215,8 @@
# 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:
expect_warnings: true
tags:
highway: "road"
lanes: "5"
Expand Down Expand Up @@ -1238,7 +1245,6 @@

- description: "lanes, lanes:backward"
comment: "assume lanes:forward to be lanes - lanes:backward"
rust: false
skip_python: true
skip_kotlin: true
tags:
Expand Down
9 changes: 9 additions & 0 deletions rust/osm2lanes/src/locale.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,15 @@ impl std::str::FromStr for DrivingSide {
}
}

impl ToString for DrivingSide {
fn to_string(&self) -> String {
match self {
Self::Right => String::from("right"),
Self::Left => String::from("left"),
}
}
}

#[cfg(test)]
mod tests {
use celes::Country;
Expand Down
22 changes: 22 additions & 0 deletions rust/osm2lanes/src/tag/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ pub use key::TagKey;
mod osm;
pub use osm::{Highway, HighwayType, Lifecycle, HIGHWAY, LIFECYCLE};

use crate::transform::{RoadWarnings, TagsToLanesMsg};

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DuplicateKeyError(String);

Expand Down Expand Up @@ -90,6 +92,26 @@ impl Tags {
self.map.get(k.as_ref()).map(String::as_str)
}

/// Get the value for the given key and parse it into T.
/// Add a `TagsToLanesMsg::Unsupported` if parsing fails.
pub fn get_parsed<K: AsRef<str>, T: FromStr>(
&self,
key: K,
warnings: &mut RoadWarnings,
) -> Option<T> {
self.get(&key).and_then(|val| {
if let Ok(n) = val.parse::<T>() {
Some(n)
} else {
warnings.push(TagsToLanesMsg::unsupported_tag(
key.as_ref().to_owned(),
val,
));
None
}
})
}

/// Return if tags key has value,
/// return false if key does not exist.
#[must_use]
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 @@ -125,7 +125,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");
let tests: Vec<TestCase> = tests
.into_iter()
.filter(|test| test.test_enabled())
Expand Down
84 changes: 59 additions & 25 deletions rust/osm2lanes/src/transform/lanes_to_tags/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,17 +157,15 @@ pub fn lanes_to_tags(

let lanes = &road.lanes;

set_lanes(lanes, &mut tags)?;
let oneway = set_oneway(lanes, &mut tags)?;
let lane_count = set_lanes(lanes, &mut tags)?;
let oneway = set_oneway(lanes, &mut tags, locale, lane_count)?;

set_shoulder(lanes, &mut tags)?;
set_pedestrian(lanes, &mut tags)?;
set_parking(lanes, &mut tags)?;
set_cycleway(lanes, &mut tags, oneway)?;
set_busway(lanes, &mut tags, oneway)?;

lanes_both_ways(lanes, &mut tags)?;

let max_speed = get_max_speed(lanes, &mut tags)?;

locale_additions(max_speed, locale, &mut tags)?;
Expand All @@ -177,7 +175,7 @@ pub fn lanes_to_tags(
Ok(tags)
}

fn set_lanes(lanes: &[Lane], tags: &mut Tags) -> Result<(), LanesToTagsMsg> {
fn set_lanes(lanes: &[Lane], tags: &mut Tags) -> Result<usize, LanesToTagsMsg> {
let lane_count = lanes
.iter()
.filter(|lane| {
Expand All @@ -191,11 +189,16 @@ fn set_lanes(lanes: &[Lane], tags: &mut Tags) -> Result<(), LanesToTagsMsg> {
})
.count();
tags.checked_insert("lanes", lane_count.to_string())?;
Ok(())
Ok(lane_count)
}

/// Returns oneway
fn set_oneway(lanes: &[Lane], tags: &mut Tags) -> Result<bool, LanesToTagsMsg> {
fn set_oneway(
lanes: &[Lane],
tags: &mut Tags,
locale: &Locale,
lane_count: usize,
) -> Result<bool, LanesToTagsMsg> {
if lanes.iter().filter(|lane| lane.is_motor()).all(|lane| {
matches!(
lane,
Expand All @@ -208,6 +211,55 @@ fn set_oneway(lanes: &[Lane], tags: &mut Tags) -> Result<bool, LanesToTagsMsg> {
tags.checked_insert("oneway", "yes")?;
Ok(true)
} else {
// Forward
let forward_lanes = lanes
.iter()
.filter(|lane| {
matches!(
lane,
Lane::Travel {
designated: Designated::Motor | Designated::Bus,
direction: Some(Direction::Forward),
..
}
)
})
.count();
tags.checked_insert("lanes:forward", forward_lanes.to_string())?;
// Backward
let backward_lanes = lanes
.iter()
.filter(|lane| {
matches!(
lane,
Lane::Travel {
designated: Designated::Motor | Designated::Bus,
direction: Some(Direction::Backward),
..
}
)
})
.count();
tags.checked_insert("lanes:backward", backward_lanes.to_string())?;
// Both ways
if lanes.iter().any(|lane| {
matches!(
lane,
Lane::Travel {
designated: Designated::Motor,
direction: Some(Direction::Both),
..
}
)
}) {
tags.checked_insert("lanes:both_ways", "1")?;
if lane_count >= 3 {
tags.checked_insert(
"turn:lanes:both_ways",
locale.driving_side.opposite().to_string(),
)?;
}
}
Ok(false)
}
}
Expand Down Expand Up @@ -361,24 +413,6 @@ fn set_busway(lanes: &[Lane], tags: &mut Tags, oneway: bool) -> Result<(), Lanes
Ok(())
}

fn lanes_both_ways(lanes: &[Lane], tags: &mut Tags) -> Result<(), LanesToTagsMsg> {
if lanes.iter().any(|lane| {
matches!(
lane,
Lane::Travel {
designated: Designated::Motor,
direction: Some(Direction::Both),
..
}
)
}) {
tags.checked_insert("lanes:both_ways", "1")?;
// TODO: add LHT support
tags.checked_insert("turn:lanes:both_ways", "left")?;
}
Ok(())
}

fn get_max_speed(lanes: &[Lane], tags: &mut Tags) -> Result<Option<Speed>, LanesToTagsMsg> {
let max_speeds: Vec<Speed> = lanes
.iter()
Expand Down
2 changes: 1 addition & 1 deletion rust/osm2lanes/src/transform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::tag::TagKey;
mod error;
pub use error::{RoadError, RoadFromTags, RoadWarnings};

mod tags_to_lanes;
pub mod tags_to_lanes;
pub use tags_to_lanes::{tags_to_lanes, Config as TagsToLanesConfig, TagsToLanesMsg};

mod lanes_to_tags;
Expand Down
Loading