work around a bug in should_use_transit with disconncted sidewalks

This commit is contained in:
Dustin Carlino 2019-08-05 13:41:02 -07:00
parent cf511f27ce
commit edfd112459
2 changed files with 11 additions and 4 deletions

View File

@ -32,6 +32,10 @@ impl<T: Copy + Ord + Serialize> NodeMap<T> {
self.node_to_id[&node] self.node_to_id[&node]
} }
pub fn maybe_get(&self, node: T) -> Option<NodeId> {
self.node_to_id.get(&node).cloned()
}
pub fn translate(&self, path: &ShortestPath) -> Vec<T> { pub fn translate(&self, path: &ShortestPath) -> Vec<T> {
path.get_nodes() path.get_nodes()
.iter() .iter()

View File

@ -117,8 +117,8 @@ impl SidewalkPathfinder {
.borrow_mut(); .borrow_mut();
let raw_path = calc.calc_path( let raw_path = calc.calc_path(
&self.graph, &self.graph,
self.nodes.get(lane_to_node(req.start.lane(), map)), self.nodes.maybe_get(lane_to_node(req.start.lane(), map))?,
self.nodes.get(lane_to_node(req.end.lane(), map)), self.nodes.maybe_get(lane_to_node(req.end.lane(), map))?,
)?; )?;
let path = self.nodes.translate(&raw_path); let path = self.nodes.translate(&raw_path);
@ -179,10 +179,13 @@ impl SidewalkPathfinder {
start: Position, start: Position,
end: Position, end: Position,
) -> Option<(BusStopID, BusStopID, BusRouteID)> { ) -> Option<(BusStopID, BusStopID, BusRouteID)> {
// TODO maybe_get is a temporaryish hack -- some sidewalks are actually totally
// disconnected, so there's no node for them. Just fail the pathfinding. Really this is a
// bug in turn creation though.
let raw_path = fast_paths::calc_path( let raw_path = fast_paths::calc_path(
&self.graph, &self.graph,
self.nodes.get(lane_to_node(start.lane(), map)), self.nodes.maybe_get(lane_to_node(start.lane(), map))?,
self.nodes.get(lane_to_node(end.lane(), map)), self.nodes.maybe_get(lane_to_node(end.lane(), map))?,
)?; )?;
let mut nodes = self.nodes.translate(&raw_path); let mut nodes = self.nodes.translate(&raw_path);