Skip to content

Commit 7c0f504

Browse files
author
Chan Tran
committed
feat: add previous edge and node to calculate edges instead of hitting dead end
1 parent 8b9ab35 commit 7c0f504

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

web-bundle/src/main/java/com/graphhopper/resources/BufferResource.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ private BufferFeature computeStartFeature(List<Integer> edgeList, Double startLa
323323
*/
324324
private BufferFeature computeEdgeAtDistanceThreshold(final BufferFeature startFeature, Double thresholdDistance,
325325
String roadName, Boolean upstreamPath, Boolean upstreamStart) {
326-
List<Integer> usedEdges = new ArrayList<>() {
326+
List<Integer> usedEdges = new ArrayList<Integer>() {
327327
{
328328
add(startFeature.getEdge());
329329
}
@@ -339,6 +339,9 @@ private BufferFeature computeEdgeAtDistanceThreshold(final BufferFeature startFe
339339
nodeAccess.getLat(currentNode), nodeAccess.getLon(currentNode));
340340
double previousDistance = 0.0;
341341
Integer currentEdge = -1;
342+
// Create previous values to use in case we don't meet the threshold
343+
Integer previousEdge = currentEdge;
344+
int previousNode = currentNode;
342345

343346
if (currentDistance >= thresholdDistance) {
344347
return startFeature;
@@ -431,7 +434,12 @@ else if (tempState.get(this.roundaboutAccessEnc)) {
431434
currentEdge = potentialRoundaboutEdgesWithoutName.get(0);
432435
usedEdges.add(currentEdge);
433436
} else {
434-
throw new WebApplicationException("Dead end found.");
437+
// Instead of throwing an exception, we break the loop and return the
438+
// path up to the current edge even though we haven't met the threshold.
439+
// Assign current edge & node to previous and break the loop.
440+
currentEdge = previousEdge;
441+
currentNode = previousNode;
442+
break;
435443
}
436444
}
437445

@@ -462,6 +470,9 @@ else if (tempState.get(this.roundaboutAccessEnc)) {
462470
// Move to next node
463471
currentNode = otherNode;
464472
currentState = graph.getEdgeIteratorState(currentEdge, Integer.MIN_VALUE);
473+
// Update previous values
474+
previousEdge = currentEdge;
475+
previousNode = currentNode;
465476
}
466477

467478
return new BufferFeature(currentEdge, currentNode,

0 commit comments

Comments
 (0)