mirror of
https://github.com/a-b-street/abstreet.git
synced 2025-01-01 10:57:17 +03:00
debug_initialmap: highlight short roads, expose a way to manually merge
a short road
This commit is contained in:
parent
b1463cf020
commit
d9474494e7
@ -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<ID>,
|
||||
data: InitialMap,
|
||||
filename: String,
|
||||
// TODO Or, if these are common things, the World could also hold this state.
|
||||
selected: Option<ID>,
|
||||
@ -17,9 +20,13 @@ struct UI {
|
||||
}
|
||||
|
||||
impl UI {
|
||||
fn new(filename: &str, world: World<ID>) -> 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<String> = 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<ID> {
|
||||
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<ID> {
|
||||
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<ID> {
|
||||
.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<ID> {
|
||||
.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)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user