mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-27 00:12:55 +03:00
first make a DirectedRoad ID, finally
This commit is contained in:
parent
8112df11d2
commit
86cb58b5f1
@ -183,6 +183,8 @@ How could lane-changing work?
|
|||||||
- one (usually turn) lane backfilling affects all
|
- one (usually turn) lane backfilling affects all
|
||||||
- later: queue per lane. turn becomes lane->road
|
- later: queue per lane. turn becomes lane->road
|
||||||
- the LCing itself doesnt really happen, merging has to happen upstream
|
- 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
|
- actual LCing during freeflow/queueing time could make sense
|
||||||
|
|
||||||
Now the interesting part... drawing!
|
Now the interesting part... drawing!
|
||||||
|
@ -2,7 +2,7 @@ use crate::objects::{DrawCtx, ID};
|
|||||||
use crate::plugins::{AmbientPlugin, PluginCtx};
|
use crate::plugins::{AmbientPlugin, PluginCtx};
|
||||||
use crate::render::ExtraShapeID;
|
use crate::render::ExtraShapeID;
|
||||||
use ezgui::Color;
|
use ezgui::Color;
|
||||||
use map_model::{BuildingID, IntersectionID, RoadID};
|
use map_model::{BuildingID, DirectedRoadID, IntersectionID};
|
||||||
use sim::{AgentID, CarID};
|
use sim::{AgentID, CarID};
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
|
||||||
@ -10,7 +10,7 @@ pub enum ShowAssociatedState {
|
|||||||
Inactive,
|
Inactive,
|
||||||
BuildingSelected(BuildingID, HashSet<CarID>),
|
BuildingSelected(BuildingID, HashSet<CarID>),
|
||||||
CarSelected(CarID, Option<BuildingID>),
|
CarSelected(CarID, Option<BuildingID>),
|
||||||
ShapeSelected(ExtraShapeID, Option<(RoadID, bool)>),
|
ShapeSelected(ExtraShapeID, Option<DirectedRoadID>),
|
||||||
IntersectionSelected(IntersectionID, HashSet<AgentID>),
|
IntersectionSelected(IntersectionID, HashSet<AgentID>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ use crate::render::{RenderOptions, Renderable, EXTRA_SHAPE_POINT_RADIUS, EXTRA_S
|
|||||||
use ezgui::{Color, GfxCtx};
|
use ezgui::{Color, GfxCtx};
|
||||||
use geom::{Bounds, Circle, Distance, FindClosest, GPSBounds, PolyLine, Polygon, Pt2D};
|
use geom::{Bounds, Circle, Distance, FindClosest, GPSBounds, PolyLine, Polygon, Pt2D};
|
||||||
use kml::ExtraShape;
|
use kml::ExtraShape;
|
||||||
use map_model::{Map, RoadID, LANE_THICKNESS};
|
use map_model::{DirectedRoadID, Map, LANE_THICKNESS};
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
@ -25,7 +25,7 @@ pub struct DrawExtraShape {
|
|||||||
pub id: ExtraShapeID,
|
pub id: ExtraShapeID,
|
||||||
shape: Shape,
|
shape: Shape,
|
||||||
pub attributes: BTreeMap<String, String>,
|
pub attributes: BTreeMap<String, String>,
|
||||||
pub road: Option<(RoadID, bool)>,
|
pub road: Option<DirectedRoadID>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DrawExtraShape {
|
impl DrawExtraShape {
|
||||||
@ -33,7 +33,7 @@ impl DrawExtraShape {
|
|||||||
id: ExtraShapeID,
|
id: ExtraShapeID,
|
||||||
s: ExtraShape,
|
s: ExtraShape,
|
||||||
gps_bounds: &GPSBounds,
|
gps_bounds: &GPSBounds,
|
||||||
closest: &FindClosest<(RoadID, bool)>,
|
closest: &FindClosest<DirectedRoadID>,
|
||||||
) -> Option<DrawExtraShape> {
|
) -> Option<DrawExtraShape> {
|
||||||
let mut pts: Vec<Pt2D> = Vec::new();
|
let mut pts: Vec<Pt2D> = Vec::new();
|
||||||
for pt in s.points.into_iter() {
|
for pt in s.points.into_iter() {
|
||||||
|
@ -16,8 +16,8 @@ use abstutil::Timer;
|
|||||||
use ezgui::{Color, Drawable, Prerender};
|
use ezgui::{Color, Drawable, Prerender};
|
||||||
use geom::{Bounds, FindClosest, Polygon};
|
use geom::{Bounds, FindClosest, Polygon};
|
||||||
use map_model::{
|
use map_model::{
|
||||||
AreaID, BuildingID, BusStopID, IntersectionID, Lane, LaneID, Map, ParcelID, RoadID,
|
AreaID, BuildingID, BusStopID, DirectedRoadID, IntersectionID, Lane, LaneID, Map, ParcelID,
|
||||||
Traversable, Turn, TurnID, LANE_THICKNESS,
|
RoadID, Traversable, Turn, TurnID, LANE_THICKNESS,
|
||||||
};
|
};
|
||||||
use sim::Tick;
|
use sim::Tick;
|
||||||
use std::borrow::Borrow;
|
use std::borrow::Borrow;
|
||||||
@ -156,15 +156,14 @@ impl DrawMap {
|
|||||||
shapes.shapes
|
shapes.shapes
|
||||||
};
|
};
|
||||||
|
|
||||||
// Match shapes with the nearest road + direction (true for forwards)
|
let mut closest: FindClosest<DirectedRoadID> = FindClosest::new(&map.get_bounds());
|
||||||
let mut closest: FindClosest<(RoadID, bool)> = FindClosest::new(&map.get_bounds());
|
|
||||||
for r in map.all_roads().iter() {
|
for r in map.all_roads().iter() {
|
||||||
closest.add(
|
closest.add(
|
||||||
(r.id, true),
|
r.id.forwards(),
|
||||||
&r.center_pts.shift_right(LANE_THICKNESS).get(timer),
|
&r.center_pts.shift_right(LANE_THICKNESS).get(timer),
|
||||||
);
|
);
|
||||||
closest.add(
|
closest.add(
|
||||||
(r.id, false),
|
r.id.backwards(),
|
||||||
&r.center_pts.shift_left(LANE_THICKNESS).get(timer),
|
&r.center_pts.shift_left(LANE_THICKNESS).get(timer),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ pub use crate::map::Map;
|
|||||||
pub use crate::neighborhood::{Neighborhood, NeighborhoodBuilder};
|
pub use crate::neighborhood::{Neighborhood, NeighborhoodBuilder};
|
||||||
pub use crate::parcel::{Parcel, ParcelID};
|
pub use crate::parcel::{Parcel, ParcelID};
|
||||||
pub use crate::pathfind::{Path, PathRequest, PathStep, Pathfinder, Trace};
|
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::stop_signs::ControlStopSign;
|
||||||
pub use crate::traffic_signals::{ControlTrafficSignal, Cycle};
|
pub use crate::traffic_signals::{ControlTrafficSignal, Cycle};
|
||||||
pub use crate::traversable::{Position, Traversable};
|
pub use crate::traversable::{Position, Traversable};
|
||||||
|
@ -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)
|
// These're bidirectional (possibly)
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub struct Road {
|
pub struct Road {
|
||||||
|
Loading…
Reference in New Issue
Block a user