Exemplo n.º 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>
        internal List <T> GetObjects(PreciseRectangle searchRect)
        {
            List <T> results = new List <T>();

            GetObjects(searchRect, ref results);
            return(results);
        }
Exemplo n.º 2
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(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);
                    }
                }
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Creates a QuadTree for the specified area.
 /// </summary>
 /// <param name="rect">The area this QuadTree object will encompass.</param>
 public QuadTree(PreciseRectangle rect)
 {
     quadTreeRoot = new QuadTreeNode <T>(rect);
 }
Exemplo n.º 4
0
 private QuadTreeNode(QuadTreeNode <T> parent, PreciseRectangle rect)
     : this(rect) {
     this.parent = parent;
 }
Exemplo n.º 5
0
 /// <summary>
 /// Creates a QuadTree for the specified area.
 /// </summary>
 /// <param name="x">The top-left position of the area rectangle.</param>
 /// <param name="y">The top-right position of the area rectangle.</param>
 /// <param name="width">The width of the area rectangle.</param>
 /// <param name="height">The height of the area rectangle.</param>
 public QuadTreeNode(double x, double y, double width, double height)
 {
     rect = new PreciseRectangle(x, y, width, height);
 }
Exemplo n.º 6
0
 /// <summary>
 /// Creates a QuadTree for the specified area.
 /// </summary>
 /// <param name="rect">The area this QuadTree object will encompass.</param>
 public QuadTreeNode(PreciseRectangle rect)
 {
     this.rect = rect;
 }
Exemplo n.º 7
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>
 /// <param name="results">A reference to a list that will be populated with the results.</param>
 public void GetObjects(PreciseRectangle rect, ref List <T> results)
 {
     moveAllObjects();
     quadTreeRoot.GetObjects(rect, ref results);
 }
Exemplo n.º 8
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(PreciseRectangle rect)
 {
     return(quadTreeRoot.GetObjects(rect));
 }