furtherHr = leftHr;
}
// step 8
IKDTreeDomain nearest = null;
RefInt distSq = new RefInt();
searchHr.add(new HREntry(furtherHr, furtherKd, pivot, furtherHr.distance(target)));
// No child, bottom reached!
if (nearerKd == null) {
distSq.val = Integer.MAX_VALUE;
} else {
nearest = nearerKd.nearestNeighbourListBBFI(best, q, target, nearerHr, maxDistSq, distSq, searchHr,
searchSteps);
}
// step 9
if (best.size() >= q) {
maxDistSq = ((BestEntry) best.get(q - 1)).getDistSq();
} else maxDistSq = Integer.MAX_VALUE;
if (searchHr.size() > 0) {
HREntry hre = (HREntry) searchHr.get(0);
searchHr.remove(0);
furtherHr = hre.rect;
furtherKd = hre.tree;
pivot = hre.pivot;
}
// step 10
searchSteps.val -= 1;
if (searchSteps.val > 0 && furtherHr.isInReach(target, (float) Math.sqrt(maxDistSq))) {
int ptDistSq = KDTree.distanceSq(pivot, target);
if (ptDistSq < distSq.val) {
// steps 10.1.1 to 10.1.3
nearest = pivot;
distSq.val = ptDistSq;
maxDistSq = distSq.val;
}
// step 10.2
RefInt tempDistSq = new RefInt();
IKDTreeDomain tempNearest = null;
if (furtherKd == null) {
tempDistSq.val = Integer.MAX_VALUE;
} else {
tempNearest = furtherKd.nearestNeighbourListBBFI(best, q, target, furtherHr, maxDistSq, tempDistSq,