/// <summary> /// Get the objects in this tree that intersect with the specified rectangle. /// </summary> /// <param name="searchRect">The rectangle to find objects in.</param> /// <param name="results">A reference to a list that will be populated with the results.</param> internal void GetObjects(PreciseRectangle searchRect, ref List <T> results) { // We can't do anything if the results list doesn't exist if (results != null) { if (searchRect.Contains(rect)) { // If the search area completely contains this quad, just get every object this quad and all it's children have GetAllObjects(ref results); } else if (searchRect.Intersects(rect)) { // Otherwise, if the quad isn't fully contained, only add objects that intersect with the search rectangle if (objects != null) { for (int i = 0; i < objects.Count; i++) { if (searchRect.Intersects(objects[i].Data.QuadBounds)) { results.Add(objects[i].Data); } } } // Get the objects for the search rectangle from the children if (childTL != null) { childTL.GetObjects(searchRect, ref results); childTR.GetObjects(searchRect, ref results); childBL.GetObjects(searchRect, ref results); childBR.GetObjects(searchRect, ref results); } } } }
/// <summary> /// Get the objects in this tree that intersect with the specified rectangle. /// </summary> /// <param name="rect">The rectangle to find objects in.</param> public List <T> GetObjects(PreciseRectangle rect) { return(quadTreeRoot.GetObjects(rect)); }