1use std::fmt;
23use serde::{Deserialize, Serialize};
45use abstutil::{deserialize_usize, serialize_usize};
6use geom::{Angle, Line, PolyLine, Polygon, Pt2D};
78use crate::{osm, Position};
910// TODO For now, ignore the mapped roads linking things and just use the same driveway approach
11// that buildings use.
1213#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord, Serialize, Deserialize)]
14pub struct ParkingLotID(
15#[serde(
16 serialize_with = "serialize_usize",
17 deserialize_with = "deserialize_usize"
18)]
19pub usize,
20);
2122impl fmt::Display for ParkingLotID {
23fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
24write!(f, "Parking lot #{}", self.0)
25 }
26}
2728/// Parking lots have some fixed capacity for cars, and are connected to a sidewalk and road.
29#[derive(Clone, Serialize, Deserialize)]
30pub struct ParkingLot {
31pub id: ParkingLotID,
32pub polygon: Polygon,
33pub aisles: Vec<Vec<Pt2D>>,
34pub osm_id: osm::OsmID,
35/// The middle of the "T", pointing towards the parking aisle
36pub spots: Vec<(Pt2D, Angle)>,
37/// If we can't render all spots (maybe a lot with no aisles or a multi-story garage), still
38 /// count the other spots.
39pub extra_spots: usize,
4041/// Goes from the lot to the driving lane
42pub driveway_line: PolyLine,
43/// Guaranteed to be at least 7m (MAX_CAR_LENGTH + a little buffer) away from both ends of the
44 /// lane, to prevent various headaches
45pub driving_pos: Position,
4647/// Lot to sidewalk
48pub sidewalk_line: Line,
49pub sidewalk_pos: Position,
50}
5152impl ParkingLot {
53pub fn capacity(&self) -> usize {
54self.spots.len() + self.extra_spots
55 }
56}