Create map_model abstractions for representing uber-turns at the granularity of roads, not lanes, in preparation for pathfinding v2. #555

I was about to recreate a higher-level turn abstraction, but realized we
previously made Movements for traffic signal editing.
This commit is contained in:
Dustin Carlino 2021-04-05 10:29:59 -07:00
parent 1e3708f9b4
commit b6d46db2ea
2 changed files with 31 additions and 2 deletions

View File

@ -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 {

View File

@ -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<MovementID>,
}
impl IntersectionCluster {
/// Group lane-based uber-turns into road-based UberTurnV2s.
pub fn to_v2(self, map: &Map) -> Vec<UberTurnV2> {
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()
}
}