Пример #1
0
        /// <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(Rectangle searchRect, ref List <T> results)
        {
            // We can't do anything if the results list doesn't exist
            if (results != null)
            {
                if (searchRect.Contains(this._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(this._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.Bounds))
                            {
                                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);
                    }
                }
            }
        }
Пример #2
0
 /// <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(Rectangle rect)
 {
     return(_quadTreeRoot.GetObjects(rect));
 }