properly render temporary path, fixes #59

This commit is contained in:
Leijurv 2018-08-20 16:24:06 -07:00
parent 6f10a007d5
commit 7f578bc3bf
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A

View File

@ -115,10 +115,20 @@ public abstract class AbstractNodeCostSearch implements IPathFinder {
@Override @Override
public Optional<IPath> bestPathSoFar() { public Optional<IPath> bestPathSoFar() {
if (startNode == null || bestSoFar[0] == null) if (startNode == null || bestSoFar[0] == null) {
return Optional.empty(); return Optional.empty();
}
return Optional.of(new Path(startNode, bestSoFar[0], 0)); for (int i = 0; i < bestSoFar.length; i++) {
if (bestSoFar[i] == null) {
continue;
}
if (getDistFromStartSq(bestSoFar[i]) > MIN_DIST_PATH * MIN_DIST_PATH) { // square the comparison since distFromStartSq is squared
return Optional.of(new Path(startNode, bestSoFar[i], 0));
}
}
// instead of returning bestSoFar[0], be less misleading
// if it actually won't find any path, don't make them think it will by rendering a dark blue that will never actually happen
return Optional.empty();
} }
@Override @Override