Allow reusing a node twice between two stops
This commit is contained in:
parent
b3de2e25f1
commit
cf43daf731
|
@ -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]),
|
||||||
|
|
Loading…
Reference in New Issue