From cf43daf731ab22adb315339856cacb0ceca80131 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matt=C3=A9o=20Delabre?= Date: Mon, 13 Jan 2020 15:01:26 +0100 Subject: [PATCH] Allow reusing a node twice between two stops --- back/data.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/back/data.js b/back/data.js index 176879f..3eab080 100644 --- a/back/data.js +++ b/back/data.js @@ -123,7 +123,7 @@ out body qt; const currentStop = stops[currentStopIndex]; const nextStop = stops[currentStopIndex + 1]; - const visited = new Set(); + const visitedEdges = new Set(); const stack = [{ currentNode: currentStop.id, way: [currentStop.id], @@ -134,7 +134,6 @@ out body qt; while (stack.length !== 0) { const {currentNode, way} = stack.pop(); - visited.add(currentNode); if (currentNode === nextStop.id) { @@ -148,8 +147,11 @@ out body qt; for (let nextNode of neighbors) { - if (!visited.has(nextNode)) + const edge = `${currentNode}-${nextNode}`; + + if (!visitedEdges.has(edge)) { + visitedEdges.add(edge); stack.push({ currentNode: nextNode, way: way.concat([nextNode]),