From e4e1eb139e7ce0d21c17c3eb1053e9660b0ace39 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Wed, 28 Nov 2018 11:56:20 -0800 Subject: [PATCH] automatically merge all short roads --- editor/src/plugins/debug_objects.rs | 7 +++++- map_model/src/make/merge_intersections.rs | 29 ++++++++++++++++++----- map_model/src/map.rs | 2 +- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/editor/src/plugins/debug_objects.rs b/editor/src/plugins/debug_objects.rs index 45ac0fe9a4..eeb2fac35e 100644 --- a/editor/src/plugins/debug_objects.rs +++ b/editor/src/plugins/debug_objects.rs @@ -99,7 +99,12 @@ fn tooltip_lines(obj: ID, map: &Map, sim: &Sim, draw_map: &DrawMap) -> Text { "Lane goes from {} to {}", i1.elevation, i2.elevation )); - txt.add_line(format!("Lane is {} long", l.length())); + txt.add_line(format!( + "Lane is {} long, parent {} is {} long", + l.length(), + r.id, + r.center_pts.length() + )); for (k, v) in &r.osm_tags { txt.add_line(format!("{} = {}", k, v)); } diff --git a/map_model/src/make/merge_intersections.rs b/map_model/src/make/merge_intersections.rs index 063a662b35..c0ff235e1d 100644 --- a/map_model/src/make/merge_intersections.rs +++ b/map_model/src/make/merge_intersections.rs @@ -6,13 +6,30 @@ use std::collections::{HashMap, HashSet}; type IntersectionID = usize; type RoadID = usize; -pub fn merge_intersections(data: &mut raw_data::Map, map_name: &str, _timer: &mut Timer) { - if map_name == "montlake" { - merge(data, 423); // 23rd and Shelby - merge(data, 419); // 23rd and Hamlin - merge(data, 258); // 23rd and Louisa - merge(data, 42); // 25th and Lynn +const MIN_ROAD_LENGTH_METERS: f64 = 15.0; + +pub fn merge_intersections(data: &mut raw_data::Map, timer: &mut Timer) { + timer.start_iter("merge short roads", data.roads.len()); + + let mut merged = 0; + for i in 0..data.roads.len() { + timer.next(); + // We destroy roads and shorten this list as we go. Don't break, so the timer finishes. + if i >= data.roads.len() { + continue; + } + + let mut length = 0.0; + for pair in data.roads[i].points.windows(2) { + length += pair[0].gps_dist_meters(pair[1]); + } + if length < MIN_ROAD_LENGTH_METERS { + merge(data, i); + merged += 1; + } } + + info!("Merged {} short roads", merged); } fn merge(data: &mut raw_data::Map, merge_road: RoadID) { diff --git a/map_model/src/map.rs b/map_model/src/map.rs index b34b878a54..500f8d840b 100644 --- a/map_model/src/map.rs +++ b/map_model/src/map.rs @@ -66,7 +66,7 @@ impl Map { ) -> Map { timer.start("raw_map to Map"); - make::merge_intersections(&mut data, &name, timer); + make::merge_intersections(&mut data, timer); let gps_bounds = data.get_gps_bounds(); let bounds = gps_bounds.to_bounds();