From 8faab3592a9afe5152b22b5e142e919f0d961817 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Tue, 22 Sep 2020 15:49:02 -0700 Subject: [PATCH] Refactor RawMap saving --- importer/src/berlin.rs | 3 +-- importer/src/krakow.rs | 3 +-- importer/src/london.rs | 3 +-- importer/src/main.rs | 7 ++----- importer/src/seattle.rs | 3 +-- importer/src/tel_aviv.rs | 3 +-- importer/src/xian.rs | 3 +-- map_model/src/raw.rs | 7 +++++++ 8 files changed, 15 insertions(+), 17 deletions(-) diff --git a/importer/src/berlin.rs b/importer/src/berlin.rs index 7b4d59d81d..00455d473e 100644 --- a/importer/src/berlin.rs +++ b/importer/src/berlin.rs @@ -79,8 +79,7 @@ pub fn osm_to_raw(name: &str, timer: &mut Timer, config: &ImporterConfiguration) }, timer, ); - let output = abstutil::path(format!("input/raw_maps/{}.bin", name)); - abstutil::write_binary(output, &map); + map.save(); } // Modify the filtered KML of planning areas with the number of residents from a different dataset. diff --git a/importer/src/krakow.rs b/importer/src/krakow.rs index cd32198514..590f934ef4 100644 --- a/importer/src/krakow.rs +++ b/importer/src/krakow.rs @@ -42,6 +42,5 @@ pub fn osm_to_raw(name: &str, timer: &mut abstutil::Timer, config: &ImporterConf }, timer, ); - let output = abstutil::path(format!("input/raw_maps/{}.bin", name)); - abstutil::write_binary(output, &map); + map.save(); } diff --git a/importer/src/london.rs b/importer/src/london.rs index 8e7c78af19..dd5c002c23 100644 --- a/importer/src/london.rs +++ b/importer/src/london.rs @@ -41,6 +41,5 @@ pub fn osm_to_raw(name: &str, timer: &mut abstutil::Timer, config: &ImporterConf }, timer, ); - let output = abstutil::path(format!("input/raw_maps/{}.bin", name)); - abstutil::write_binary(output, &map); + map.save(); } diff --git a/importer/src/main.rs b/importer/src/main.rs index 36a30b0110..bd80bb8801 100644 --- a/importer/src/main.rs +++ b/importer/src/main.rs @@ -225,11 +225,8 @@ fn oneshot(osm_path: String, clip: Option, drive_on_right: bool, build_c }, &mut timer, ); - - // Often helpful to save intermediate representation in case user - // wants to load into map_editor - abstutil::write_binary(abstutil::path_raw_map(&name), &raw); - + // Often helpful to save intermediate representation in case user wants to load into map_editor + raw.save(); let map = map_model::Map::create_from_raw(raw, build_ch, &mut timer); timer.start("save map"); map.save(); diff --git a/importer/src/seattle.rs b/importer/src/seattle.rs index 4ad06c91dc..695c3c0b5d 100644 --- a/importer/src/seattle.rs +++ b/importer/src/seattle.rs @@ -102,8 +102,7 @@ pub fn osm_to_raw(name: &str, timer: &mut abstutil::Timer, config: &ImporterConf }, timer, ); - let output = abstutil::path(format!("input/raw_maps/{}.bin", name)); - abstutil::write_binary(output, &map); + map.save(); } // Download and pre-process data needed to generate Seattle scenarios. diff --git a/importer/src/tel_aviv.rs b/importer/src/tel_aviv.rs index ae627ded00..5af060363c 100644 --- a/importer/src/tel_aviv.rs +++ b/importer/src/tel_aviv.rs @@ -41,6 +41,5 @@ pub fn osm_to_raw(name: &str, timer: &mut abstutil::Timer, config: &ImporterConf }, timer, ); - let output = abstutil::path(format!("input/raw_maps/{}.bin", name)); - abstutil::write_binary(output, &map); + map.save(); } diff --git a/importer/src/xian.rs b/importer/src/xian.rs index 58b8033f43..61c0d41426 100644 --- a/importer/src/xian.rs +++ b/importer/src/xian.rs @@ -38,6 +38,5 @@ pub fn osm_to_raw(name: &str, timer: &mut abstutil::Timer, config: &ImporterConf }, timer, ); - let output = abstutil::path(format!("input/raw_maps/{}.bin", name)); - abstutil::write_binary(output, &map); + map.save(); } diff --git a/map_model/src/raw.rs b/map_model/src/raw.rs index 227a81bd7e..050af0dea9 100644 --- a/map_model/src/raw.rs +++ b/map_model/src/raw.rs @@ -171,6 +171,13 @@ impl RawMap { debug, ) } + + pub fn save(&self) { + abstutil::write_binary( + abstutil::path(format!("input/raw_maps/{}.bin", self.name)), + self, + ) + } } // Mutations and supporting queries