map_model/objects/
parking_lot.rs

1use std::fmt;
2
3use serde::{Deserialize, Serialize};
4
5use abstutil::{deserialize_usize, serialize_usize};
6use geom::{Angle, Line, PolyLine, Polygon, Pt2D};
7
8use crate::{osm, Position};
9
10// TODO For now, ignore the mapped roads linking things and just use the same driveway approach
11// that buildings use.
12
13#[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    )]
19    pub usize,
20);
21
22impl fmt::Display for ParkingLotID {
23    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
24        write!(f, "Parking lot #{}", self.0)
25    }
26}
27
28/// Parking lots have some fixed capacity for cars, and are connected to a sidewalk and road.
29#[derive(Clone, Serialize, Deserialize)]
30pub struct ParkingLot {
31    pub id: ParkingLotID,
32    pub polygon: Polygon,
33    pub aisles: Vec<Vec<Pt2D>>,
34    pub osm_id: osm::OsmID,
35    /// The middle of the "T", pointing towards the parking aisle
36    pub 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.
39    pub extra_spots: usize,
40
41    /// Goes from the lot to the driving lane
42    pub 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
45    pub driving_pos: Position,
46
47    /// Lot to sidewalk
48    pub sidewalk_line: Line,
49    pub sidewalk_pos: Position,
50}
51
52impl ParkingLot {
53    pub fn capacity(&self) -> usize {
54        self.spots.len() + self.extra_spots
55    }
56}