From 2e4cb2cb763643e8082e135da63bad9fa87c0f09 Mon Sep 17 00:00:00 2001 From: Michael Droogleever Fortuyn Date: Mon, 9 May 2022 14:57:20 +0200 Subject: [PATCH] Add Direction To Access --- osm2lanes/src/road/lane.rs | 28 +++++++++++++------ osm2lanes/src/road/mod.rs | 2 +- osm2lanes/src/transform/tags_to_lanes/road.rs | 27 ++++++++++++------ 3 files changed, 40 insertions(+), 17 deletions(-) diff --git a/osm2lanes/src/road/lane.rs b/osm2lanes/src/road/lane.rs index 29c0aa2c..6c211254 100644 --- a/osm2lanes/src/road/lane.rs +++ b/osm2lanes/src/road/lane.rs @@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize}; use crate::locale::Locale; use crate::metric::{Metre, Speed}; use crate::road::separator::{Markings, Semantic}; -use crate::tag::{Access as AccessValue, HighwayType}; +use crate::tag::{Access as AccessTagValue, HighwayType}; /// A single lane #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] @@ -19,7 +19,7 @@ pub enum Lane { #[serde(skip_serializing_if = "Option::is_none")] max_speed: Option, #[serde(skip_serializing_if = "Option::is_none")] - access: Option, + access: Option, }, Parking { direction: Direction, @@ -170,19 +170,31 @@ impl Printable for Direction { } /// Access by vehicle type +/// /// Types as defined in // TODO: how to handle the motor_vehicle vs motorcar discussion in https://wiki.openstreetmap.org/wiki/Key:motorcar#Controversy +// TODO: separating weight class by usage? #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[serde(tag = "type", rename_all = "snake_case")] -pub struct Access { +pub struct AccessByType { #[serde(skip_serializing_if = "Option::is_none")] - pub(crate) foot: Option, + pub(crate) foot: Option, #[serde(skip_serializing_if = "Option::is_none")] - pub(crate) bicycle: Option, + pub(crate) bicycle: Option, #[serde(skip_serializing_if = "Option::is_none")] - pub(crate) taxi: Option, + pub(crate) taxi: Option, #[serde(skip_serializing_if = "Option::is_none")] - pub(crate) bus: Option, + pub(crate) bus: Option, #[serde(skip_serializing_if = "Option::is_none")] - pub(crate) motor: Option, + pub(crate) motor: Option, +} + +/// Access for a given user +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +#[serde(tag = "type", rename_all = "snake_case")] +pub struct AccessAndDirection { + pub(crate) access: AccessTagValue, + /// Direction, if different from designated direction + #[serde(skip_serializing_if = "Option::is_none")] + pub(crate) direction: Option, } diff --git a/osm2lanes/src/road/mod.rs b/osm2lanes/src/road/mod.rs index 29483076..fcaaa1dc 100644 --- a/osm2lanes/src/road/mod.rs +++ b/osm2lanes/src/road/mod.rs @@ -5,7 +5,7 @@ use crate::metric::Metre; use crate::tag::Highway; mod lane; -pub use lane::{Access, Designated, Direction, Lane, Printable}; +pub use lane::{AccessAndDirection, AccessByType, Designated, Direction, Lane, Printable}; mod separator; pub use separator::{Color, Marking, Markings, Semantic, Style}; diff --git a/osm2lanes/src/transform/tags_to_lanes/road.rs b/osm2lanes/src/transform/tags_to_lanes/road.rs index 38bb8b7b..4ae48d95 100644 --- a/osm2lanes/src/transform/tags_to_lanes/road.rs +++ b/osm2lanes/src/transform/tags_to_lanes/road.rs @@ -10,7 +10,10 @@ use super::separator::{ use super::TagsToLanesMsg; use crate::locale::{DrivingSide, Locale}; use crate::metric::{Metre, Speed}; -use crate::road::{Access as LaneAccess, Designated, Direction, Lane}; +use crate::road::{ + AccessAndDirection as LaneAccessAndDirection, AccessByType as LaneAccessByType, Designated, + Direction, Lane, +}; use crate::tag::{Access as AccessValue, Highway, TagKey, Tags, HIGHWAY, LIFECYCLE}; use crate::transform::error::{RoadError, RoadWarnings}; use crate::transform::tags_to_lanes::counts::{CentreTurnLaneScheme, Counts}; @@ -56,8 +59,16 @@ pub struct Access { pub motor: Infer, } -impl From for Option { +impl From for Option { fn from(inferred: Access) -> Self { + impl LaneAccessAndDirection { + fn from(v: Infer) -> Option { + v.some().map(|v| Self { + access: v, + direction: None, + }) + } + } if inferred.foot.is_none() && inferred.bicycle.is_none() && inferred.taxi.is_none() @@ -66,12 +77,12 @@ impl From for Option { { return None; } - Some(LaneAccess { - foot: inferred.foot.some(), - bicycle: inferred.bicycle.some(), - taxi: inferred.taxi.some(), - bus: inferred.bus.some(), - motor: inferred.motor.some(), + Some(LaneAccessByType { + foot: LaneAccessAndDirection::from(inferred.foot), + bicycle: LaneAccessAndDirection::from(inferred.bicycle), + taxi: LaneAccessAndDirection::from(inferred.taxi), + bus: LaneAccessAndDirection::from(inferred.bus), + motor: LaneAccessAndDirection::from(inferred.motor), }) } }