store Polygon in Building natively

This commit is contained in:
Dustin Carlino 2019-02-12 12:22:12 -08:00
parent 21ddbc2ecc
commit b8eec25116
8 changed files with 12 additions and 11 deletions

View File

@ -50,7 +50,7 @@ pub fn clip_map(map: &mut raw_data::Map, path: &str, timer: &mut Timer) -> GPSBo
if map
.roads
.values()
.filter(|r2| r2.i1 == move_i || r2.i1 == move_i)
.filter(|r2| r2.i1 == move_i || r2.i2 == move_i)
.count()
> 1
{

View File

@ -94,7 +94,7 @@ impl ID {
ID::Lane(id) => map.maybe_get_l(id).map(|l| l.first_pt()),
ID::Intersection(id) => map.maybe_get_i(id).map(|i| i.point),
ID::Turn(id) => map.maybe_get_i(id.parent).map(|i| i.point),
ID::Building(id) => map.maybe_get_b(id).map(|b| Pt2D::center(&b.points)),
ID::Building(id) => map.maybe_get_b(id).map(|b| b.polygon.center()),
ID::Car(id) => sim.get_draw_car(id, map).map(|c| c.body.last_pt()),
ID::Pedestrian(id) => sim.get_draw_ped(id, map).map(|p| p.pos),
// TODO maybe_get_es

View File

@ -7,6 +7,7 @@ use map_model::{Building, BuildingID, BuildingType, LANE_THICKNESS};
pub struct DrawBuilding {
pub id: BuildingID,
// TODO Stop storing a copy here
pub fill_polygon: Polygon,
front_path: Polygon,
@ -26,7 +27,6 @@ impl DrawBuilding {
front_path_line.dist_along(len - trim_back),
);
}
let fill_polygon = Polygon::new(&bldg.points);
let front_path = front_path_line.make_polygons(Distance::meters(1.0));
let default_draw = prerender.upload_borrowed(vec![
@ -42,14 +42,14 @@ impl DrawBuilding {
cs.get_def("unknown building", Color::rgb_f(0.7, 0.7, 0.7))
}
},
&fill_polygon,
&bldg.polygon,
),
(cs.get_def("building path", Color::grey(0.6)), &front_path),
]);
DrawBuilding {
id: bldg.id,
fill_polygon,
fill_polygon: bldg.polygon.clone(),
front_path,
default_draw,
}

View File

@ -92,7 +92,7 @@ impl DrawBuilding {
fn new(b: &Building) -> DrawBuilding {
DrawBuilding {
id: b.id,
polygon: Polygon::new(&b.points),
polygon: b.polygon.clone(),
line: b.front_path.line.reverse(),
}
}

View File

@ -1,6 +1,6 @@
use crate::{LaneID, Position};
use abstutil;
use geom::{Line, Pt2D};
use geom::{Line, Polygon};
use serde_derive::{Deserialize, Serialize};
use std::collections::BTreeMap;
use std::fmt;
@ -34,7 +34,7 @@ pub enum BuildingType {
pub struct Building {
pub id: BuildingID,
pub building_type: BuildingType,
pub points: Vec<Pt2D>,
pub polygon: Polygon,
pub osm_tags: BTreeMap<String, String>,
pub osm_way_id: i64,
pub num_residential_units: Option<usize>,

View File

@ -1,7 +1,7 @@
use crate::make::sidewalk_finder::find_sidewalk_points;
use crate::{raw_data, Building, BuildingID, BuildingType, FrontPath, Lane};
use abstutil::Timer;
use geom::{Bounds, Distance, GPSBounds, HashablePt2D, Line, Pt2D};
use geom::{Bounds, Distance, GPSBounds, HashablePt2D, Line, Polygon, Pt2D};
use std::collections::{BTreeMap, HashSet};
pub fn make_all_buildings(
@ -47,7 +47,7 @@ pub fn make_all_buildings(
results.push(Building {
id,
building_type: classify(input[idx].num_residential_units, &input[idx].osm_tags),
points,
polygon: Polygon::new(&points),
osm_tags: input[idx].osm_tags.clone(),
osm_way_id: input[idx].osm_way_id,
front_path: FrontPath {

View File

@ -83,7 +83,7 @@ impl Neighborhood {
pub fn find_matching_buildings(&self, map: &Map) -> Vec<BuildingID> {
let mut results: Vec<BuildingID> = Vec::new();
for b in map.all_buildings() {
if self.polygon.contains_pt(Pt2D::center(&b.points)) {
if self.polygon.contains_pt(b.polygon.center()) {
results.push(b.id);
}
}

View File

@ -14,6 +14,7 @@ pub fn run(t: &mut TestRunner) {
parking_shapes: "../data/shapes/blockface".to_string(),
gtfs: "../data/input/google_transit_2018_18_08".to_string(),
neighborhoods: "../data/input/neighborhoods.geojson".to_string(),
clip: "../data/polygons/montlake.poly".to_string(),
output: "convert_osm_twice".to_string(),
fast_dev: false,
};