first make a DirectedRoad ID, finally

This commit is contained in:
Dustin Carlino 2019-02-20 16:17:30 -08:00
parent 8112df11d2
commit 86cb58b5f1
6 changed files with 50 additions and 12 deletions

View File

@ -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!

View File

@ -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<CarID>),
CarSelected(CarID, Option<BuildingID>),
ShapeSelected(ExtraShapeID, Option<(RoadID, bool)>),
ShapeSelected(ExtraShapeID, Option<DirectedRoadID>),
IntersectionSelected(IntersectionID, HashSet<AgentID>),
}

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::{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<String, String>,
pub road: Option<(RoadID, bool)>,
pub road: Option<DirectedRoadID>,
}
impl DrawExtraShape {
@ -33,7 +33,7 @@ impl DrawExtraShape {
id: ExtraShapeID,
s: ExtraShape,
gps_bounds: &GPSBounds,
closest: &FindClosest<(RoadID, bool)>,
closest: &FindClosest<DirectedRoadID>,
) -> Option<DrawExtraShape> {
let mut pts: Vec<Pt2D> = Vec::new();
for pt in s.points.into_iter() {

View File

@ -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<DirectedRoadID> = 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),
);
}

View File

@ -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};

View File

@ -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 {