From 86cb58b5f1625b47d24b40b8dbc61fd827490866 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Wed, 20 Feb 2019 16:17:30 -0800 Subject: [PATCH] first make a DirectedRoad ID, finally --- docs/design/notes/discrete_sim.md | 2 ++ editor/src/plugins/view/show_associated.rs | 4 +-- editor/src/render/extra_shape.rs | 6 ++-- editor/src/render/map.rs | 11 +++---- map_model/src/lib.rs | 2 +- map_model/src/road.rs | 37 ++++++++++++++++++++++ 6 files changed, 50 insertions(+), 12 deletions(-) diff --git a/docs/design/notes/discrete_sim.md b/docs/design/notes/discrete_sim.md index d6526b14c6..ddd4eacf40 100644 --- a/docs/design/notes/discrete_sim.md +++ b/docs/design/notes/discrete_sim.md @@ -183,6 +183,8 @@ How could lane-changing work? - one (usually turn) lane backfilling affects all - later: queue per lane. turn becomes lane->road - the LCing itself doesnt really happen, merging has to happen upstream + - the only place this is really weird is when there are multiple turn lanes from src to dst + - or when two incoming roads could turn into different lanes of a road - actual LCing during freeflow/queueing time could make sense Now the interesting part... drawing! diff --git a/editor/src/plugins/view/show_associated.rs b/editor/src/plugins/view/show_associated.rs index 79937f1b67..ea55287466 100644 --- a/editor/src/plugins/view/show_associated.rs +++ b/editor/src/plugins/view/show_associated.rs @@ -2,7 +2,7 @@ use crate::objects::{DrawCtx, ID}; use crate::plugins::{AmbientPlugin, PluginCtx}; use crate::render::ExtraShapeID; use ezgui::Color; -use map_model::{BuildingID, IntersectionID, RoadID}; +use map_model::{BuildingID, DirectedRoadID, IntersectionID}; use sim::{AgentID, CarID}; use std::collections::HashSet; @@ -10,7 +10,7 @@ pub enum ShowAssociatedState { Inactive, BuildingSelected(BuildingID, HashSet), CarSelected(CarID, Option), - ShapeSelected(ExtraShapeID, Option<(RoadID, bool)>), + ShapeSelected(ExtraShapeID, Option), IntersectionSelected(IntersectionID, HashSet), } diff --git a/editor/src/render/extra_shape.rs b/editor/src/render/extra_shape.rs index 40e8e1b39e..24778711ed 100644 --- a/editor/src/render/extra_shape.rs +++ b/editor/src/render/extra_shape.rs @@ -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::{Map, RoadID, LANE_THICKNESS}; +use map_model::{DirectedRoadID, Map, LANE_THICKNESS}; use std::collections::BTreeMap; use std::fmt; @@ -25,7 +25,7 @@ pub struct DrawExtraShape { pub id: ExtraShapeID, shape: Shape, pub attributes: BTreeMap, - pub road: Option<(RoadID, bool)>, + pub road: Option, } impl DrawExtraShape { @@ -33,7 +33,7 @@ impl DrawExtraShape { id: ExtraShapeID, s: ExtraShape, gps_bounds: &GPSBounds, - closest: &FindClosest<(RoadID, bool)>, + closest: &FindClosest, ) -> Option { let mut pts: Vec = Vec::new(); for pt in s.points.into_iter() { diff --git a/editor/src/render/map.rs b/editor/src/render/map.rs index dd5cc528f2..dc4833c25b 100644 --- a/editor/src/render/map.rs +++ b/editor/src/render/map.rs @@ -16,8 +16,8 @@ use abstutil::Timer; use ezgui::{Color, Drawable, Prerender}; use geom::{Bounds, FindClosest, Polygon}; use map_model::{ - AreaID, BuildingID, BusStopID, IntersectionID, Lane, LaneID, Map, ParcelID, RoadID, - Traversable, Turn, TurnID, LANE_THICKNESS, + AreaID, BuildingID, BusStopID, DirectedRoadID, IntersectionID, Lane, LaneID, Map, ParcelID, + RoadID, Traversable, Turn, TurnID, LANE_THICKNESS, }; use sim::Tick; use std::borrow::Borrow; @@ -156,15 +156,14 @@ impl DrawMap { shapes.shapes }; - // Match shapes with the nearest road + direction (true for forwards) - let mut closest: FindClosest<(RoadID, bool)> = FindClosest::new(&map.get_bounds()); + let mut closest: FindClosest = FindClosest::new(&map.get_bounds()); for r in map.all_roads().iter() { closest.add( - (r.id, true), + r.id.forwards(), &r.center_pts.shift_right(LANE_THICKNESS).get(timer), ); closest.add( - (r.id, false), + r.id.backwards(), &r.center_pts.shift_left(LANE_THICKNESS).get(timer), ); } diff --git a/map_model/src/lib.rs b/map_model/src/lib.rs index 1cfb8b51fd..42c3fc7499 100644 --- a/map_model/src/lib.rs +++ b/map_model/src/lib.rs @@ -27,7 +27,7 @@ pub use crate::map::Map; pub use crate::neighborhood::{Neighborhood, NeighborhoodBuilder}; pub use crate::parcel::{Parcel, ParcelID}; pub use crate::pathfind::{Path, PathRequest, PathStep, Pathfinder, Trace}; -pub use crate::road::{Road, RoadID}; +pub use crate::road::{DirectedRoadID, Road, RoadID}; pub use crate::stop_signs::ControlStopSign; pub use crate::traffic_signals::{ControlTrafficSignal, Cycle}; pub use crate::traversable::{Position, Traversable}; diff --git a/map_model/src/road.rs b/map_model/src/road.rs index eaca5ba92e..10835927e5 100644 --- a/map_model/src/road.rs +++ b/map_model/src/road.rs @@ -15,6 +15,43 @@ impl fmt::Display for RoadID { } } +impl RoadID { + pub fn forwards(self) -> DirectedRoadID { + DirectedRoadID { + id: self, + forwards: true, + } + } + + pub fn backwards(self) -> DirectedRoadID { + DirectedRoadID { + id: self, + forwards: false, + } + } +} + +#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord, Serialize, Deserialize)] +pub struct DirectedRoadID { + pub id: RoadID, + pub forwards: bool, +} + +impl fmt::Display for DirectedRoadID { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!( + f, + "DirectedRoadID({}, {})", + self.id.0, + if self.forwards { + "forwards" + } else { + "backwards" + } + ) + } +} + // These're bidirectional (possibly) #[derive(Serialize, Deserialize, Debug)] pub struct Road {