1use map_model::{AreaID, BuildingID, IntersectionID, LaneID, ParkingLotID, RoadID, TransitStopID};
2use sim::{AgentID, CarID, PedestrianID};
3
4#[derive(Clone, Hash, PartialEq, Eq, Debug, PartialOrd, Ord)]
5pub enum ID {
6 Road(RoadID),
7 Lane(LaneID),
8 Intersection(IntersectionID),
9 Building(BuildingID),
10 ParkingLot(ParkingLotID),
11 Car(CarID),
12 Pedestrian(PedestrianID),
13 PedCrowd(Vec<PedestrianID>),
14 TransitStop(TransitStopID),
15 Area(AreaID),
16}
17
18impl ID {
19 pub fn from_agent(id: AgentID) -> ID {
20 match id {
21 AgentID::Car(id) => ID::Car(id),
22 AgentID::Pedestrian(id) => ID::Pedestrian(id),
23 AgentID::BusPassenger(_, bus) => ID::Car(bus),
24 }
25 }
26
27 pub fn agent_id(&self) -> Option<AgentID> {
28 match *self {
29 ID::Car(id) => Some(AgentID::Car(id)),
30 ID::Pedestrian(id) => Some(AgentID::Pedestrian(id)),
31 _ => None,
33 }
34 }
35
36 pub fn as_intersection(&self) -> IntersectionID {
37 match *self {
38 ID::Intersection(i) => i,
39 _ => panic!("Can't call as_intersection on {:?}", self),
40 }
41 }
42
43 pub fn to_map_gui(self) -> map_gui::ID {
44 match self {
45 Self::Road(x) => map_gui::ID::Road(x),
46 Self::Lane(x) => map_gui::ID::Lane(x),
47 Self::Intersection(x) => map_gui::ID::Intersection(x),
48 Self::Building(x) => map_gui::ID::Building(x),
49 Self::ParkingLot(x) => map_gui::ID::ParkingLot(x),
50 Self::TransitStop(x) => map_gui::ID::TransitStop(x),
51 Self::Area(x) => map_gui::ID::Area(x),
52 _ => panic!("Can't call map_gui on {:?}", self),
53 }
54 }
55}
56
57impl From<map_gui::ID> for ID {
58 fn from(id: map_gui::ID) -> Self {
59 match id {
60 map_gui::ID::Road(x) => Self::Road(x),
61 map_gui::ID::Lane(x) => Self::Lane(x),
62 map_gui::ID::Intersection(x) => Self::Intersection(x),
63 map_gui::ID::Building(x) => Self::Building(x),
64 map_gui::ID::ParkingLot(x) => Self::ParkingLot(x),
65 map_gui::ID::TransitStop(x) => Self::TransitStop(x),
66 map_gui::ID::Area(x) => Self::Area(x),
67 }
68 }
69}