コード例 #1
0
ファイル: QuadTree.cs プロジェクト: ddl2829/space-shooter
 public List <T> GetObjects <J>(Rectangle rect)
 {
     return(quadTreeRoot.GetObjects(rect).FindAll(delegate(T item)
     {
         return item is J;
     }));
 }
コード例 #2
0
ファイル: QuadTree.cs プロジェクト: ddl2829/space-shooter
        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.Rect))
                            {
                                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);
                    }
                }
            }
        }