From 636e6328cb76f01113aa07939355ed9eb1072607 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Mon, 26 Aug 2019 16:03:29 -0700 Subject: [PATCH] fix up synthetic's boundary_polygon, and remove more dead geom code --- geom/src/bounds.rs | 30 ------------------------------ synthetic/src/lib.rs | 37 ++++++++++++++++++++++++++++++++----- 2 files changed, 32 insertions(+), 35 deletions(-) diff --git a/geom/src/bounds.rs b/geom/src/bounds.rs index 884a32fde9..bd252adb7a 100644 --- a/geom/src/bounds.rs +++ b/geom/src/bounds.rs @@ -86,14 +86,6 @@ impl GPSBounds { } } - pub fn from(pts: &Vec) -> GPSBounds { - let mut b = GPSBounds::new(); - for pt in pts { - b.update(*pt); - } - b - } - pub fn update(&mut self, pt: LonLat) { self.min_lon = self.min_lon.min(pt.longitude); self.max_lon = self.max_lon.max(pt.longitude); @@ -108,28 +100,6 @@ impl GPSBounds { && pt.latitude <= self.max_lat } - pub fn as_bbox(&self) -> Rect { - Rect { - top_left: Point { - x: self.min_lon as f32, - y: self.min_lat as f32, - }, - bottom_right: Point { - x: self.max_lon as f32, - y: self.max_lat as f32, - }, - } - } - - pub fn get_corners(&self) -> Vec { - vec![ - LonLat::new(self.min_lon, self.min_lat), - LonLat::new(self.max_lon, self.min_lat), - LonLat::new(self.max_lon, self.max_lat), - LonLat::new(self.min_lon, self.max_lat), - ] - } - // TODO cache this pub fn get_max_world_pt(&self) -> Pt2D { let width = LonLat::new(self.min_lon, self.min_lat) diff --git a/synthetic/src/lib.rs b/synthetic/src/lib.rs index 3402b67e8b..8b6f254775 100644 --- a/synthetic/src/lib.rs +++ b/synthetic/src/lib.rs @@ -372,11 +372,38 @@ impl Model { }); } - // TODO Argh need to do this manually now - //map.compute_gps_bounds(); - //map.boundary_polygon = map.gps_bounds.get_corners(); - // Close off the polygon - //map.boundary_polygon.push(map.boundary_polygon[0]); + // Leave gps_bounds alone. We'll get nonsense answers when converting back to it, which is + // fine. + + let mut max_x = 0.0; + let mut max_y = 0.0; + for b in &map.buildings { + for pt in b.polygon.points() { + if pt.x() > max_x { + max_x = pt.x(); + } + if pt.y() > max_y { + max_y = pt.y(); + } + } + } + for r in map.roads.values() { + for pt in &r.center_points { + if pt.x() > max_x { + max_x = pt.x(); + } + if pt.y() > max_y { + max_y = pt.y(); + } + } + } + map.boundary_polygon = Polygon::new(&vec![ + Pt2D::new(0.0, 0.0), + Pt2D::new(max_x, 0.0), + Pt2D::new(max_x, max_y), + Pt2D::new(0.0, max_y), + Pt2D::new(0.0, 0.0), + ]); let path = abstutil::path_raw_map(self.name.as_ref().expect("Model hasn't been named yet")); abstutil::write_binary(&path, &map).expect(&format!("Saving {} failed", path));