diff --git a/docs/TODO_game.md b/docs/TODO_game.md index 6263126981..a9d8098cb1 100644 --- a/docs/TODO_game.md +++ b/docs/TODO_game.md @@ -16,6 +16,7 @@ - zoom in too much, what might you see? ;) - loading screen: snakey cars - game intro/backstory: history of seattle urban planning + - player context: a drone. people will look up eventually. ## Tutorial diff --git a/docs/TODO_refactoring.md b/docs/TODO_refactoring.md index 343dd98fbd..42cfbc00e7 100644 --- a/docs/TODO_refactoring.md +++ b/docs/TODO_refactoring.md @@ -21,6 +21,7 @@ - rename Car->Vehicle? - spawning is convoluted - popdat trip -> Scenario SpawnTrip -> pick ped speed and make spawner's TripSpec -> create trip and schedule a Command -> last minute rewriting when executing the command +- more precise car FSM by putting scheduler pointer into carstate ## ezgui layer diff --git a/game/src/render/building.rs b/game/src/render/building.rs index 66dcb9fa23..95625a3dd3 100644 --- a/game/src/render/building.rs +++ b/game/src/render/building.rs @@ -81,6 +81,11 @@ impl DrawBuilding { ); } + // TODO Slow and looks silly, but it's a nice experiment. + /*for poly in bldg.polygon.shrink(-3.0) { + batch.push(cs.get_def("building roof", Color::rgb(150, 75, 0)), poly); + }*/ + DrawBuilding { id: bldg.id, label, diff --git a/geom/Cargo.toml b/geom/Cargo.toml index 75bfe2c07a..d7767b3ccb 100644 --- a/geom/Cargo.toml +++ b/geom/Cargo.toml @@ -9,6 +9,7 @@ aabb-quadtree = "0.1.0" abstutil = { path = "../abstutil" } geo = "0.12.0" geo-booleanop = "0.2.0" +geo-offset = "0.1.0" histogram = "0.6.9" ordered-float = "1.0.1" polylabel = "1.3.0" diff --git a/geom/src/polygon.rs b/geom/src/polygon.rs index 0247d59a75..b1bacea91d 100644 --- a/geom/src/polygon.rs +++ b/geom/src/polygon.rs @@ -1,5 +1,6 @@ use crate::{Bounds, Distance, HashablePt2D, Pt2D}; use geo_booleanop::boolean::BooleanOp; +use geo_offset::Offset; use serde_derive::{Deserialize, Serialize}; use std::fmt; @@ -184,27 +185,17 @@ impl Polygon { } pub fn intersection(&self, other: &Polygon) -> Vec { - let multi = to_geo(self.points()).intersection(&to_geo(other.points())); - multi - .into_iter() - .map(|poly| { - Polygon::new( - &poly - .into_inner() - .0 - .into_points() - .into_iter() - .map(|pt| Pt2D::new(pt.x(), pt.y())) - .collect(), - ) - }) - .collect() + from_multi(to_geo(self.points()).intersection(&to_geo(other.points()))) } pub fn polylabel(&self) -> Pt2D { let pt = polylabel::polylabel(&to_geo(&self.points()), &1.0); Pt2D::new(pt.x(), pt.y()) } + + pub fn shrink(&self, distance: f64) -> Vec { + from_multi(to_geo(self.points()).offset(distance).unwrap()) + } } impl fmt::Display for Polygon { @@ -297,3 +288,20 @@ fn to_geo(pts: &Vec) -> geo::Polygon { Vec::new(), ) } + +fn from_multi(multi: geo::MultiPolygon) -> Vec { + multi + .into_iter() + .map(|poly| { + Polygon::new( + &poly + .into_inner() + .0 + .into_points() + .into_iter() + .map(|pt| Pt2D::new(pt.x(), pt.y())) + .collect(), + ) + }) + .collect() +}