From 70cfcc9b4519c302f691f9fcceb1176ded1ae9a7 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Thu, 21 Feb 2019 09:54:28 -0800 Subject: [PATCH] convert all synthetic maps during precompute.sh; they keep getting out of sync with map format changes --- editor/src/plugins/sim/even_simpler_model.rs | 4 ++-- editor/src/ui.rs | 4 +++- geom/src/gps.rs | 9 +++++++++ precompute.sh | 6 ++++++ precompute/Cargo.toml | 1 + precompute/src/main.rs | 10 +++++++++- synthetic/src/{model.rs => lib.rs} | 8 +++++++- synthetic/src/main.rs | 4 +--- 8 files changed, 38 insertions(+), 8 deletions(-) rename synthetic/src/{model.rs => lib.rs} (98%) diff --git a/editor/src/plugins/sim/even_simpler_model.rs b/editor/src/plugins/sim/even_simpler_model.rs index 4c95859e39..f9c75be93f 100644 --- a/editor/src/plugins/sim/even_simpler_model.rs +++ b/editor/src/plugins/sim/even_simpler_model.rs @@ -162,7 +162,7 @@ fn populate_world(start: LaneID, map: &Map) -> new_des_model::World { vehicle_len, max_speed, path.clone(), - Duration::seconds(1.0) * (i as f64), + Duration::seconds(1.0) * f64::from(i), rand_dist(&mut rng, vehicle_len, len), rand_dist( &mut rng, @@ -205,7 +205,7 @@ fn densely_populate_world(map: &Map) -> new_des_model::World { vehicle_len, max_speed, path, - Duration::seconds(1.0) * (i as f64), + Duration::seconds(1.0) * f64::from(i), rand_dist(&mut rng, vehicle_len, len), rand_dist(&mut rng, Distance::ZERO, map.get_l(last_lane).length()), map, diff --git a/editor/src/ui.rs b/editor/src/ui.rs index 37b0a75c43..29333830d2 100644 --- a/editor/src/ui.rs +++ b/editor/src/ui.rs @@ -234,7 +234,9 @@ impl GUI for UI { ctx.input.populate_osd(&mut hints.osd); // TODO a plugin should do this, even though it's such a tiny thing - if ctx.input.action_chosen("screenshot everything") { + if self.state.get_state().enable_debug_controls + && ctx.input.action_chosen("screenshot everything") + { let bounds = self.state.get_state().primary.map.get_bounds(); assert!(bounds.min_x == 0.0 && bounds.min_y == 0.0); hints.mode = EventLoopMode::ScreenCaptureEverything { diff --git a/geom/src/gps.rs b/geom/src/gps.rs index 10f2d0afa1..5eb20d2e61 100644 --- a/geom/src/gps.rs +++ b/geom/src/gps.rs @@ -110,6 +110,15 @@ impl GPSBounds { } } + pub fn get_corners(&self) -> Vec { + vec![ + LonLat::new(self.min_lon, self.min_lat), + LonLat::new(self.max_lon, self.min_lat), + LonLat::new(self.max_lon, self.max_lat), + LonLat::new(self.min_lon, self.max_lat), + ] + } + // TODO cache this pub fn get_max_world_pt(&self) -> Pt2D { let width = LonLat::new(self.min_lon, self.min_lat) diff --git a/precompute.sh b/precompute.sh index f301b215a2..8541c589b7 100755 --- a/precompute.sh +++ b/precompute.sh @@ -33,3 +33,9 @@ for map_path in `ls data/raw_maps/`; do done fi done + +# Re-export all synthetic maps from scratch. +cd precompute; +for path in `ls ../data/synthetic_maps/*`; do + RUST_BACKTRACE=1 cargo run $release_mode $path --edits_name=no_edits; +done diff --git a/precompute/Cargo.toml b/precompute/Cargo.toml index 4c0a7b3534..93098ba15b 100644 --- a/precompute/Cargo.toml +++ b/precompute/Cargo.toml @@ -8,3 +8,4 @@ edition = "2018" abstutil = { path = "../abstutil" } map_model = { path = "../map_model" } structopt = "0.2" +synthetic = { path = "../synthetic" } diff --git a/precompute/src/main.rs b/precompute/src/main.rs index c2a542addb..dce5db4aac 100644 --- a/precompute/src/main.rs +++ b/precompute/src/main.rs @@ -31,7 +31,15 @@ fn main() { .unwrap() }; - let map = Map::new(&flags.load, edits, &mut timer).unwrap(); + let raw_map_path = if flags.load.contains("synthetic") { + let model: synthetic::Model = + abstutil::read_json(&flags.load).expect(&format!("Couldn't load {}", &flags.load)); + model.export() + } else { + flags.load + }; + + let map = Map::new(&raw_map_path, edits, &mut timer).unwrap(); timer.start("save map"); map.save(); timer.stop("save map"); diff --git a/synthetic/src/model.rs b/synthetic/src/lib.rs similarity index 98% rename from synthetic/src/model.rs rename to synthetic/src/lib.rs index baebe8b136..f77bfb3009 100644 --- a/synthetic/src/model.rs +++ b/synthetic/src/lib.rs @@ -309,7 +309,8 @@ impl Model { println!("Saved {}", path); } - pub fn export(&self) { + // Returns path to raw map + pub fn export(&self) -> String { let mut map = raw_data::Map::blank(); map.coordinates_in_world_space = true; @@ -369,12 +370,17 @@ impl Model { }); } + map.boundary_polygon = map.get_gps_bounds().get_corners(); + // Close off the polygon + map.boundary_polygon.push(map.boundary_polygon[3]); + let path = format!( "../data/raw_maps/{}.abst", self.name.as_ref().expect("Model hasn't been named yet") ); abstutil::write_binary(&path, &map).expect(&format!("Saving {} failed", path)); println!("Exported {}", path); + path } // TODO Directly use raw_data and get rid of Model? Might be more maintainable long-term. diff --git a/synthetic/src/main.rs b/synthetic/src/main.rs index fe40f31b83..3be8b2967a 100644 --- a/synthetic/src/main.rs +++ b/synthetic/src/main.rs @@ -1,11 +1,9 @@ -mod model; - -use crate::model::{BuildingID, Direction, Model, ID}; use aabb_quadtree::QuadTree; use ezgui::{Color, EventCtx, EventLoopMode, GfxCtx, Key, Text, Wizard, GUI}; use geom::{Distance, Line}; use map_model::raw_data::{StableIntersectionID, StableRoadID}; use std::{env, process}; +use synthetic::{BuildingID, Direction, Model, ID}; struct UI { model: Model,