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; }