public bool SearchForIntersect(VMObstacle rect) { if (rect.Intersects(Rect)) { return(true); } //search in child nodes. int dontSearch = 0; switch (Dimension) { case IntersectRectDimension.Top: dontSearch = (rect.y2 <= Rect.y1) ? 2 : 0; break; //if true, do not have to search right (where top greater) case IntersectRectDimension.Left: dontSearch = (rect.x2 <= Rect.x1) ? 2 : 0; break; //if true, do not have to search right (where left greater) case IntersectRectDimension.Bottom: dontSearch = (rect.y1 >= Rect.y2) ? 1 : 0; break; //if true, do not have to search left (where bottom less) case IntersectRectDimension.Right: dontSearch = (rect.x1 >= Rect.x2) ? 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(VMObstacle rect) { if (Root == null) { return(false); } else { return(Root.SearchForIntersect(rect)); } }