Don't crash when planning a route after editing one-ways. Use Dijkstra's

for pathfinding always, so we don't need to recalculate CHs after
changing directions.
This commit is contained in:
Dustin Carlino 2022-06-12 09:36:48 +01:00
parent 08cc1e2722
commit 293987999e
2 changed files with 20 additions and 5 deletions

View File

@ -109,7 +109,8 @@ pub fn handle_world_outcome(ctx: &mut EventCtx, app: &mut App, outcome: WorldOut
app.draw_map.recreate_intersection(i, &app.map);
}
// TODO Pathfinding
// See the argument in filters/existing.rs about not recalculating the pathfinder.
app.map.keep_pathfinder_despite_edits();
});
true

View File

@ -188,11 +188,19 @@ impl RoutePlanner {
};
let biking_time = {
// No custom params -- use the map's built-in bike CH
// No custom params, but don't use the map's built-in bike CH. Changes to one-way
// streets haven't been reflected, and it's cheap enough to use Dijkstra's for
// calculating one path at a time anyway.
let mut total_time = Duration::ZERO;
for pair in self.waypoints.get_waypoints().windows(2) {
if let Some(path) = TripEndpoint::path_req(pair[0], pair[1], TripMode::Bike, map)
.and_then(|req| map.pathfind_v2(req).ok())
.and_then(|req| {
self.pathfinder_cache.pathfind_with_params(
map,
req,
map.routing_params().clone(),
)
})
{
total_time += path.get_cost();
paths.push((path, *colors::PLAN_ROUTE_BIKE));
@ -202,11 +210,17 @@ impl RoutePlanner {
};
let walking_time = {
// No custom params -- use the map's built-in CH
// Same as above -- don't use the built-in CH.
let mut total_time = Duration::ZERO;
for pair in self.waypoints.get_waypoints().windows(2) {
if let Some(path) = TripEndpoint::path_req(pair[0], pair[1], TripMode::Walk, map)
.and_then(|req| map.pathfind_v2(req).ok())
.and_then(|req| {
self.pathfinder_cache.pathfind_with_params(
map,
req,
map.routing_params().clone(),
)
})
{
total_time += path.get_cost();
paths.push((path, *colors::PLAN_ROUTE_WALK));