public object GetNode(float x, float y, float z, double shortestDistance)
{
object closest = null;
if (Branch == null)
{
// var childDistance = this.Bounds.BorderDistance(x, y, z);
//if (childDistance > shortestDistance)
// return null;
foreach (OctreeLeaf leaf in Items)
{
var distance = Math.Sqrt(
Math.Pow(x - leaf.X, 2.0) +
Math.Pow(y - leaf.Y, 2.0) +
Math.Pow(z - leaf.Z, 2.0));
if (!(distance < shortestDistance)) continue;
shortestDistance = distance;
closest = leaf.LeafObject;
}
return closest;
}
// Check the distance of the bounds of the branch,
// versus the bestDistance. If there is a boundary that
// is closer, then it is possible that another node has an
// object that is closer.
foreach (OctreeNode t in Branch)
{
var childDistance = t.Bounds.BorderDistance(x, y, z);
if (!(childDistance < shortestDistance)) continue;
object test = t.GetNode(x, y, z, shortestDistance);
if (test != null)
closest = test;
}
return closest;
}