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`.
This commit is contained in:
Bryan Housel
2018-02-06 14:34:26 -05:00
parent c1378a141f
commit 520cfd3276
+9 -3
View File
@@ -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;
}