diff --git a/convert_osm/src/lib.rs b/convert_osm/src/lib.rs index 19ab30f00a..331a09af20 100644 --- a/convert_osm/src/lib.rs +++ b/convert_osm/src/lib.rs @@ -77,8 +77,7 @@ pub fn convert(flags: &Flags, timer: &mut abstutil::Timer) -> raw_data::Map { if !flags.neighborhoods.is_empty() { timer.start("convert neighborhood polygons"); - let map_name = abstutil::basename(&flags.output); - neighborhoods::convert(&flags.neighborhoods, map_name, &map.gps_bounds); + neighborhoods::convert(&flags.neighborhoods, map.name.clone(), &map.gps_bounds); timer.stop("convert neighborhood polygons"); } diff --git a/convert_osm/src/osm.rs b/convert_osm/src/osm.rs index fd3731a9f4..380cc2c6c8 100644 --- a/convert_osm/src/osm.rs +++ b/convert_osm/src/osm.rs @@ -28,7 +28,7 @@ pub fn extract_osm( done(timer); let mut map = if maybe_clip_path.is_empty() { - let mut m = raw_data::Map::blank(); + let mut m = raw_data::Map::blank(abstutil::basename(osm_path)); for node in doc.nodes.values() { m.gps_bounds.update(LonLat::new(node.lon, node.lat)); } @@ -344,7 +344,7 @@ fn read_osmosis_polygon(path: &str) -> raw_data::Map { gps_bounds.update(pt); } - let mut map = raw_data::Map::blank(); + let mut map = raw_data::Map::blank(abstutil::basename(path)); map.boundary_polygon = Polygon::new(&gps_bounds.must_convert(&pts)); map.gps_bounds = gps_bounds; map diff --git a/fix_map_geom/src/main.rs b/fix_map_geom/src/main.rs index e392570706..6228fc9567 100644 --- a/fix_map_geom/src/main.rs +++ b/fix_map_geom/src/main.rs @@ -50,8 +50,12 @@ impl UI { fn new(filename: &str, ctx: &mut EventCtx) -> UI { ctx.loading_screen(&format!("load {}", filename), |ctx, mut timer| { let raw: Map = abstutil::read_binary(filename, &mut timer).unwrap(); - let map_name = abstutil::basename(filename); - let mut data = InitialMap::new(map_name, &raw, &raw.gps_bounds.to_bounds(), &mut timer); + let mut data = InitialMap::new( + raw.name.clone(), + &raw, + &raw.gps_bounds.to_bounds(), + &mut timer, + ); let hints = Hints::load(); data.apply_hints(&hints, &raw, &mut timer); @@ -121,7 +125,10 @@ impl GUI for UI { let r2_tags = &self.raw.roads[iter.next().unwrap()].osm_tags; for (k, v1) in r1_tags { - let v2 = r2_tags.get(k).cloned().unwrap_or("MISSING".to_string()); + let v2 = r2_tags + .get(k) + .cloned() + .unwrap_or_else(|| "MISSING".to_string()); if *v1 != v2 { txt.add_appended(vec![ Line(k).fg(Color::RED), diff --git a/map_model/src/map.rs b/map_model/src/map.rs index d3c6283690..39cfe7ef34 100644 --- a/map_model/src/map.rs +++ b/map_model/src/map.rs @@ -55,7 +55,7 @@ impl Map { data.apply_fixes(&raw_data::MapFixes::load(), timer); // Do this after applying fixes, which might split off pieces of the map. make::remove_disconnected_roads(&mut data, timer); - Ok(Map::create_from_raw(abstutil::basename(path), data, timer)) + Ok(Map::create_from_raw(data, timer)) } // Just for temporary std::mem::replace tricks. @@ -86,11 +86,11 @@ impl Map { } } - pub fn create_from_raw(name: String, data: raw_data::Map, timer: &mut Timer) -> Map { + fn create_from_raw(data: raw_data::Map, timer: &mut Timer) -> Map { timer.start("raw_map to InitialMap"); let gps_bounds = data.gps_bounds.clone(); let bounds = gps_bounds.to_bounds(); - let mut initial_map = make::InitialMap::new(name.clone(), &data, &bounds, timer); + let mut initial_map = make::InitialMap::new(data.name.clone(), &data, &bounds, timer); let hints = raw_data::Hints::load(); initial_map.apply_hints(&hints, &data, timer); timer.stop("raw_map to InitialMap"); @@ -117,8 +117,8 @@ impl Map { turn_lookup: half_map.turn_lookup, pathfinder: None, pathfinder_dirty: false, - name: name.clone(), - edits: MapEdits::new(name), + name: data.name.clone(), + edits: MapEdits::new(data.name), }; // Extra setup that's annoying to do as HalfMap, since we want to pass around a Map. diff --git a/map_model/src/raw_data.rs b/map_model/src/raw_data.rs index 523db550be..9c3072133e 100644 --- a/map_model/src/raw_data.rs +++ b/map_model/src/raw_data.rs @@ -27,6 +27,7 @@ impl fmt::Display for StableIntersectionID { #[derive(Debug, Serialize, Deserialize)] pub struct Map { + pub name: String, pub roads: BTreeMap, pub intersections: BTreeMap, pub buildings: Vec, @@ -40,8 +41,9 @@ pub struct Map { } impl Map { - pub fn blank() -> Map { + pub fn blank(name: String) -> Map { Map { + name, roads: BTreeMap::new(), intersections: BTreeMap::new(), buildings: Vec::new(), diff --git a/synthetic/src/model.rs b/synthetic/src/model.rs index 33b8399675..b2fb480c4a 100644 --- a/synthetic/src/model.rs +++ b/synthetic/src/model.rs @@ -210,7 +210,7 @@ impl Model { // Returns path to raw map pub fn export(&self) -> String { - let mut map = raw_data::Map::blank(); + let mut map = raw_data::Map::blank(self.name.clone().expect("Model hasn't been named yet")); for (id, r) in &self.roads { let mut osm_tags = BTreeMap::new(); @@ -267,7 +267,7 @@ impl Model { map.gps_bounds = self.gps_bounds.clone(); map.boundary_polygon = self.compute_bounds().get_rectangle(); - let path = abstutil::path_raw_map(self.name.as_ref().expect("Model hasn't been named yet")); + let path = abstutil::path_raw_map(&map.name); abstutil::write_binary(&path, &map).expect(&format!("Saving {} failed", path)); println!("Exported {}", path); path @@ -286,7 +286,7 @@ impl Model { let mut data: raw_data::Map = read_binary(path, &mut timer).unwrap(); data.apply_fixes(&m.fixes, &mut timer); - m.name = Some(abstutil::basename(path)); + m.name = Some(data.name.clone()); m.gps_bounds = data.gps_bounds.clone(); for (id, raw_i) in &data.intersections { @@ -315,7 +315,7 @@ impl Model { .osm_tags .get(k) .cloned() - .unwrap_or("MISSING".to_string()); + .unwrap_or_else(|| "MISSING".to_string()); println!(" {} = {} / {}", k, v1, v2); } for (k, v2) in &other.osm_tags {