mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-26 07:52:05 +03:00
speed up building creation by doing sidewalk finding in bulk
This commit is contained in:
parent
630f6504f4
commit
f3982282de
@ -92,6 +92,7 @@ impl UI {
|
|||||||
kml: Option<String>,
|
kml: Option<String>,
|
||||||
window_size: Size,
|
window_size: Size,
|
||||||
) -> UI {
|
) -> UI {
|
||||||
|
flame::start("setup");
|
||||||
let (map, edits, control_map, sim) = sim::load(
|
let (map, edits, control_map, sim) = sim::load(
|
||||||
load,
|
load,
|
||||||
scenario_name,
|
scenario_name,
|
||||||
@ -109,6 +110,7 @@ impl UI {
|
|||||||
let (draw_map, center_pt) = render::DrawMap::new(&map, &control_map, extra_shapes);
|
let (draw_map, center_pt) = render::DrawMap::new(&map, &control_map, extra_shapes);
|
||||||
flame::end("draw_map");
|
flame::end("draw_map");
|
||||||
|
|
||||||
|
flame::end("setup");
|
||||||
flame::dump_stdout();
|
flame::dump_stdout();
|
||||||
|
|
||||||
let steepness_viz = SteepnessVisualizer::new(&map);
|
let steepness_viz = SteepnessVisualizer::new(&map);
|
||||||
|
@ -85,6 +85,12 @@ impl fmt::Display for Pt2D {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<HashablePt2D> 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.
|
// 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)]
|
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
|
||||||
pub struct HashablePt2D {
|
pub struct HashablePt2D {
|
||||||
|
@ -5,25 +5,48 @@ use raw_data;
|
|||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use {Building, BuildingID, FrontPath, Lane};
|
use {Building, BuildingID, FrontPath, Lane};
|
||||||
|
|
||||||
pub(crate) fn make_building(
|
pub(crate) fn make_all_buildings(
|
||||||
b: &raw_data::Building,
|
results: &mut Vec<Building>,
|
||||||
id: BuildingID,
|
input: &Vec<raw_data::Building>,
|
||||||
bounds: &Bounds,
|
bounds: &Bounds,
|
||||||
lanes: &Vec<Lane>,
|
lanes: &Vec<Lane>,
|
||||||
) -> Building {
|
) {
|
||||||
// TODO consume data, so we dont have to clone tags?
|
let mut pts_per_bldg: Vec<Vec<Pt2D>> = Vec::new();
|
||||||
let points = b.points
|
let mut center_per_bldg: Vec<HashablePt2D> = Vec::new();
|
||||||
|
let mut query: HashSet<HashablePt2D> = HashSet::new();
|
||||||
|
for b in input {
|
||||||
|
let pts = b.points
|
||||||
.iter()
|
.iter()
|
||||||
.map(|coord| Pt2D::from_gps(coord, bounds))
|
.map(|coord| Pt2D::from_gps(coord, bounds))
|
||||||
.collect();
|
.collect();
|
||||||
let front_path = find_front_path(id, &points, lanes);
|
let center: HashablePt2D = geometry::center(&pts).into();
|
||||||
|
pts_per_bldg.push(pts);
|
||||||
|
center_per_bldg.push(center);
|
||||||
|
query.insert(center);
|
||||||
|
}
|
||||||
|
|
||||||
Building {
|
let sidewalk_pts = find_sidewalk_points(query, lanes);
|
||||||
points,
|
|
||||||
front_path,
|
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,
|
id,
|
||||||
osm_way_id: b.osm_way_id,
|
points,
|
||||||
osm_tags: b.osm_tags.clone(),
|
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<Pt2D>, path: Line) -> Line {
|
|||||||
path
|
path
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_front_path(bldg: BuildingID, bldg_points: &Vec<Pt2D>, lanes: &Vec<Lane>) -> FrontPath {
|
|
||||||
let bldg_center = geometry::center(bldg_points);
|
|
||||||
let mut query: HashSet<HashablePt2D> = 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,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -5,7 +5,7 @@ mod sidewalk_finder;
|
|||||||
mod trim_lines;
|
mod trim_lines;
|
||||||
mod turns;
|
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::bus_stops::make_bus_stops;
|
||||||
pub(crate) use self::lanes::get_lane_specs;
|
pub(crate) use self::lanes::get_lane_specs;
|
||||||
pub(crate) use self::trim_lines::trim_lines;
|
pub(crate) use self::trim_lines::trim_lines;
|
||||||
|
@ -172,11 +172,9 @@ impl Map {
|
|||||||
|
|
||||||
{
|
{
|
||||||
let _guard = flame::start_guard(format!("make {} buildings", data.buildings.len()));
|
let _guard = flame::start_guard(format!("make {} buildings", data.buildings.len()));
|
||||||
for (idx, b) in data.buildings.iter().enumerate() {
|
make::make_all_buildings(&mut m.buildings, &data.buildings, &bounds, &m.lanes);
|
||||||
let id = BuildingID(idx);
|
for b in &m.buildings {
|
||||||
let bldg = make::make_building(b, id, &bounds, &m.lanes);
|
m.lanes[b.front_path.sidewalk.0].building_paths.push(b.id);
|
||||||
m.lanes[bldg.front_path.sidewalk.0].building_paths.push(id);
|
|
||||||
m.buildings.push(bldg);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user