filter OSM restrictions only to roads where they really apply
@@ -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.
{
