Allow reusing a node twice between two stops

This commit is contained in:
Mattéo Delabre 2020-01-13 15:01:26 +01:00
parent b3de2e25f1
commit cf43daf731
Signed by: matteo
GPG Key ID: AE3FBD02DC583ABB
1 changed files with 5 additions and 3 deletions

View File

@ -123,7 +123,7 @@ out body qt;
const currentStop = stops[currentStopIndex]; const currentStop = stops[currentStopIndex];
const nextStop = stops[currentStopIndex + 1]; const nextStop = stops[currentStopIndex + 1];
const visited = new Set(); const visitedEdges = new Set();
const stack = [{ const stack = [{
currentNode: currentStop.id, currentNode: currentStop.id,
way: [currentStop.id], way: [currentStop.id],
@ -134,7 +134,6 @@ out body qt;
while (stack.length !== 0) while (stack.length !== 0)
{ {
const {currentNode, way} = stack.pop(); const {currentNode, way} = stack.pop();
visited.add(currentNode);
if (currentNode === nextStop.id) if (currentNode === nextStop.id)
{ {
@ -148,8 +147,11 @@ out body qt;
for (let nextNode of neighbors) for (let nextNode of neighbors)
{ {
if (!visited.has(nextNode)) const edge = `${currentNode}-${nextNode}`;
if (!visitedEdges.has(edge))
{ {
visitedEdges.add(edge);
stack.push({ stack.push({
currentNode: nextNode, currentNode: nextNode,
way: way.concat([nextNode]), way: way.concat([nextNode]),