use derive_more::{AsRef, Display, From};
use uom::si::f64::{Length, Velocity};
use uom::si::length::meter;
#[must_use]
pub fn default_lane_width() -> Length {
Length::new::<meter>(3.2)
}
#[must_use]
pub fn default_lane_end_offset() -> Length {
Length::new::<meter>(0.0)
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Display, From, AsRef)]
pub struct EdgeId(#[as_ref(forward)] pub String);
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Display, From, AsRef)]
pub struct LaneId(#[as_ref(forward)] pub String);
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Display, From, AsRef)]
pub struct JunctionId(#[as_ref(forward)] pub String);
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Display, From, AsRef)]
pub struct TrafficLightId(#[as_ref(forward)] pub String);
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Display, From)]
pub struct LaneIndex(pub usize);
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Display, From)]
pub struct Priority(pub i32);
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Display, From)]
pub struct LinkIndex(pub i32);
#[derive(Debug, Clone, Copy, Default, PartialEq)]
pub struct Point {
pub x: f64,
pub y: f64,
pub z: f64,
}
#[derive(Debug, Clone, Default, PartialEq)]
pub struct Shape(pub Vec<Point>);
#[derive(Debug, Clone, Copy, Default, PartialEq)]
pub struct Boundary {
pub min: (f64, f64),
pub max: (f64, f64),
}
#[derive(Debug, Clone, Default, PartialEq)]
pub enum Projection {
#[default]
None,
Proj4(String),
}
#[derive(Debug, Clone, Default, PartialEq)]
pub struct Location {
pub net_offset: Point,
pub converted_boundary: Boundary,
pub original_boundary: Boundary,
pub projection: Projection,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum EdgeFunction {
Normal,
Internal,
Connector,
Crossing,
Walkingarea,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SpreadType {
Center,
RoadCenter,
Right,
}
#[derive(Debug, Clone, PartialEq)]
pub struct Lane {
pub id: LaneId,
pub index: LaneIndex,
pub speed: Velocity,
pub length: Length,
pub width: Length,
pub end_offset: Length,
pub shape: Shape,
pub allow: Vec<String>,
pub disallow: Vec<String>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct Edge {
pub id: EdgeId,
pub function: EdgeFunction,
pub from: Option<JunctionId>,
pub to: Option<JunctionId>,
pub name: Option<String>,
pub priority: Option<Priority>,
pub length: Option<Length>,
pub shape: Option<Shape>,
pub spread_type: Option<SpreadType>,
pub lanes: Vec<Lane>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum JunctionKind {
TrafficLight,
TrafficLightUnregulated,
TrafficLightRightOnRed,
RailSignal,
RailCrossing,
Priority,
PriorityStop,
LeftBeforeRight,
RightBeforeLeft,
AllWayStop,
Zipper,
District,
Unregulated,
Internal,
DeadEnd,
}
#[derive(Debug, Clone, PartialEq)]
pub struct Junction {
pub id: JunctionId,
pub position: Point,
pub kind: JunctionKind,
pub incoming_lanes: Vec<LaneId>,
pub internal_lanes: Vec<LaneId>,
pub shape: Option<Shape>,
pub name: Option<String>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ConnectionDirection {
Straight,
Turn,
TurnLeftHand,
Left,
Right,
PartialLeft,
PartialRight,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LinkState {
Major,
Minor,
TlsOffNoSignal,
TlsOffBlinking,
Equal,
Stop,
AllWayStop,
Zipper,
DeadEnd,
}
#[derive(Debug, Clone, PartialEq)]
pub struct Connection {
pub from_edge: EdgeId,
pub to_edge: EdgeId,
pub from_lane: LaneIndex,
pub to_lane: LaneIndex,
pub direction: ConnectionDirection,
pub state: LinkState,
pub via: Option<LaneId>,
pub traffic_light: Option<TrafficLightId>,
pub link_index: Option<LinkIndex>,
pub pass: bool,
pub keep_clear: bool,
}
#[derive(Debug, Clone, PartialEq)]
pub struct Roundabout {
pub nodes: Vec<JunctionId>,
pub edges: Vec<EdgeId>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct TrafficLightProgram {
pub id: TrafficLightId,
pub phases: Vec<String>,
}
#[derive(Debug, Clone, Default, PartialEq)]
pub struct Network {
pub location: Location,
pub edges: Vec<Edge>,
pub junctions: Vec<Junction>,
pub connections: Vec<Connection>,
pub roundabouts: Vec<Roundabout>,
pub traffic_light_programs: Vec<TrafficLightProgram>,
}