public QuadTree(QuadRectangle <T> boundry, int capacity) { this.capacity = capacity; this.boundry = boundry; points = new List <QuadTreeElement <T> >(); subdivided = false; }
public List <QuadTreeElement <T> > Query(QuadRectangle <T> range, List <QuadTreeElement <T> > result = null) { if (result == null) { result = new List <QuadTreeElement <T> >(); } if (!boundry.Intersects(range)) { return(null); } foreach (QuadTreeElement <T> point in points) { if (range.BoundryContains(point)) { result.Add(point); } } if (subdivided) { topLeft.Query(range, result); topRight.Query(range, result); bottomLeft.Query(range, result); bottomRight.Query(range, result); } return(result); }
public bool Intersects(QuadRectangle <T> rect) { return(!( rect.X - rect.Width > X + Width || rect.X + rect.Width < X - Width || rect.Y - rect.Height > Y + Height || rect.Y + rect.Height < Y - Height )); }