public bool SearchForIntersect(Rectangle rect) { if (rect.Intersects(Rect)) { return(true); } //search in child nodes. int dontSearch = 0; switch (Dimension) { case IntersectRectDimension.Top: dontSearch = (rect.Bottom < Rect.Top)?2:0; break; //if true, do not have to search right (where top greater) case IntersectRectDimension.Left: dontSearch = (rect.Right < Rect.Left)?2:0; break; //if true, do not have to search right (where left greater) case IntersectRectDimension.Bottom: dontSearch = (rect.Top > Rect.Bottom)?1:0; break; //if true, do not have to search left (where bottom less) case IntersectRectDimension.Right: dontSearch = (rect.Left > Rect.Right)?1:0; break; //if true, do not have to search left (where right less) } //may need to search both :'( won't happen often with our small rectangles over large space though. return((dontSearch != 1 && LeftChild != null && LeftChild.SearchForIntersect(rect)) || (dontSearch != 2 && RightChild != null && RightChild.SearchForIntersect(rect))); }
public bool SearchForIntersect(Rectangle rect) { if (Root == null) { return(false); } else { return(Root.SearchForIntersect(rect)); } }