public ISpatialCollection <T> getNeighborsInSphere(T item, double r)
        {
            ISpatialCollection <T> neighbors = new SpatialCollectionAsLinkedList <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();
                    double  dSquared = (Math.Pow(p1.X - p2.X, 2) +
                                        Math.Pow(p1.Y - p2.Y, 2) +
                                        Math.Pow(p1.Z - p2.Z, 2));
                    if (dSquared < r * r)
                    {
                        neighbors.Add(other);
                    }
                }
            }

            return(neighbors);
        }
 public SpatialCollectionAsLinkedList(SpatialCollectionAsLinkedList <T> collection)
 {
     this.spatialObjects = collection.spatialObjects;
 }