mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-25 23:43:25 +03:00
preps for interpreting turn:lanes from OSM
This commit is contained in:
parent
142c34af4e
commit
5fa824f504
@ -89,6 +89,8 @@ pub fn split_up_roads(
|
||||
timer.next();
|
||||
let mut r = orig_road.clone();
|
||||
r.points.clear();
|
||||
let endpt1 = pt_to_intersection[&orig_road.points[0].to_hashable()];
|
||||
let endpt2 = pt_to_intersection[&orig_road.points.last().unwrap().to_hashable()];
|
||||
r.i1 = pt_to_intersection[&orig_road.points[0].to_hashable()];
|
||||
|
||||
for (idx, pt) in orig_road.points.iter().enumerate() {
|
||||
@ -105,10 +107,20 @@ pub fn split_up_roads(
|
||||
}
|
||||
|
||||
r.i2 = *i2;
|
||||
if r.i1 == endpt1 {
|
||||
r.osm_tags
|
||||
.insert("abst:endpt_back".to_string(), "true".to_string());
|
||||
}
|
||||
if r.i2 == endpt2 {
|
||||
r.osm_tags
|
||||
.insert("abst:endpt_fwd".to_string(), "true".to_string());
|
||||
}
|
||||
// Start a new road
|
||||
map.roads
|
||||
.insert(raw_data::StableRoadID(map.roads.len()), r.clone());
|
||||
r.points.clear();
|
||||
r.osm_tags.remove("abst:endpt_fwd");
|
||||
r.osm_tags.remove("abst:endpt_back");
|
||||
r.i1 = *i2;
|
||||
r.points.push(pt.clone());
|
||||
}
|
||||
|
@ -125,6 +125,9 @@ impl ID {
|
||||
if l.is_parking() {
|
||||
txt.add_line(format!("Has {} parking spots", l.number_parking_spots()));
|
||||
}
|
||||
if let Some(types) = l.get_turn_restrictions(r) {
|
||||
txt.add_line(format!("Turn restriction for this lane: {:?}", types));
|
||||
}
|
||||
}
|
||||
ID::Intersection(id) => {
|
||||
txt.add_line(id.to_string());
|
||||
|
@ -1,7 +1,8 @@
|
||||
use crate::{BuildingID, BusStopID, DirectedRoadID, IntersectionID, Map, RoadID};
|
||||
use crate::{BuildingID, BusStopID, DirectedRoadID, IntersectionID, Map, Road, RoadID, TurnType};
|
||||
use abstutil;
|
||||
use geom::{Angle, Distance, Line, PolyLine, Pt2D};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use std::collections::HashSet;
|
||||
use std::fmt;
|
||||
|
||||
// Bit longer than the longest car.
|
||||
@ -157,4 +158,39 @@ impl Lane {
|
||||
r.id.backwards()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_turn_restrictions(&self, road: &Road) -> Option<HashSet<TurnType>> {
|
||||
if !self.is_driving() {
|
||||
return None;
|
||||
}
|
||||
|
||||
let (dir, offset) = road.dir_and_offset(self.id);
|
||||
let all = if dir && road.osm_tags.contains_key("abst:endpt_fwd") {
|
||||
road.osm_tags
|
||||
.get("turn:lanes:forward")
|
||||
.or_else(|| road.osm_tags.get("turn:lanes"))?
|
||||
} else if !dir && road.osm_tags.contains_key("abst:endpt_back") {
|
||||
road.osm_tags.get("turn:lanes:backward")?
|
||||
} else {
|
||||
return None;
|
||||
};
|
||||
let parts: Vec<&str> = all.split("|").collect();
|
||||
// TODO Verify the number of lanes matches up
|
||||
Some(
|
||||
parts[offset]
|
||||
.split(";")
|
||||
.flat_map(|s| match s {
|
||||
"left" => vec![TurnType::Left],
|
||||
"right" => vec![TurnType::Right],
|
||||
// TODO What is blank supposed to mean? From few observed cases, same as through
|
||||
"through" | "" => vec![
|
||||
TurnType::Straight,
|
||||
TurnType::LaneChangeLeft,
|
||||
TurnType::LaneChangeRight,
|
||||
],
|
||||
_ => panic!("What's turn restriction {}?", s),
|
||||
})
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user