mirror of
https://github.com/a-b-street/abstreet.git
synced 2025-01-04 04:23:25 +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 abstutil::{find_next_file, find_prev_file, read_binary, Timer};
|
||||||
use ezgui::{Color, EventCtx, EventLoopMode, GfxCtx, Key, Text, GUI};
|
use ezgui::{Color, EventCtx, EventLoopMode, GfxCtx, Key, Text, GUI};
|
||||||
use geom::{Distance, Polygon};
|
use geom::{Distance, Polygon};
|
||||||
use map_model::raw_data;
|
use map_model::raw_data::{StableIntersectionID, StableRoadID, InitialMap};
|
||||||
use map_model::raw_data::{StableIntersectionID, StableRoadID};
|
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::{env, process};
|
use std::{env, process};
|
||||||
use viewer::World;
|
use viewer::World;
|
||||||
|
|
||||||
|
// Bit bigger than buses
|
||||||
|
const MIN_ROAD_LENGTH: Distance = Distance::const_meters(13.0);
|
||||||
|
|
||||||
struct UI {
|
struct UI {
|
||||||
world: World<ID>,
|
world: World<ID>,
|
||||||
|
data: InitialMap,
|
||||||
filename: String,
|
filename: String,
|
||||||
// TODO Or, if these are common things, the World could also hold this state.
|
// TODO Or, if these are common things, the World could also hold this state.
|
||||||
selected: Option<ID>,
|
selected: Option<ID>,
|
||||||
@ -17,9 +20,13 @@ struct UI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl 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 {
|
UI {
|
||||||
world,
|
world,
|
||||||
|
data,
|
||||||
filename: filename.to_string(),
|
filename: filename.to_string(),
|
||||||
selected: None,
|
selected: None,
|
||||||
hide: HashSet::new(),
|
hide: HashSet::new(),
|
||||||
@ -28,7 +35,9 @@ impl UI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn load_different(&mut self, filename: String, ctx: &mut EventCtx) {
|
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.selected = None;
|
||||||
self.filename = filename;
|
self.filename = filename;
|
||||||
self.hide.clear();
|
self.hide.clear();
|
||||||
@ -64,6 +73,13 @@ impl GUI for UI {
|
|||||||
self.selected = None;
|
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 !self.hide.is_empty() {
|
||||||
if ctx.input.key_pressed(Key::K, "unhide everything") {
|
if ctx.input.key_pressed(Key::K, "unhide everything") {
|
||||||
self.hide.clear();
|
self.hide.clear();
|
||||||
@ -92,7 +108,7 @@ fn main() {
|
|||||||
let args: Vec<String> = env::args().collect();
|
let args: Vec<String> = env::args().collect();
|
||||||
ezgui::run("InitialMap debugger", 1024.0, 768.0, |ctx| {
|
ezgui::run("InitialMap debugger", 1024.0, 768.0, |ctx| {
|
||||||
ctx.canvas.cam_zoom = 4.0;
|
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> {
|
fn initial_map_to_world(data: &InitialMap, ctx: &mut EventCtx) -> World<ID> {
|
||||||
let data: raw_data::InitialMap =
|
|
||||||
read_binary(filename, &mut Timer::new("load InitialMap")).unwrap();
|
|
||||||
|
|
||||||
let mut w = World::new(&data.bounds);
|
let mut w = World::new(&data.bounds);
|
||||||
|
|
||||||
for r in data.roads.values() {
|
for r in data.roads.values() {
|
||||||
|
let len = r.trimmed_center_pts.length();
|
||||||
if r.fwd_width > Distance::ZERO {
|
if r.fwd_width > Distance::ZERO {
|
||||||
w.add_obj(
|
w.add_obj(
|
||||||
ctx.prerender,
|
ctx.prerender,
|
||||||
@ -127,12 +141,12 @@ fn load_initial_map(filename: &str, ctx: &mut EventCtx) -> World<ID> {
|
|||||||
.shift_right(r.fwd_width / 2.0)
|
.shift_right(r.fwd_width / 2.0)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.make_polygons(r.fwd_width),
|
.make_polygons(r.fwd_width),
|
||||||
Color::grey(0.8),
|
if len < MIN_ROAD_LENGTH {
|
||||||
Text::from_line(format!(
|
Color::CYAN
|
||||||
"{} forwards, {} long",
|
} else {
|
||||||
r.id,
|
Color::grey(0.8)
|
||||||
r.trimmed_center_pts.length()
|
},
|
||||||
)),
|
Text::from_line(format!("{} forwards, {} long", r.id, len)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if r.back_width > Distance::ZERO {
|
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)
|
.shift_left(r.back_width / 2.0)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.make_polygons(r.back_width),
|
.make_polygons(r.back_width),
|
||||||
Color::grey(0.6),
|
if len < MIN_ROAD_LENGTH {
|
||||||
Text::from_line(format!(
|
Color::GREEN
|
||||||
"{} backwards, {} long",
|
} else {
|
||||||
r.id,
|
Color::grey(0.6)
|
||||||
r.trimmed_center_pts.length()
|
},
|
||||||
)),
|
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.
|
// Returns the retained intersection.
|
||||||
fn merge(
|
pub fn merge(
|
||||||
map: &mut InitialMap,
|
map: &mut InitialMap,
|
||||||
merge_road: StableRoadID,
|
merge_road: StableRoadID,
|
||||||
timer: &mut Timer,
|
timer: &mut Timer,
|
||||||
|
@ -163,4 +163,11 @@ impl InitialMap {
|
|||||||
abstutil::write_binary(&path, self).expect(&format!("Saving {} failed", path));
|
abstutil::write_binary(&path, self).expect(&format!("Saving {} failed", path));
|
||||||
println!("Saved {}", 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