diff --git a/docs/development.md b/docs/development.md index 1b54c3fa41..a4b5c70f43 100644 --- a/docs/development.md +++ b/docs/development.md @@ -3,3 +3,5 @@ Find packages to upgrade: `cargo outdated -R` Diff screencaps: http://www.imagemagick.org/Usage/compare/#methods + +Cross-compilation: https://github.com/rust-embedded/cross diff --git a/editor/src/ui.rs b/editor/src/ui.rs index ffb193a64f..1816bccc32 100644 --- a/editor/src/ui.rs +++ b/editor/src/ui.rs @@ -235,8 +235,7 @@ impl GUI for UI { // TODO a plugin should do this, even though it's such a tiny thing if input.unimportant_key_pressed(Key::F1, "take screenshot") { let bounds = self.state.get_state().primary.map.get_bounds(); - assert_eq!(bounds.min_x, 0.0); - assert_eq!(bounds.min_y, 0.0); + assert!(bounds.min_x == 0.0 && bounds.min_y == 0.0); hints.mode = EventLoopMode::ScreenCaptureEverything { zoom: 3.0, max_x: bounds.max_x, diff --git a/ezgui/src/event.rs b/ezgui/src/event.rs index be30b67005..5daf54b022 100644 --- a/ezgui/src/event.rs +++ b/ezgui/src/event.rs @@ -74,7 +74,7 @@ impl Event { return Event::MouseWheelScroll(pair[1]); } if let Some(pair) = ev.resize_args() { - return Event::WindowResized(f64::from(pair[0]), f64::from(pair[1])); + return Event::WindowResized(pair[0], pair[1]); } if let Some(has) = ev.cursor_args() { if has { diff --git a/synthetic/src/main.rs b/synthetic/src/main.rs index 6c6501bc07..f73008ab95 100644 --- a/synthetic/src/main.rs +++ b/synthetic/src/main.rs @@ -26,7 +26,11 @@ enum State { impl UI { fn new(load: Option<&String>) -> UI { let model: Model = if let Some(path) = load { - abstutil::read_json(path).expect(&format!("Couldn't load {}", path)) + if path.contains("raw_maps/") { + Model::import(path) + } else { + abstutil::read_json(path).expect(&format!("Couldn't load {}", path)) + } } else { Model::new() }; diff --git a/synthetic/src/model.rs b/synthetic/src/model.rs index 993e093b8a..4fc3915605 100644 --- a/synthetic/src/model.rs +++ b/synthetic/src/model.rs @@ -1,10 +1,10 @@ -use abstutil::{deserialize_btreemap, serialize_btreemap, write_json}; +use abstutil::{deserialize_btreemap, read_binary, serialize_btreemap, write_json, Timer}; use dimensioned::si; use ezgui::{Canvas, Color, GfxCtx, Text}; -use geom::{Circle, LonLat, PolyLine, Polygon, Pt2D}; +use geom::{Circle, HashablePt2D, LonLat, PolyLine, Polygon, Pt2D}; use map_model::{raw_data, IntersectionType, LaneType, RoadSpec, LANE_THICKNESS}; use serde_derive::{Deserialize, Serialize}; -use std::collections::BTreeMap; +use std::collections::{BTreeMap, HashMap}; use std::mem; const INTERSECTION_RADIUS: f64 = 10.0; @@ -291,6 +291,67 @@ impl Model { abstutil::write_binary(&path, &map).expect(&format!("Saving {} failed", path)); println!("Exported {}", path); } + + // TODO Directly use raw_data and get rid of Model? Might be more maintainable long-term. + pub fn import(path: &str) -> Model { + let data: raw_data::Map = read_binary(path, &mut Timer::new("load raw map")).unwrap(); + let gps_bounds = data.get_gps_bounds(); + + let mut m = Model::new(); + let mut pt_to_intersection: HashMap = HashMap::new(); + + for (idx, i) in data.intersections.iter().enumerate() { + let center = Pt2D::from_gps(i.point, &gps_bounds).unwrap(); + m.intersections.insert( + idx, + Intersection { + center, + intersection_type: i.intersection_type, + label: i.label.clone(), + }, + ); + pt_to_intersection.insert(center.into(), idx); + } + + for r in &data.roads { + let i1 = pt_to_intersection[&Pt2D::from_gps(r.points[0], &gps_bounds).unwrap().into()]; + let i2 = pt_to_intersection[&Pt2D::from_gps(*r.points.last().unwrap(), &gps_bounds) + .unwrap() + .into()]; + m.roads.insert( + (i1, i2), + Road { + i1, + i2, + // TODO Do better + lanes: RoadSpec { + fwd: vec![LaneType::Driving, LaneType::Parking, LaneType::Sidewalk], + back: vec![LaneType::Driving, LaneType::Parking, LaneType::Sidewalk], + }, + // TODO nope + fwd_label: None, + back_label: None, + }, + ); + } + + for (idx, b) in data.buildings.iter().enumerate() { + m.buildings.insert( + idx, + Building { + label: None, + center: Pt2D::center( + &b.points + .iter() + .map(|pt| Pt2D::from_gps(*pt, &gps_bounds).unwrap()) + .collect(), + ), + }, + ); + } + + m + } } impl Model {