filter OSM restrictions only to roads where they really apply

This commit is contained in:
Dustin Carlino 2019-07-04 18:39:49 -05:00
parent d1fc655aec
commit 90236c3afb

View File

@ -120,18 +120,28 @@ impl Map {
};
// TODO Temporary to debug turn restrictions.
for r in m.roads.iter_mut() {
if let Some(ref restrictions) = data.turn_restrictions.get(&r.osm_way_id) {
for (idx, (restriction, to)) in restrictions.iter().enumerate() {
// TODO Is this road even connected to the other way ID? Filter by the relevant
// pieces.
r.osm_tags.insert(
let mut filtered_restrictions = Vec::new();
for r in &m.roads {
if let Some(restrictions) = data.turn_restrictions.get(&r.osm_way_id) {
for (restriction, to) in restrictions {
// Make sure the restriction actually applies to this road.
if let Some(to_road) = m.intersections[r.src_i.0]
.roads
.iter()
.chain(m.intersections[r.dst_i.0].roads.iter())
.find(|r| m.roads[r.0].osm_way_id == *to)
{
filtered_restrictions.push((r.id, restriction, to_road));
}
}
}
}
for (idx, (from, restriction, to)) in filtered_restrictions.into_iter().enumerate() {
m.roads[from.0].osm_tags.insert(
format!("turn_restriction_{}", idx),
format!("{} to {}", restriction, to),
);
}
}
}
// Extra setup that's annoying to do as HalfMap, since we want to pass around a Map.
{