From 520cfd3276266c438006733576ecd14b433880b2 Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Tue, 6 Feb 2018 14:34:26 -0500 Subject: [PATCH] Fix bug causing improper calc of from/via/to metadata after trimming This is the part of the algorithm where trivial sections get trimmed from the vgraph. Removing a vertex from `vertexIds` means "stop checking this one". But there were some situations where it could get removed twice, so we now just verify that `vertexId` is actually in the array before calling `splice`. --- modules/osm/intersection.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/modules/osm/intersection.js b/modules/osm/intersection.js index a9ca41f69..1f1a6d6ed 100644 --- a/modules/osm/intersection.js +++ b/modules/osm/intersection.js @@ -263,14 +263,18 @@ export function osmIntersection(graph, startVertexId) { vertex = vgraph.hasEntity(vertexId); if (!vertex) { - vertexIds.splice(vertexIds.indexOf(vertexId), 1); // stop checking this one + if (vertexIds.indexOf(vertexId) !== -1) { + vertexIds.splice(vertexIds.indexOf(vertexId), 1); // stop checking this one + } removeVertexIds.push(vertexId); continue; } parents = vgraph.parentWays(vertex); if (parents.length < 3) { - vertexIds.splice(vertexIds.indexOf(vertexId), 1); // stop checking this one + if (vertexIds.indexOf(vertexId) !== -1) { + vertexIds.splice(vertexIds.indexOf(vertexId), 1); // stop checking this one + } } if (parents.length === 2) { // vertex with 2 parents is trivial @@ -299,7 +303,9 @@ export function osmIntersection(graph, startVertexId) { parents = vgraph.parentWays(vertex); if (parents.length < 2) { // vertex is no longer a key vertex - vertexIds.splice(vertexIds.indexOf(vertexId), 1); // stop checking this one + if (vertexIds.indexOf(vertexId) !== -1) { + vertexIds.splice(vertexIds.indexOf(vertexId), 1); // stop checking this one + } removeVertexIds.push(vertexId); keepGoing = true; }