diff --git a/editor/src/ui.rs b/editor/src/ui.rs index 30c73ba70f..a1f6bff180 100644 --- a/editor/src/ui.rs +++ b/editor/src/ui.rs @@ -92,6 +92,7 @@ impl UI { kml: Option, window_size: Size, ) -> UI { + flame::start("setup"); let (map, edits, control_map, sim) = sim::load( load, scenario_name, @@ -109,6 +110,7 @@ impl UI { let (draw_map, center_pt) = render::DrawMap::new(&map, &control_map, extra_shapes); flame::end("draw_map"); + flame::end("setup"); flame::dump_stdout(); let steepness_viz = SteepnessVisualizer::new(&map); diff --git a/geom/src/pt.rs b/geom/src/pt.rs index d0f07f230b..44104fc781 100644 --- a/geom/src/pt.rs +++ b/geom/src/pt.rs @@ -85,6 +85,12 @@ impl fmt::Display for Pt2D { } } +impl From for Pt2D { + fn from(pt: HashablePt2D) -> Self { + Pt2D::new(pt.x(), pt.y()) + } +} + // This isn't opinionated about what the (x, y) represents -- could be lat/lon or world space. #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)] pub struct HashablePt2D { diff --git a/map_model/src/make/buildings.rs b/map_model/src/make/buildings.rs index 12192b4711..e37f901dc6 100644 --- a/map_model/src/make/buildings.rs +++ b/map_model/src/make/buildings.rs @@ -5,25 +5,48 @@ use raw_data; use std::collections::HashSet; use {Building, BuildingID, FrontPath, Lane}; -pub(crate) fn make_building( - b: &raw_data::Building, - id: BuildingID, +pub(crate) fn make_all_buildings( + results: &mut Vec, + input: &Vec, bounds: &Bounds, lanes: &Vec, -) -> Building { - // TODO consume data, so we dont have to clone tags? - let points = b.points - .iter() - .map(|coord| Pt2D::from_gps(coord, bounds)) - .collect(); - let front_path = find_front_path(id, &points, lanes); +) { + let mut pts_per_bldg: Vec> = Vec::new(); + let mut center_per_bldg: Vec = Vec::new(); + let mut query: HashSet = HashSet::new(); + for b in input { + let pts = b.points + .iter() + .map(|coord| Pt2D::from_gps(coord, bounds)) + .collect(); + let center: HashablePt2D = geometry::center(&pts).into(); + pts_per_bldg.push(pts); + center_per_bldg.push(center); + query.insert(center); + } - Building { - points, - front_path, - id, - osm_way_id: b.osm_way_id, - osm_tags: b.osm_tags.clone(), + let sidewalk_pts = find_sidewalk_points(query, lanes); + + for (idx, points) in pts_per_bldg.into_iter().enumerate() { + let id = BuildingID(idx); + + let bldg_center = center_per_bldg[idx]; + let (sidewalk, dist_along) = sidewalk_pts[&bldg_center]; + let (sidewalk_pt, _) = lanes[sidewalk.0].dist_along(dist_along); + let line = trim_front_path(&points, Line::new(bldg_center.into(), sidewalk_pt)); + + results.push(Building { + id, + points, + osm_tags: input[idx].osm_tags.clone(), + osm_way_id: input[idx].osm_way_id, + front_path: FrontPath { + bldg: id, + sidewalk: sidewalk, + line, + dist_along_sidewalk: dist_along, + }, + }); } } @@ -37,20 +60,3 @@ fn trim_front_path(bldg_points: &Vec, path: Line) -> Line { path } } - -fn find_front_path(bldg: BuildingID, bldg_points: &Vec, lanes: &Vec) -> FrontPath { - let bldg_center = geometry::center(bldg_points); - let mut query: HashSet = HashSet::new(); - query.insert(bldg_center.into()); - let sidewalk_pts = find_sidewalk_points(query, lanes); - let (sidewalk, dist_along) = sidewalk_pts.values().next().unwrap(); - let (sidewalk_pt, _) = lanes[sidewalk.0].dist_along(*dist_along); - let line = trim_front_path(bldg_points, Line::new(bldg_center, sidewalk_pt)); - - FrontPath { - bldg, - sidewalk: *sidewalk, - line, - dist_along_sidewalk: *dist_along, - } -} diff --git a/map_model/src/make/mod.rs b/map_model/src/make/mod.rs index 80033b2c19..60027f5754 100644 --- a/map_model/src/make/mod.rs +++ b/map_model/src/make/mod.rs @@ -5,7 +5,7 @@ mod sidewalk_finder; mod trim_lines; mod turns; -pub(crate) use self::buildings::make_building; +pub(crate) use self::buildings::make_all_buildings; pub(crate) use self::bus_stops::make_bus_stops; pub(crate) use self::lanes::get_lane_specs; pub(crate) use self::trim_lines::trim_lines; diff --git a/map_model/src/map.rs b/map_model/src/map.rs index 8a8dc0abbe..3052954fe5 100644 --- a/map_model/src/map.rs +++ b/map_model/src/map.rs @@ -172,11 +172,9 @@ impl Map { { let _guard = flame::start_guard(format!("make {} buildings", data.buildings.len())); - for (idx, b) in data.buildings.iter().enumerate() { - let id = BuildingID(idx); - let bldg = make::make_building(b, id, &bounds, &m.lanes); - m.lanes[bldg.front_path.sidewalk.0].building_paths.push(id); - m.buildings.push(bldg); + make::make_all_buildings(&mut m.buildings, &data.buildings, &bounds, &m.lanes); + for b in &m.buildings { + m.lanes[b.front_path.sidewalk.0].building_paths.push(b.id); } }