1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use crate::{AreaType, Map};
use geom::{LonLat, Polygon, Ring};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]
pub struct City {
pub name: String,
pub boundary: Polygon,
pub areas: Vec<(AreaType, Polygon)>,
pub regions: Vec<(String, Polygon)>,
}
impl City {
pub fn new(huge_map: &Map) -> City {
let mut regions = abstutil::list_all_objects(abstutil::path(format!(
"input/{}/polygons",
huge_map.get_city_name()
)))
.into_iter()
.map(|name| {
let pts = LonLat::read_osmosis_polygon(abstutil::path(format!(
"input/{}/polygons/{}.poly",
huge_map.get_city_name(),
name
)))
.unwrap();
(
name,
Ring::must_new(huge_map.get_gps_bounds().convert(&pts)).to_polygon(),
)
})
.collect::<Vec<_>>();
regions.sort_by_key(|(_, poly)| poly.get_bounds().width() as usize);
City {
name: huge_map.get_city_name().to_string(),
boundary: huge_map.get_boundary_polygon().clone(),
areas: huge_map
.all_areas()
.iter()
.map(|a| (a.area_type, a.polygon.clone()))
.collect(),
regions,
}
}
}