From e47bfd890a6df9818d5c1594b763affded2231d6 Mon Sep 17 00:00:00 2001 From: Tuukka Hastrup Date: Fri, 4 Mar 2022 22:03:18 +0200 Subject: [PATCH] Handle very short edges by setting a minimum cost Without this, some very short edges break the math and crash the path finding. --- src/pathfinding/PathfinderProvider.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pathfinding/PathfinderProvider.ts b/src/pathfinding/PathfinderProvider.ts index 81b480bc..87b0672b 100644 --- a/src/pathfinding/PathfinderProvider.ts +++ b/src/pathfinding/PathfinderProvider.ts @@ -224,9 +224,9 @@ export default class PathfinderProvider { // if you need to add any other edge, you'll need to create a different method graph = graph || this.getGraphForProfile(profile); // make sure we never have 0 costs, this confuses dijkstra - distance = distance || profile.getDistance(from, to, way) || 0.01; - const duration = profile.getDuration(from, to, way) || 1; - const cost = profile.getCost(from, to, way) || 1; + distance = Math.max(distance || profile.getDistance(from, to, way) || 0.01, 0.01); + const duration = Math.max(profile.getDuration(from, to, way) || 1, 1); + const cost = Math.max(profile.getCost(from, to, way) || 1, 1); graph.addEdge(Geo.getId(from), Geo.getId(to), way.id, distance, duration, cost); }