public ISpatialCollection <T> getNeighborsInSphere(T item, double r)
{
ISpatialCollection <T> neighbors = new SpatialCollectionAsList <T>();
IPosition position = (IPosition)item;
foreach (T other in this.spatialObjects)
{
// DK: changed this:
// IPosition otherPosition = (IPosition)other;
// double d = position.getPoint3d().DistanceTo(otherPosition.getPoint3d());
// if (d < r && !Object.ReferenceEquals(item, other))
// {
// neighbors.Add(other);
// }
// to this:
if (!Object.ReferenceEquals(item, other))
{
Point3d p1 = position.getPoint3d();
Point3d p2 = ((IPosition)other).getPoint3d();
if (p1.DistanceSquared(p2) < r * r)
{
neighbors.Add(other);
}
}
}
return(neighbors);
}