diff --git a/convert_osm/src/remove_disconnected.rs b/convert_osm/src/remove_disconnected.rs index aed397f0c3..62c3703527 100644 --- a/convert_osm/src/remove_disconnected.rs +++ b/convert_osm/src/remove_disconnected.rs @@ -55,8 +55,8 @@ pub fn remove_disconnected_roads(map: &mut raw_data::Map, timer: &mut Timer) { let mut roads: Vec = Vec::new(); for (idx, r) in map.roads.iter().enumerate() { if remove_roads.contains(&idx) { - next_roads.remove(r.first_pt(), idx); - next_roads.remove(r.last_pt(), idx); + next_roads.remove(r.first_pt().to_hashable(), idx); + next_roads.remove(r.last_pt().to_hashable(), idx); } else { roads.push(r.clone()); } diff --git a/map_model/src/edits.rs b/map_model/src/edits.rs index 89dde1870e..18107d2b23 100644 --- a/map_model/src/edits.rs +++ b/map_model/src/edits.rs @@ -1,3 +1,4 @@ +use abstutil::{deserialize_btreemap, serialize_btreemap}; use std::collections::BTreeMap; use {Lane, LaneType, Road, RoadID}; @@ -7,6 +8,10 @@ use {Lane, LaneType, Road, RoadID}; pub struct RoadEdits { pub edits_name: String, // TODO detect when we wind up editing back to the original thing + #[serde( + serialize_with = "serialize_btreemap", + deserialize_with = "deserialize_btreemap" + )] pub(crate) roads: BTreeMap, } diff --git a/map_model/src/map.rs b/map_model/src/map.rs index 16a79bf73a..b34b878a54 100644 --- a/map_model/src/map.rs +++ b/map_model/src/map.rs @@ -1,7 +1,7 @@ // Copyright 2018 Google LLC, licensed under http://www.apache.org/licenses/LICENSE-2.0 use abstutil; -use abstutil::{Error, Timer}; +use abstutil::{deserialize_btreemap, serialize_btreemap, Error, Timer}; use edits::RoadEdits; use geom::{Bounds, GPSBounds, HashablePt2D, PolyLine, Pt2D}; use make; @@ -20,9 +20,17 @@ pub struct Map { roads: Vec, lanes: Vec, intersections: Vec, + #[serde( + serialize_with = "serialize_btreemap", + deserialize_with = "deserialize_btreemap" + )] turns: BTreeMap, buildings: Vec, parcels: Vec, + #[serde( + serialize_with = "serialize_btreemap", + deserialize_with = "deserialize_btreemap" + )] bus_stops: BTreeMap, bus_routes: Vec, areas: Vec, diff --git a/tests/src/map_conversion.rs b/tests/src/map_conversion.rs index bd2cb9900b..6742bd97f8 100644 --- a/tests/src/map_conversion.rs +++ b/tests/src/map_conversion.rs @@ -1,10 +1,11 @@ use abstutil; use convert_osm; +use map_model; use runner::TestRunner; pub fn run(t: &mut TestRunner) { t.run_slow( - "convert_twice", + "convert_osm_twice", Box::new(|_| { let flags = convert_osm::Flags { osm: "../data/input/montlake.osm".to_string(), @@ -14,7 +15,7 @@ pub fn run(t: &mut TestRunner) { parking_shapes: "../data/shapes/blockface".to_string(), gtfs: "../data/input/google_transit_2018_18_08".to_string(), neighborhoods: "../data/input/neighborhoods.geojson".to_string(), - output: "convert_twice".to_string(), + output: "convert_osm_twice".to_string(), }; let map1 = convert_osm::convert(&flags, &mut abstutil::Timer::new("convert map")); @@ -28,4 +29,27 @@ pub fn run(t: &mut TestRunner) { } }), ); + + t.run_slow( + "raw_to_map_twice", + Box::new(|_| { + let map1 = map_model::Map::new( + "../data/raw_maps/montlake.abst", + map_model::RoadEdits::new(), + &mut abstutil::Timer::new("raw to map"), + ).unwrap(); + let map2 = map_model::Map::new( + "../data/raw_maps/montlake.abst", + map_model::RoadEdits::new(), + &mut abstutil::Timer::new("raw to map"), + ).unwrap(); + + if abstutil::to_json(&map1) != abstutil::to_json(&map2) { + // TODO tmp files + abstutil::write_json("map1.json", &map1).unwrap(); + abstutil::write_json("map2.json", &map2).unwrap(); + panic!("map1.json and map2.json differ"); + } + }), + ); }