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. // TODO Temporary to debug turn restrictions.
for r in m.roads.iter_mut() { let mut filtered_restrictions = Vec::new();
if let Some(ref restrictions) = data.turn_restrictions.get(&r.osm_way_id) { for r in &m.roads {
for (idx, (restriction, to)) in restrictions.iter().enumerate() { if let Some(restrictions) = data.turn_restrictions.get(&r.osm_way_id) {
// TODO Is this road even connected to the other way ID? Filter by the relevant for (restriction, to) in restrictions {
// pieces. // Make sure the restriction actually applies to this road.
r.osm_tags.insert( 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!("turn_restriction_{}", idx),
format!("{} to {}", restriction, to), format!("{} to {}", restriction, to),
); );
} }
}
}
// Extra setup that's annoying to do as HalfMap, since we want to pass around a Map. // Extra setup that's annoying to do as HalfMap, since we want to pass around a Map.
{ {