From a52b966b033e60f4512393788955f07411b7709a Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Mon, 23 Jul 2018 08:39:58 -0700 Subject: [PATCH] make some more pedestrian paths possible by forcing turns even when line trimming fails --- docs/TODO_phase3.md | 2 -- geom/src/polyline.rs | 14 ++++++++++++++ map_model/src/make/turns.rs | 4 +++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/docs/TODO_phase3.md b/docs/TODO_phase3.md index 7afe55fee0..2f1a0c1fc2 100644 --- a/docs/TODO_phase3.md +++ b/docs/TODO_phase3.md @@ -28,8 +28,6 @@ ## pedestrians -- why so many impossible paths? r350 to r41 - - UI: draw cars and peds in intersections, even at lower zoom levels, just like on roads - make them obey intersections (deterministically!) - make them start and end at buildings diff --git a/geom/src/polyline.rs b/geom/src/polyline.rs index ab6d4c04e0..fb57f7ed63 100644 --- a/geom/src/polyline.rs +++ b/geom/src/polyline.rs @@ -180,6 +180,20 @@ impl PolyLine { .map(|pts| pts.iter().map(|pt| pt.to_vec()).collect()) .collect() } + + pub fn intersects(&self, other: &PolyLine) -> bool { + // Quadratic + for pair1 in self.pts.windows(2) { + let l1 = Line::new(pair1[0], pair1[1]); + for pair2 in other.pts.windows(2) { + let l2 = Line::new(pair2[0], pair2[1]); + if l1.intersects(&l2) { + return true; + } + } + } + false + } } impl fmt::Display for PolyLine { diff --git a/map_model/src/make/turns.rs b/map_model/src/make/turns.rs index aa9e14a6b5..b865b37640 100644 --- a/map_model/src/make/turns.rs +++ b/map_model/src/make/turns.rs @@ -99,7 +99,9 @@ pub(crate) fn make_crosswalks(i: &Intersection, m: &Map, mut turn_id_start: usiz } let dst_pt = dst.endpoint(i.id); - if src_pt != dst_pt { + // TODO Just the first check ideally, but until line trimming handles polylines, we + // should also do the second check. + if src_pt != dst_pt && !src.lane_center_pts.intersects(&dst.lane_center_pts) { continue; }