// find which integer based unit cube we're in
final int ix = (int) MathUtils.floor(dx), iy = (int) MathUtils.floor(dy), iz = (int) MathUtils.floor(dz);
final Key k = new Key();
final Vector3 minPoint = new Vector3();
double nearestSq = Double.MAX_VALUE;
// Each cube has a point... Walk through all nearby cubes and see where our closest point lies.
for (int a = ix - SEARCH_RADIUS; a <= ix + SEARCH_RADIUS; a++) {
k.x = a;
for (int b = iy - SEARCH_RADIUS; b <= iy + SEARCH_RADIUS; b++) {
k.y = b;
for (int c = iz - SEARCH_RADIUS; c <= iz + SEARCH_RADIUS; c++) {
k.z = c;
Vector3 point = _points.get(k);
if (point == null) {
final double pX = a + point(a, b, c, _seed);
final double pY = b + point(a, b, c, _seed + 1);
final double pZ = c + point(a, b, c, _seed + 2);
point = new Vector3(pX, pY, pZ);
// cache for future lookups
_points.put(new Key(k), point);
}
final double xDist = point.getX() - dx;
final double yDist = point.getY() - dy;
final double zDist = point.getZ() - dz;
final double distSq = xDist * xDist + yDist * yDist + zDist * zDist;
// check distance
if (distSq < nearestSq) {
nearestSq = distSq;