diff --git a/editor/src/objects.rs b/editor/src/objects.rs index 969c7882e7..fb5e486cd6 100644 --- a/editor/src/objects.rs +++ b/editor/src/objects.rs @@ -101,7 +101,7 @@ impl ID { ID::ExtraShape(id) => Some(draw_map.get_es(id).center()), ID::Parcel(id) => map.maybe_get_p(id).map(|p| Pt2D::center(&p.points)), ID::BusStop(id) => map.maybe_get_bs(id).map(|bs| bs.sidewalk_pos.pt(map)), - ID::Area(id) => map.maybe_get_a(id).map(|a| Pt2D::center(&a.points)), + ID::Area(id) => map.maybe_get_a(id).map(|a| a.polygon.center()), ID::Trip(id) => sim.get_canonical_pt_per_trip(id, map), } } diff --git a/editor/src/plugins/debug/debug_polygon.rs b/editor/src/plugins/debug/debug_polygon.rs index 1936771c1a..e2d77cab87 100644 --- a/editor/src/plugins/debug/debug_polygon.rs +++ b/editor/src/plugins/debug/debug_polygon.rs @@ -80,7 +80,7 @@ impl DebugPolygon { } Some(ID::Area(id)) => { if ctx.input.contextual_action(Key::X, "debug area geometry") { - let pts = &ctx.primary.map.get_a(id).points; + let pts = &ctx.primary.map.get_a(id).polygon.points(); let center = if pts[0] == *pts.last().unwrap() { // TODO The center looks really wrong for Volunteer Park and others, but I // think it's because they have many points along some edges. diff --git a/editor/src/render/area.rs b/editor/src/render/area.rs index 24cde97231..03693b3dc0 100644 --- a/editor/src/render/area.rs +++ b/editor/src/render/area.rs @@ -7,25 +7,16 @@ use map_model::{Area, AreaID, AreaType, Map}; pub struct DrawArea { pub id: AreaID, - fill_polygon: Polygon, } impl DrawArea { pub fn new(area: &Area, cs: &ColorScheme) -> (DrawArea, Color, Polygon) { - let fill_polygon = area.get_polygon(); let color = match area.area_type { AreaType::Park => cs.get_def("park area", Color::rgb(200, 250, 204)), AreaType::Water => cs.get_def("water area", Color::rgb(170, 211, 223)), }; - ( - DrawArea { - id: area.id, - fill_polygon: fill_polygon.clone(), - }, - color, - fill_polygon, - ) + (DrawArea { id: area.id }, color, area.polygon.clone()) } } @@ -34,17 +25,17 @@ impl Renderable for DrawArea { ID::Area(self.id) } - fn draw(&self, g: &mut GfxCtx, opts: RenderOptions, _ctx: &DrawCtx) { + fn draw(&self, g: &mut GfxCtx, opts: RenderOptions, ctx: &DrawCtx) { if let Some(color) = opts.color { - g.draw_polygon(color, &self.fill_polygon); + g.draw_polygon(color, &ctx.map.get_a(self.id).polygon); } } - fn get_bounds(&self, _: &Map) -> Bounds { - self.fill_polygon.get_bounds() + fn get_bounds(&self, map: &Map) -> Bounds { + map.get_a(self.id).polygon.get_bounds() } - fn contains_pt(&self, pt: Pt2D, _: &Map) -> bool { - self.fill_polygon.contains_pt(pt) + fn contains_pt(&self, pt: Pt2D, map: &Map) -> bool { + map.get_a(self.id).polygon.contains_pt(pt) } } diff --git a/map_model/src/area.rs b/map_model/src/area.rs index d4d0aa9db6..3819622714 100644 --- a/map_model/src/area.rs +++ b/map_model/src/area.rs @@ -1,6 +1,5 @@ -use crate::LANE_THICKNESS; use abstutil; -use geom::{PolyLine, Polygon, Pt2D}; +use geom::Polygon; use serde_derive::{Deserialize, Serialize}; use std::collections::BTreeMap; use std::fmt; @@ -25,8 +24,7 @@ pub enum AreaType { pub struct Area { pub id: AreaID, pub area_type: AreaType, - // Might be a closed loop or not -- waterways can be linear. - pub points: Vec, + pub polygon: Polygon, pub osm_tags: BTreeMap, pub osm_id: i64, } @@ -34,13 +32,5 @@ pub struct Area { impl Area { pub fn dump_debug(&self) { println!("{}", abstutil::to_json(self)); - println!("{}", PolyLine::new(self.points.clone())); - } - - pub fn get_polygon(&self) -> Polygon { - if self.points[0] == *self.points.last().unwrap() { - return Polygon::new(&self.points); - } - PolyLine::new(self.points.clone()).make_polygons(LANE_THICKNESS) } } diff --git a/map_model/src/make/half_map.rs b/map_model/src/make/half_map.rs index 7a3f2f38c8..e13926a8ae 100644 --- a/map_model/src/make/half_map.rs +++ b/map_model/src/make/half_map.rs @@ -181,10 +181,17 @@ pub fn make_half_map( ); for (idx, a) in data.areas.iter().enumerate() { + let pts = gps_bounds.must_convert(&a.points); + if pts[0] != *pts.last().unwrap() { + panic!( + "Unclosed Area from OSM {} with tags {:?}", + a.osm_id, a.osm_tags + ); + } half_map.areas.push(Area { id: AreaID(idx), area_type: a.area_type, - points: gps_bounds.must_convert(&a.points), + polygon: Polygon::new(&pts), osm_tags: a.osm_tags.clone(), osm_id: a.osm_id, });