From b6a9e2e1a4470e324e88b863917996b01a334e82 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Thu, 26 Jul 2018 17:08:49 -0700 Subject: [PATCH] dont make u-turns unless really at a dead-end --- map_model/src/intersection.rs | 13 ++++++++++++- map_model/src/make/turns.rs | 7 +++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/map_model/src/intersection.rs b/map_model/src/intersection.rs index ca479b42dd..94ca6b4379 100644 --- a/map_model/src/intersection.rs +++ b/map_model/src/intersection.rs @@ -3,7 +3,8 @@ use dimensioned::si; use geom::Pt2D; use std::fmt; -use {LaneID, TurnID}; +use {LaneID, TurnID, RoadID, Map}; +use std::collections::HashSet; // TODO reconsider pub usize. maybe outside world shouldnt know. #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord, Serialize, Deserialize)] @@ -33,3 +34,13 @@ impl PartialEq for Intersection { self.id == other.id } } + +impl Intersection { + pub fn is_dead_end(&self, map: &Map) -> bool { + let mut roads: HashSet = HashSet::new(); + for l in self.incoming_lanes.iter().chain(self.outgoing_lanes.iter()) { + roads.insert(map.get_l(*l).parent); + } + roads.len() == 1 + } +} diff --git a/map_model/src/make/turns.rs b/map_model/src/make/turns.rs index 5512aae6cb..22f1ad7d1b 100644 --- a/map_model/src/make/turns.rs +++ b/map_model/src/make/turns.rs @@ -107,20 +107,19 @@ fn make_turns( assert_eq!(map.get_l(*l).src_i, parent); } - let dead_end = incoming.len() == 1 && outgoing.len() == 1; + let dead_end = map.get_i(parent).is_dead_end(map); let mut result = Vec::new(); for src in incoming { let src_l = map.get_l(*src); - let other_side = map.get_r(src_l.parent) - .get_opposite_lane(src_l.id, src_l.lane_type); for dst in outgoing { let dst_l = map.get_l(*dst); // Don't create U-turns unless it's a dead-end - if other_side == Some(dst_l.id) && !dead_end { + if src_l.parent == dst_l.parent && !dead_end { continue; } + // TODO if it's a multi-lane dead-end, ideally match up lanes or something result.push(Turn { id: TurnID::new(*src, *dst),