From 2451244344622f1dd44c371833b589cd3d5e353f Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Mon, 25 Jun 2018 12:03:34 -0700 Subject: [PATCH] splitting out a mapmaking fxn --- docs/lanes.md | 3 ++ map_model/src/map.rs | 92 ++++++++++++++++++++++++-------------------- 2 files changed, 53 insertions(+), 42 deletions(-) diff --git a/docs/lanes.md b/docs/lanes.md index 0fa02f74ba..b7baeeae39 100644 --- a/docs/lanes.md +++ b/docs/lanes.md @@ -107,6 +107,9 @@ wait slow down even more -- before any of this change, lanes on adjacent roads s any point, by the magic of easy serialization. - get rid of the protobuf + - line trimming + - just replacing the last pt might not always work. especially with old center lines! + - an mvp release could just be producing high-quality, reusable geometry for seattle - with an editor to quickly fiddle with where sidewalks/different lanes are diff --git a/map_model/src/map.rs b/map_model/src/map.rs index 977f2b260c..898c0f1081 100644 --- a/map_model/src/map.rs +++ b/map_model/src/map.rs @@ -135,48 +135,8 @@ impl Map { } for i in &m.intersections { - let incoming: Vec = i.incoming_roads - .iter() - .filter(|id| m.roads[id.0].lane_type == LaneType::Driving) - .map(|id| *id) - .collect(); - let outgoing: Vec = i.outgoing_roads - .iter() - .filter(|id| m.roads[id.0].lane_type == LaneType::Driving) - .map(|id| *id) - .collect(); - - // TODO: Figure out why this happens in the huge map - if incoming.is_empty() { - println!("WARNING: intersection {:?} has no incoming roads", i); - continue; - } - if outgoing.is_empty() { - println!("WARNING: intersection {:?} has no outgoing roads", i); - continue; - } - let dead_end = incoming.len() == 1 && outgoing.len() == 1; - - for src in &incoming { - let src_r = &m.roads[src.0]; - for dst in &outgoing { - let dst_r = &m.roads[dst.0]; - // Don't create U-turns unless it's a dead-end - if src_r.other_side == Some(dst_r.id) && !dead_end { - continue; - } - - let id = TurnID(m.turns.len()); - m.turns.push(Turn { - id, - parent: i.id, - src: *src, - dst: *dst, - src_pt: src_r.last_pt(), - dst_pt: dst_r.first_pt(), - }); - } - } + let turns = make_turns(i, &m); + m.turns.extend(turns); } for t in &m.turns { m.intersections[t.parent.0].turns.push(t.id); @@ -293,3 +253,51 @@ impl Map { self.bounds.clone() } } + +// TODO organize these differently +fn make_turns(i: &Intersection, m: &Map) -> Vec { + let incoming: Vec = i.incoming_roads + .iter() + .filter(|id| m.roads[id.0].lane_type == LaneType::Driving) + .map(|id| *id) + .collect(); + let outgoing: Vec = i.outgoing_roads + .iter() + .filter(|id| m.roads[id.0].lane_type == LaneType::Driving) + .map(|id| *id) + .collect(); + + // TODO: Figure out why this happens in the huge map + if incoming.is_empty() { + println!("WARNING: intersection {:?} has no incoming roads", i); + return Vec::new(); + } + if outgoing.is_empty() { + println!("WARNING: intersection {:?} has no outgoing roads", i); + return Vec::new(); + } + let dead_end = incoming.len() == 1 && outgoing.len() == 1; + + let mut result = Vec::new(); + for src in &incoming { + let src_r = &m.roads[src.0]; + for dst in &outgoing { + let dst_r = &m.roads[dst.0]; + // Don't create U-turns unless it's a dead-end + if src_r.other_side == Some(dst_r.id) && !dead_end { + continue; + } + + let id = TurnID(m.turns.len()); + result.push(Turn { + id, + parent: i.id, + src: *src, + dst: *dst, + src_pt: src_r.last_pt(), + dst_pt: dst_r.first_pt(), + }); + } + } + result +}