From 90236c3afb65cf8eb86aa33d6d8890c01a9e8880 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Thu, 4 Jul 2019 18:39:49 -0500 Subject: [PATCH] filter OSM restrictions only to roads where they really apply --- map_model/src/map.rs | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/map_model/src/map.rs b/map_model/src/map.rs index ed840cc815..5ff7dfcede 100644 --- a/map_model/src/map.rs +++ b/map_model/src/map.rs @@ -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( - format!("turn_restriction_{}", idx), - format!("{} to {}", restriction, to), - ); + 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. {