diff --git a/debug_initialmap/src/main.rs b/debug_initialmap/src/main.rs index 268f840450..1bc928945b 100644 --- a/debug_initialmap/src/main.rs +++ b/debug_initialmap/src/main.rs @@ -1,14 +1,17 @@ use abstutil::{find_next_file, find_prev_file, read_binary, Timer}; use ezgui::{Color, EventCtx, EventLoopMode, GfxCtx, Key, Text, GUI}; use geom::{Distance, Polygon}; -use map_model::raw_data; -use map_model::raw_data::{StableIntersectionID, StableRoadID}; +use map_model::raw_data::{StableIntersectionID, StableRoadID, InitialMap}; use std::collections::HashSet; use std::{env, process}; use viewer::World; +// Bit bigger than buses +const MIN_ROAD_LENGTH: Distance = Distance::const_meters(13.0); + struct UI { world: World, + data: InitialMap, filename: String, // TODO Or, if these are common things, the World could also hold this state. selected: Option, @@ -17,9 +20,13 @@ struct UI { } impl UI { - fn new(filename: &str, world: World) -> UI { + fn new(filename: &str, ctx: &mut EventCtx) -> UI { + let data: InitialMap = + read_binary(filename, &mut Timer::new("load InitialMap")).unwrap(); + let world = initial_map_to_world(&data, ctx); UI { world, + data, filename: filename.to_string(), selected: None, hide: HashSet::new(), @@ -28,7 +35,9 @@ impl UI { } fn load_different(&mut self, filename: String, ctx: &mut EventCtx) { - self.world = load_initial_map(&filename, ctx); + let data: InitialMap = + read_binary(&filename, &mut Timer::new("load InitialMap")).unwrap(); + self.world = initial_map_to_world(&data, ctx); self.selected = None; self.filename = filename; self.hide.clear(); @@ -64,6 +73,13 @@ impl GUI for UI { self.selected = None; } } + if let Some(ID::HalfRoad(r, _)) = self.selected { + if ctx.input.key_pressed(Key::M, "merge") { + self.data.merge(r); + self.world = initial_map_to_world(&self.data, ctx); + self.selected = None; + } + } if !self.hide.is_empty() { if ctx.input.key_pressed(Key::K, "unhide everything") { self.hide.clear(); @@ -92,7 +108,7 @@ fn main() { let args: Vec = env::args().collect(); ezgui::run("InitialMap debugger", 1024.0, 768.0, |ctx| { ctx.canvas.cam_zoom = 4.0; - UI::new(&args[1], load_initial_map(&args[1], ctx)) + UI::new(&args[1], ctx) }); } @@ -112,13 +128,11 @@ impl viewer::ObjectID for ID { } } -fn load_initial_map(filename: &str, ctx: &mut EventCtx) -> World { - let data: raw_data::InitialMap = - read_binary(filename, &mut Timer::new("load InitialMap")).unwrap(); - +fn initial_map_to_world(data: &InitialMap, ctx: &mut EventCtx) -> World { let mut w = World::new(&data.bounds); for r in data.roads.values() { + let len = r.trimmed_center_pts.length(); if r.fwd_width > Distance::ZERO { w.add_obj( ctx.prerender, @@ -127,12 +141,12 @@ fn load_initial_map(filename: &str, ctx: &mut EventCtx) -> World { .shift_right(r.fwd_width / 2.0) .unwrap() .make_polygons(r.fwd_width), - Color::grey(0.8), - Text::from_line(format!( - "{} forwards, {} long", - r.id, - r.trimmed_center_pts.length() - )), + if len < MIN_ROAD_LENGTH { + Color::CYAN + } else { + Color::grey(0.8) + }, + Text::from_line(format!("{} forwards, {} long", r.id, len)), ); } if r.back_width > Distance::ZERO { @@ -143,12 +157,12 @@ fn load_initial_map(filename: &str, ctx: &mut EventCtx) -> World { .shift_left(r.back_width / 2.0) .unwrap() .make_polygons(r.back_width), - Color::grey(0.6), - Text::from_line(format!( - "{} backwards, {} long", - r.id, - r.trimmed_center_pts.length() - )), + if len < MIN_ROAD_LENGTH { + Color::GREEN + } else { + Color::grey(0.6) + }, + Text::from_line(format!("{} backwards, {} long", r.id, len)), ); } } diff --git a/map_model/src/make/initial/merge.rs b/map_model/src/make/initial/merge.rs index dd1410dc6c..0ba559c052 100644 --- a/map_model/src/make/initial/merge.rs +++ b/map_model/src/make/initial/merge.rs @@ -56,7 +56,7 @@ pub fn short_roads(map: &mut InitialMap, timer: &mut Timer) { } // Returns the retained intersection. -fn merge( +pub fn merge( map: &mut InitialMap, merge_road: StableRoadID, timer: &mut Timer, diff --git a/map_model/src/make/initial/mod.rs b/map_model/src/make/initial/mod.rs index b588652d3a..7e55cb1db3 100644 --- a/map_model/src/make/initial/mod.rs +++ b/map_model/src/make/initial/mod.rs @@ -163,4 +163,11 @@ impl InitialMap { abstutil::write_binary(&path, self).expect(&format!("Saving {} failed", path)); println!("Saved {}", path); } + + pub fn merge( + &mut self, + r: StableRoadID, + ) { + merge::merge(self, r, &mut Timer::throwaway()); + } }