diff --git a/map_model/src/objects/turn.rs b/map_model/src/objects/turn.rs index 3448024c01..d1d6bd1fcf 100644 --- a/map_model/src/objects/turn.rs +++ b/map_model/src/objects/turn.rs @@ -166,6 +166,8 @@ impl Turn { } } +/// A movement is like a turn, but with less detail -- it identifies a movement from one directed +/// road to another. /// One road usually has 4 crosswalks, each a singleton Movement. We need all of the information /// here to keep each crosswalk separate. #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord, Serialize, Deserialize)] @@ -186,7 +188,7 @@ pub struct CompressedMovementID { /// A Movement groups all turns from one road to another, letting traffic signals operate at a /// higher level of abstraction. -/// This is only useful for traffic signals currently. +/// This is used for pathfinding and traffic signals currently; other places focus instead on turns. // TODO Unclear how this plays with different lane types #[derive(Debug, Serialize, Deserialize, Clone, PartialEq)] pub struct Movement { diff --git a/map_model/src/pathfind/uber_turns.rs b/map_model/src/pathfind/uber_turns.rs index 2031edf257..7e359eabca 100644 --- a/map_model/src/pathfind/uber_turns.rs +++ b/map_model/src/pathfind/uber_turns.rs @@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize}; use geom::{Distance, PolyLine}; -use crate::{IntersectionID, LaneID, Map, TurnID}; +use crate::{IntersectionID, LaneID, Map, MovementID, TurnID}; /// This only applies to VehiclePathfinder; walking through these intersections is nothing special. // TODO I haven't seen any cases yet with "interior" intersections. Some stuff might break. @@ -254,3 +254,30 @@ impl UberTurn { pl } } + +/// A sequence of movements through a cluster of intersections. Like UberTurn, but at the +/// granularity of directed roads, not lanes. +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)] +pub struct UberTurnV2 { + pub path: Vec, +} + +impl IntersectionCluster { + /// Group lane-based uber-turns into road-based UberTurnV2s. + pub fn to_v2(self, map: &Map) -> Vec { + let mut result = BTreeSet::new(); + for ut in self.uber_turns { + let mut path = Vec::new(); + for turn in ut.path { + path.push(MovementID { + from: map.get_l(turn.src).get_directed_parent(map), + to: map.get_l(turn.dst).get_directed_parent(map), + parent: turn.parent, + crosswalk: false, + }); + } + result.insert(UberTurnV2 { path }); + } + result.into_iter().collect() + } +}