Skip to content

Commit

Permalink
Add shared use paths
Browse files Browse the repository at this point in the history
  • Loading branch information
ginnyTheCat committed Feb 26, 2024
1 parent 4acb221 commit 197bd29
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
27 changes: 21 additions & 6 deletions osm2lanes/src/algorithm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,7 @@ pub fn get_lane_specs_ltr(tags: &Tags, cfg: &MapConfig) -> Vec<LaneSpec> {
.map(|(i, lane)| {
from_lane(
lane,
if (i * 2 < lanes.centre_line) == (cfg.driving_side == DrivingSide::Left) {
Direction::Fwd
} else {
Direction::Back
},
traffic_direction(i * 2, lanes.centre_line, cfg.driving_side),
)
})
.collect();
Expand All @@ -58,6 +54,18 @@ pub fn get_lane_specs_ltr(tags: &Tags, cfg: &MapConfig) -> Vec<LaneSpec> {
specs
}

fn traffic_direction(position: usize, centre_line: usize, driving_side: DrivingSide) -> Direction {
if position + 1 == centre_line {
return Direction::Fwd;
}

if (position < centre_line) == (driving_side == DrivingSide::Left) {
Direction::Fwd
} else {
Direction::Back
}
}

fn from_lane(lane: Lane, traffic_direction: Direction) -> LaneSpec {
let (lt, dir, turns) = match &lane.variant {
LaneVariant::Travel(t) => travel_lane(t, traffic_direction),
Expand Down Expand Up @@ -104,7 +112,7 @@ fn travel_lane(
}
}

for (mode, lt) in [
for (mode, mut lt) in [
(TMode::Tram, LaneType::LightRail),
(TMode::Train, LaneType::LightRail),
(TMode::Motorcar, LaneType::Driving),
Expand All @@ -116,6 +124,13 @@ fn travel_lane(
let access_forward = t.forward.access.get(mode).is_some_and(mode_allowed);
let access_backward = t.backward.access.get(mode).is_some_and(mode_allowed);

if mode == TMode::Bicycle
&& (t.forward.access.get(TMode::Foot).is_some_and(mode_allowed)
|| t.backward.access.get(TMode::Foot).is_some_and(mode_allowed))
{
lt = LaneType::SharedUse;
}

let dir = match (access_forward, access_backward) {
(true, false) => Direction::Fwd,
(false, true) => Direction::Back,
Expand Down
8 changes: 4 additions & 4 deletions osm2lanes/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ fn test_osm_to_specs() {
"cycleway:right:oneway=no",
],
DrivingSide::Right,
"spddddbbps",
"vvvv^^v^^^",
"spddddpbbs",
"vvvv^^^v^^",
),
(
"https://www.openstreetmap.org/way/389654080",
Expand Down Expand Up @@ -161,8 +161,8 @@ fn test_osm_to_specs() {
"https://www.openstreetmap.org/way/335668924",
vec!["lanes=1", "sidewalk=none"],
DrivingSide::Right,
"dd",
"v^",
"d",
"^",
),
(
"https://www.openstreetmap.org/way/632329263",
Expand Down

0 comments on commit 197bd29

Please sign in to comment.