public bool SearchForIntersect(ref VMObstacleSetNode node, BaseMeshTriangle rect) { if (node.Intersects(rect)) { return(true); } //search in child nodes. int dontSearch = 0; switch (node.Dimension) { case IntersectRectDimension.Top: dontSearch = (rect.y2 <= node.y1) ? 2 : 0; break; //if true, do not have to search right (where top greater) case IntersectRectDimension.Left: dontSearch = (rect.x2 <= node.x1) ? 2 : 0; break; //if true, do not have to search right (where left greater) case IntersectRectDimension.Bottom: dontSearch = (rect.y1 >= node.y2) ? 1 : 0; break; //if true, do not have to search left (where bottom less) case IntersectRectDimension.Right: dontSearch = (rect.x1 >= node.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 && node.LeftChild != -1 && SearchForIntersect(ref Nodes[node.LeftChild], rect)) || (dontSearch != 2 && node.RightChild != -1 && SearchForIntersect(ref Nodes[node.RightChild], rect))); }
public void AllIntersect(ref VMObstacleSetNode node, VMObstacle rect, List <VMObstacle> result) { if (node.Intersects(rect)) { result.Add(node.Rect); } //search in child nodes. int dontSearch = 0; switch (node.Dimension) { case IntersectRectDimension.Top: dontSearch = (rect.y2 <= node.y1) ? 2 : 0; break; //if true, do not have to search right (where top greater) case IntersectRectDimension.Left: dontSearch = (rect.x2 <= node.x1) ? 2 : 0; break; //if true, do not have to search right (where left greater) case IntersectRectDimension.Bottom: dontSearch = (rect.y1 >= node.y2) ? 1 : 0; break; //if true, do not have to search left (where bottom less) case IntersectRectDimension.Right: dontSearch = (rect.x1 >= node.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. //if (node.LeftChild != -1) AllIntersect(ref Nodes[node.LeftChild], rect, result); //if (node.RightChild != -1) AllIntersect(ref Nodes[node.RightChild], rect, result); if (dontSearch != 1 && node.LeftChild != -1) { AllIntersect(ref Nodes[node.LeftChild], rect, result); } if (dontSearch != 2 && node.RightChild != -1) { AllIntersect(ref Nodes[node.RightChild], rect, result); } }