Skip to content

Commit

Permalink
adding new type of ParkingSpot to sim layer. not glued to everything
Browse files Browse the repository at this point in the history
yet.
  • Loading branch information
dabreegster committed Aug 30, 2019
1 parent e17e77c commit abe4d21
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 128 deletions.
33 changes: 16 additions & 17 deletions sim/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,20 @@ impl VehicleSpec {
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
pub struct ParkingSpot {
pub lane: LaneID,
pub idx: usize,
pub enum ParkingSpot {
// Lane and idx
Onstreet(LaneID, usize),
// Building and idx (pretty meaningless)
Offstreet(BuildingID, usize),
}

impl ParkingSpot {
pub fn new(lane: LaneID, idx: usize) -> ParkingSpot {
ParkingSpot { lane, idx }
pub fn onstreet(lane: LaneID, idx: usize) -> ParkingSpot {
ParkingSpot::Onstreet(lane, idx)
}

pub fn offstreet(bldg: BuildingID, idx: usize) -> ParkingSpot {
ParkingSpot::Offstreet(bldg, idx)
}
}

Expand All @@ -160,12 +166,6 @@ pub struct ParkedCar {
pub spot: ParkingSpot,
}

impl ParkedCar {
pub fn get_driving_pos(&self, parking: &ParkingSimState, map: &Map) -> Position {
parking.spot_to_driving_pos(self.spot, &self.vehicle, map)
}
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub enum DrivingGoal {
ParkNear(BuildingID),
Expand Down Expand Up @@ -228,13 +228,9 @@ impl SidewalkSpot {
map: &Map,
parking_sim: &ParkingSimState,
) -> SidewalkSpot {
// TODO Consider precomputing this.
let sidewalk = map
.find_closest_lane(spot.lane, vec![LaneType::Sidewalk])
.unwrap();
SidewalkSpot {
connection: SidewalkPOI::ParkingSpot(spot),
sidewalk_pos: parking_sim.spot_to_sidewalk_pos(spot, sidewalk, map),
sidewalk_pos: parking_sim.spot_to_sidewalk_pos(spot, map),
}
}

Expand Down Expand Up @@ -331,6 +327,7 @@ impl SidewalkSpot {
// Point of interest, that is
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub enum SidewalkPOI {
// Note that for offstreet parking, the path will be the same as the building's front path.
ParkingSpot(ParkingSpot),
Building(BuildingID),
BusStop(BusStopID),
Expand Down Expand Up @@ -448,7 +445,9 @@ impl CreateCar {
CreateCar {
vehicle: parked_car.vehicle.clone(),
router,
start_dist: parked_car.get_driving_pos(parking, map).dist_along(),
start_dist: parking
.spot_to_driving_pos(parked_car.spot, &parked_car.vehicle, map)
.dist_along(),
maybe_parked_car: Some(parked_car),
trip,
}
Expand Down
6 changes: 2 additions & 4 deletions sim/src/make/scenario.rs
Original file line number Diff line number Diff line change
Expand Up @@ -722,14 +722,12 @@ fn seed_parked_cars(
for id in neighborhoods_roads {
let r = map.get_r(*id);
let mut spots: Vec<ParkingSpot> = Vec::new();
for (lane, lane_type) in r
for (lane, _) in r
.children_forwards
.iter()
.chain(r.children_backwards.iter())
{
if *lane_type == LaneType::Parking {
spots.extend(sim.get_free_spots(*lane));
}
spots.extend(sim.get_free_spots(*lane));
}
total_spots += spots.len();
spots.shuffle(&mut fork_rng(base_rng));
Expand Down
Loading

0 comments on commit abe4d21

Please sign in to comment.