1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
//! `map_model` describes the world where simulations occur. Importing a map from OSM partly happens
//! in `convert_osm` and here.
//!
//! Helpful terminology:
//! - ch = contraction hierarchy, for speeding up pathfinding
//! - degenerate intersection = only has 2 roads connected, so why is it an intersection at all?
//! - lc = lane-change (which is modelled very strangely: <https://a-b-street.github.io/docs/tech/trafficsim/discrete_event.html#lane-changing>)
//! - ltr = left-to-right, the order of lanes for a road
//! - osm = OpenStreetMap
//!
//! Map objects are usually abbreviated in method names:
//! - a = area
//! - b = building
//! - tr = transit route
//! - ts = transit stop
//! - i = intersection
//! - l = lane
//! - pl = parking lot
//! - r = road
//! - ss = stop sign
//! - t = turn
//! - ts = traffic signal

#![allow(clippy::new_without_default)]

#[macro_use]
extern crate anyhow;
#[macro_use]
extern crate log;

use std::collections::BTreeMap;

use serde::{Deserialize, Serialize};

use abstio::MapName;
use abstutil::{deserialize_btreemap, serialize_btreemap, MultiMap};
use geom::{Bounds, GPSBounds, Polygon};

pub use crate::city::City;
pub use crate::edits::{
    EditCmd, EditEffects, EditIntersection, EditRoad, MapEdits, PermanentMapEdits,
};
pub use crate::make::RawToMapOptions;
pub use crate::map::{DrivingSide, MapConfig};
pub use crate::objects::area::{Area, AreaID, AreaType};
pub use crate::objects::block::{Block, Perimeter};
pub use crate::objects::building::{
    Amenity, AmenityType, Building, BuildingID, BuildingType, NamePerLanguage, OffstreetParking,
};
pub use crate::objects::intersection::{Intersection, IntersectionID, IntersectionType};
pub use crate::objects::lane::{
    BufferType, Lane, LaneID, LaneSpec, LaneType, NORMAL_LANE_THICKNESS, PARKING_LOT_SPOT_LENGTH,
    SIDEWALK_THICKNESS,
};
pub use crate::objects::movement::{CompressedMovementID, Movement, MovementID};
pub use crate::objects::parking_lot::{ParkingLot, ParkingLotID};
pub use crate::objects::road::{DirectedRoadID, Direction, Road, RoadID, RoadSideID, SideOfRoad};
pub use crate::objects::stop_signs::{ControlStopSign, RoadWithStopSign};
pub use crate::objects::traffic_signals::{ControlTrafficSignal, Stage, StageType};
pub use crate::objects::transit::{TransitRoute, TransitRouteID, TransitStop, TransitStopID};
pub use crate::objects::turn::{Turn, TurnID, TurnPriority, TurnType};
pub use crate::objects::zone::{AccessRestrictions, Zone};
pub use crate::pathfind::uber_turns::{IntersectionCluster, UberTurn};
use crate::pathfind::Pathfinder;
pub use crate::pathfind::{
    Path, PathConstraints, PathRequest, PathStep, PathStepV2, PathV2, RoutingParams,
};
pub use crate::traversable::{Position, Traversable, MAX_BIKE_SPEED, MAX_WALKING_SPEED};

mod city;
pub mod connectivity;
mod edits;
mod make;
mod map;
mod objects;
pub mod osm;
mod pathfind;
pub mod raw;
mod traversable;

// The map used by the simulation and UI. This struct is declared here so that the rest of the
// crate can reach into private fields.
#[derive(Clone, Serialize, Deserialize)]
pub struct Map {
    roads: Vec<Road>,
    intersections: Vec<Intersection>,
    buildings: Vec<Building>,
    #[serde(
        serialize_with = "serialize_btreemap",
        deserialize_with = "deserialize_btreemap"
    )]
    transit_stops: BTreeMap<TransitStopID, TransitStop>,
    transit_routes: Vec<TransitRoute>,
    areas: Vec<Area>,
    parking_lots: Vec<ParkingLot>,
    boundary_polygon: Polygon,

    // Note that border nodes belong in neither!
    stop_signs: BTreeMap<IntersectionID, ControlStopSign>,
    traffic_signals: BTreeMap<IntersectionID, ControlTrafficSignal>,

    gps_bounds: GPSBounds,
    bounds: Bounds,
    config: MapConfig,

    pathfinder: Pathfinder,
    pathfinder_dirty: bool,
    routing_params: RoutingParams,
    // Not the source of truth, just cached.
    zones: Vec<Zone>,

    name: MapName,

    #[serde(skip_serializing, skip_deserializing)]
    edits: MapEdits,
    #[serde(skip_serializing, skip_deserializing)]
    edits_generation: usize,
    #[serde(skip_serializing, skip_deserializing)]
    road_to_buildings: MultiMap<RoadID, BuildingID>,
}