From 360870a72cffef01a34b99136b3866a6955432bd Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Sun, 12 Jun 2022 16:35:11 +0100 Subject: [PATCH] Refactor convert_osm::Options default settings --- convert_osm/src/lib.rs | 23 +++++++++++++++++++++++ importer/src/lib.rs | 23 +++-------------------- tests/src/main.rs | 21 ++------------------- 3 files changed, 28 insertions(+), 39 deletions(-) diff --git a/convert_osm/src/lib.rs b/convert_osm/src/lib.rs index ab625c9696..e040747f36 100644 --- a/convert_osm/src/lib.rs +++ b/convert_osm/src/lib.rs @@ -43,6 +43,29 @@ pub struct Options { pub elevation: bool, } +impl Options { + pub fn default_for_side(driving_side: raw_map::DrivingSide) -> Self { + Self { + map_config: MapConfig { + driving_side, + bikes_can_use_bus_lanes: true, + inferred_sidewalks: true, + street_parking_spot_length: Distance::meters(8.0), + turn_on_red: true, + }, + onstreet_parking: OnstreetParking::JustOSM, + public_offstreet_parking: PublicOffstreetParking::None, + private_offstreet_parking: PrivateOffstreetParking::FixedPerBldg(1), + include_railroads: true, + extra_buildings: None, + skip_local_roads: false, + filter_crosswalks: false, + gtfs_url: None, + elevation: false, + } + } +} + /// What roads will have on-street parking lanes? Data from /// is always used if available. #[derive(Clone, Serialize, Deserialize)] diff --git a/importer/src/lib.rs b/importer/src/lib.rs index 119b9f30f8..bbd5df2492 100644 --- a/importer/src/lib.rs +++ b/importer/src/lib.rs @@ -13,7 +13,6 @@ use structopt::StructOpt; use abstio::{CityName, MapName}; use abstutil::Timer; -use geom::Distance; use map_model::RawToMapOptions; use self::configuration::{load_configuration, ImporterConfiguration}; @@ -58,29 +57,13 @@ pub async fn oneshot( let mut timer = abstutil::Timer::new("oneshot"); println!("- Running convert_osm on {}", osm_path); let name = abstutil::basename(&osm_path); + let mut options = convert_osm::Options::default_for_side(driving_side); + options.filter_crosswalks = filter_crosswalks; let raw = convert_osm::convert( osm_path, MapName::new("zz", "oneshot", &name), clip, - convert_osm::Options { - map_config: map_model::MapConfig { - driving_side, - bikes_can_use_bus_lanes: true, - inferred_sidewalks: true, - street_parking_spot_length: Distance::meters(8.0), - turn_on_red: true, - }, - - onstreet_parking: convert_osm::OnstreetParking::JustOSM, - public_offstreet_parking: convert_osm::PublicOffstreetParking::None, - private_offstreet_parking: convert_osm::PrivateOffstreetParking::FixedPerBldg(1), - include_railroads: true, - extra_buildings: None, - skip_local_roads: false, - filter_crosswalks, - gtfs_url: None, - elevation: false, - }, + options, &mut timer, ); // Often helpful to save intermediate representation in case user wants to load into map_editor diff --git a/tests/src/main.rs b/tests/src/main.rs index 086ca305d5..cefa796bec 100644 --- a/tests/src/main.rs +++ b/tests/src/main.rs @@ -8,7 +8,7 @@ use rand::seq::SliceRandom; use abstio::{CityName, MapName}; use abstutil::Timer; -use geom::{Distance, Duration, Time}; +use geom::{Duration, Time}; use map_model::{IntersectionID, LaneType, Map, Perimeter, RoadID}; use sim::{AlertHandler, PrebakeSummary, Sim, SimFlags, SimOptions}; use synthpop::{IndividTrip, PersonSpec, Scenario, TripEndpoint, TripMode, TripPurpose}; @@ -59,24 +59,7 @@ fn import_map(path: String) -> Map { path, name, clip, - convert_osm::Options { - map_config: map_model::MapConfig { - driving_side: map_model::DrivingSide::Right, - bikes_can_use_bus_lanes: true, - inferred_sidewalks: true, - street_parking_spot_length: Distance::meters(8.0), - turn_on_red: false, - }, - onstreet_parking: convert_osm::OnstreetParking::JustOSM, - public_offstreet_parking: convert_osm::PublicOffstreetParking::None, - private_offstreet_parking: convert_osm::PrivateOffstreetParking::FixedPerBldg(0), - include_railroads: true, - extra_buildings: None, - skip_local_roads: false, - filter_crosswalks: false, - gtfs_url: None, - elevation: false, - }, + convert_osm::Options::default_for_side(map_model::DrivingSide::Right), &mut timer, ); Map::create_from_raw(raw, map_model::RawToMapOptions::default(), &mut timer)