remove duplicated polygon from DrawBuilding by passing in map

This commit is contained in:
Dustin Carlino 2019-02-12 12:29:52 -08:00
parent b8eec25116
commit f91fbb67d6
16 changed files with 48 additions and 50 deletions

View File

@ -21,12 +21,12 @@ impl Validator {
if ctx.input.action_chosen("validate map geometry") {
// TODO Kinda temporarily stuck here for convenience
list_problems(&ctx.primary.map);
return Some(Validator::start(&ctx.primary.draw_map));
return Some(Validator::start(&ctx.primary.map, &ctx.primary.draw_map));
}
None
}
fn start(draw_map: &DrawMap) -> Validator {
fn start(map: &Map, draw_map: &DrawMap) -> Validator {
let mut objects: Vec<(ID, Vec<geo::Polygon<f64>>)> = Vec::new();
for l in &draw_map.lanes {
objects.push((ID::Lane(l.id), make_polys(&l.polygon)));
@ -34,8 +34,8 @@ impl Validator {
for i in &draw_map.intersections {
objects.push((ID::Intersection(i.id), make_polys(&i.polygon)));
}
for b in &draw_map.buildings {
objects.push((ID::Building(b.id), make_polys(&b.fill_polygon)));
for b in map.all_buildings() {
objects.push((ID::Building(b.id), make_polys(&b.polygon)));
}
for p in &draw_map.parcels {
objects.push((ID::Parcel(p.id), make_polys(&p.fill_polygon)));

View File

@ -3,7 +3,7 @@ use crate::objects::{DrawCtx, ID};
use crate::render::{RenderOptions, Renderable};
use ezgui::{Color, Drawable, GfxCtx, Prerender};
use geom::{Bounds, Polygon, Pt2D};
use map_model::{Area, AreaID, AreaType};
use map_model::{Area, AreaID, AreaType, Map};
pub struct DrawArea {
pub id: AreaID,
@ -44,11 +44,11 @@ impl Renderable for DrawArea {
}
}
fn get_bounds(&self) -> Bounds {
fn get_bounds(&self, _: &Map) -> Bounds {
self.fill_polygon.get_bounds()
}
fn contains_pt(&self, pt: Pt2D) -> bool {
fn contains_pt(&self, pt: Pt2D, _: &Map) -> bool {
self.fill_polygon.contains_pt(pt)
}
}

View File

@ -3,6 +3,7 @@ use crate::objects::{DrawCtx, ID};
use crate::render::{RenderOptions, Renderable};
use ezgui::{Color, Drawable, GfxCtx, Prerender};
use geom::{Bounds, Distance, Polygon, Pt2D};
use map_model::Map;
use sim::{CarID, CarState, DrawCarInput};
const BIKE_WIDTH: Distance = Distance::const_meters(0.8);
@ -65,11 +66,11 @@ impl Renderable for DrawBike {
}
}
fn get_bounds(&self) -> Bounds {
fn get_bounds(&self, _: &Map) -> Bounds {
self.polygon.get_bounds()
}
fn contains_pt(&self, pt: Pt2D) -> bool {
fn contains_pt(&self, pt: Pt2D, _: &Map) -> bool {
self.polygon.contains_pt(pt)
}
}

View File

@ -3,12 +3,10 @@ use crate::objects::{DrawCtx, ID};
use crate::render::{RenderOptions, Renderable};
use ezgui::{Color, Drawable, GfxCtx, Prerender};
use geom::{Bounds, Distance, Line, Polygon, Pt2D};
use map_model::{Building, BuildingID, BuildingType, LANE_THICKNESS};
use map_model::{Building, BuildingID, BuildingType, Map, LANE_THICKNESS};
pub struct DrawBuilding {
pub id: BuildingID,
// TODO Stop storing a copy here
pub fill_polygon: Polygon,
front_path: Polygon,
default_draw: Drawable,
@ -49,7 +47,6 @@ impl DrawBuilding {
DrawBuilding {
id: bldg.id,
fill_polygon: bldg.polygon.clone(),
front_path,
default_draw,
}
@ -64,7 +61,7 @@ impl Renderable for DrawBuilding {
fn draw(&self, g: &mut GfxCtx, opts: RenderOptions, ctx: &DrawCtx) {
if let Some(c) = opts.color {
g.draw_polygon_batch(vec![
(c, &self.fill_polygon),
(c, &ctx.map.get_b(self.id).polygon),
(ctx.cs.get("building path"), &self.front_path),
]);
} else {
@ -72,13 +69,13 @@ impl Renderable for DrawBuilding {
}
}
fn get_bounds(&self) -> Bounds {
let mut b = self.fill_polygon.get_bounds();
fn get_bounds(&self, map: &Map) -> Bounds {
let mut b = map.get_b(self.id).polygon.get_bounds();
b.union(self.front_path.get_bounds());
b
}
fn contains_pt(&self, pt: Pt2D) -> bool {
self.fill_polygon.contains_pt(pt)
fn contains_pt(&self, pt: Pt2D, map: &Map) -> bool {
map.get_b(self.id).polygon.contains_pt(pt)
}
}

View File

@ -58,11 +58,11 @@ impl Renderable for DrawBusStop {
}
}
fn get_bounds(&self) -> Bounds {
fn get_bounds(&self, _: &Map) -> Bounds {
self.polygon.get_bounds()
}
fn contains_pt(&self, pt: Pt2D) -> bool {
fn contains_pt(&self, pt: Pt2D, _: &Map) -> bool {
self.polygon.contains_pt(pt)
}

View File

@ -203,11 +203,11 @@ impl Renderable for DrawCar {
}
}
fn get_bounds(&self) -> Bounds {
fn get_bounds(&self, _: &Map) -> Bounds {
self.body_polygon.get_bounds()
}
fn contains_pt(&self, pt: Pt2D) -> bool {
fn contains_pt(&self, pt: Pt2D, _: &Map) -> bool {
self.body_polygon.contains_pt(pt)
}

View File

@ -3,7 +3,7 @@ use crate::render::{RenderOptions, Renderable, EXTRA_SHAPE_POINT_RADIUS, EXTRA_S
use ezgui::{Color, GfxCtx};
use geom::{Bounds, Circle, Distance, FindClosest, GPSBounds, PolyLine, Polygon, Pt2D};
use kml::ExtraShape;
use map_model::{RoadID, LANE_THICKNESS};
use map_model::{Map, RoadID, LANE_THICKNESS};
use std::collections::BTreeMap;
use std::fmt;
@ -89,14 +89,14 @@ impl Renderable for DrawExtraShape {
}
}
fn get_bounds(&self) -> Bounds {
fn get_bounds(&self, _: &Map) -> Bounds {
match self.shape {
Shape::Polygon(ref p) => p.get_bounds(),
Shape::Circle(ref c) => c.get_bounds(),
}
}
fn contains_pt(&self, pt: Pt2D) -> bool {
fn contains_pt(&self, pt: Pt2D, _: &Map) -> bool {
match self.shape {
Shape::Polygon(ref p) => p.contains_pt(pt),
Shape::Circle(ref c) => c.contains_pt(pt),

View File

@ -121,11 +121,11 @@ impl Renderable for DrawIntersection {
}
}
fn get_bounds(&self) -> Bounds {
fn get_bounds(&self, _: &Map) -> Bounds {
self.polygon.get_bounds()
}
fn contains_pt(&self, pt: Pt2D) -> bool {
fn contains_pt(&self, pt: Pt2D, _: &Map) -> bool {
self.polygon.contains_pt(pt)
}

View File

@ -110,11 +110,11 @@ impl Renderable for DrawLane {
}
}
fn get_bounds(&self) -> Bounds {
fn get_bounds(&self, _: &Map) -> Bounds {
self.polygon.get_bounds()
}
fn contains_pt(&self, pt: Pt2D) -> bool {
fn contains_pt(&self, pt: Pt2D, _: &Map) -> bool {
self.polygon.contains_pt(pt)
}

View File

@ -164,28 +164,28 @@ impl DrawMap {
let mut quadtree = QuadTree::default(map.get_bounds().as_bbox());
// TODO use iter chain if everything was boxed as a renderable...
for obj in &roads {
quadtree.insert_with_box(obj.get_id(), obj.get_bounds().as_bbox());
quadtree.insert_with_box(obj.get_id(), obj.get_bounds(map).as_bbox());
}
for obj in &lanes {
quadtree.insert_with_box(obj.get_id(), obj.get_bounds().as_bbox());
quadtree.insert_with_box(obj.get_id(), obj.get_bounds(map).as_bbox());
}
for obj in &intersections {
quadtree.insert_with_box(obj.get_id(), obj.get_bounds().as_bbox());
quadtree.insert_with_box(obj.get_id(), obj.get_bounds(map).as_bbox());
}
for obj in &buildings {
quadtree.insert_with_box(obj.get_id(), obj.get_bounds().as_bbox());
quadtree.insert_with_box(obj.get_id(), obj.get_bounds(map).as_bbox());
}
for obj in &parcels {
quadtree.insert_with_box(obj.get_id(), obj.get_bounds().as_bbox());
quadtree.insert_with_box(obj.get_id(), obj.get_bounds(map).as_bbox());
}
for obj in &extra_shapes {
quadtree.insert_with_box(obj.get_id(), obj.get_bounds().as_bbox());
quadtree.insert_with_box(obj.get_id(), obj.get_bounds(map).as_bbox());
}
for obj in bus_stops.values() {
quadtree.insert_with_box(obj.get_id(), obj.get_bounds().as_bbox());
quadtree.insert_with_box(obj.get_id(), obj.get_bounds(map).as_bbox());
}
for obj in &areas {
quadtree.insert_with_box(obj.get_id(), obj.get_bounds().as_bbox());
quadtree.insert_with_box(obj.get_id(), obj.get_bounds(map).as_bbox());
}
timer.stop("create quadtree");

View File

@ -46,8 +46,8 @@ pub const MIN_ZOOM_FOR_MARKINGS: f64 = 5.0;
pub trait Renderable {
fn get_id(&self) -> ID;
fn draw(&self, g: &mut GfxCtx, opts: RenderOptions, ctx: &DrawCtx);
fn get_bounds(&self) -> Bounds;
fn contains_pt(&self, pt: Pt2D) -> bool;
fn get_bounds(&self, map: &Map) -> Bounds;
fn contains_pt(&self, pt: Pt2D, map: &Map) -> bool;
// Higher z-ordered objects are drawn later
fn get_zorder(&self) -> isize {
0

View File

@ -3,7 +3,7 @@ use crate::objects::{DrawCtx, ID};
use crate::render::{RenderOptions, Renderable, PARCEL_BOUNDARY_THICKNESS};
use ezgui::{Color, Drawable, GfxCtx, Prerender};
use geom::{Bounds, PolyLine, Polygon, Pt2D};
use map_model::{Parcel, ParcelID};
use map_model::{Map, Parcel, ParcelID};
const COLORS: [Color; 14] = [
// TODO these are awful choices
@ -70,11 +70,11 @@ impl Renderable for DrawParcel {
}
}
fn get_bounds(&self) -> Bounds {
fn get_bounds(&self, _: &Map) -> Bounds {
self.fill_polygon.get_bounds()
}
fn contains_pt(&self, pt: Pt2D) -> bool {
fn contains_pt(&self, pt: Pt2D, _: &Map) -> bool {
self.fill_polygon.contains_pt(pt)
}
}

View File

@ -78,11 +78,11 @@ impl Renderable for DrawPedestrian {
}
}
fn get_bounds(&self) -> Bounds {
fn get_bounds(&self, _: &Map) -> Bounds {
self.circle.get_bounds()
}
fn contains_pt(&self, pt: Pt2D) -> bool {
fn contains_pt(&self, pt: Pt2D, _: &Map) -> bool {
self.circle.contains_pt(pt)
}

View File

@ -3,7 +3,7 @@ use crate::objects::{DrawCtx, ID};
use crate::render::{RenderOptions, Renderable, BIG_ARROW_THICKNESS, MIN_ZOOM_FOR_MARKINGS};
use ezgui::{Color, Drawable, GfxCtx, Prerender};
use geom::{Bounds, Polygon, Pt2D};
use map_model::{Road, RoadID, LANE_THICKNESS};
use map_model::{Map, Road, RoadID, LANE_THICKNESS};
pub struct DrawRoad {
pub id: RoadID,
@ -62,11 +62,11 @@ impl Renderable for DrawRoad {
}
}
fn get_bounds(&self) -> Bounds {
fn get_bounds(&self, _: &Map) -> Bounds {
self.polygon.get_bounds()
}
fn contains_pt(&self, pt: Pt2D) -> bool {
fn contains_pt(&self, pt: Pt2D, _: &Map) -> bool {
self.polygon.contains_pt(pt)
}

View File

@ -96,11 +96,11 @@ impl Renderable for DrawTurn {
);
}
fn get_bounds(&self) -> Bounds {
fn get_bounds(&self, _: &Map) -> Bounds {
self.icon_circle.get_bounds()
}
fn contains_pt(&self, pt: Pt2D) -> bool {
fn contains_pt(&self, pt: Pt2D, _: &Map) -> bool {
self.icon_circle.contains_pt(pt)
}
}

View File

@ -386,7 +386,7 @@ impl<S: UIState> UI<S> {
ID::Area(_) => {}
ID::Road(_) if ctx.canvas.cam_zoom >= MIN_ZOOM_FOR_MARKINGS => {}
_ => {
if obj.contains_pt(pt) {
if obj.contains_pt(pt, &self.state.get_state().primary.map) {
return Some(obj.get_id());
}
}