コード例 #1
0
        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)));
        }
コード例 #2
0
        public void AllIntersect(VMObstacle rect, List <VMObstacle> result)
        {
            if (rect.Intersects(Rect))
            {
                result.Add(Rect);
            }
            //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.
            //if (LeftChild != null) LeftChild.AllIntersect(rect, result);
            //if (RightChild != null) RightChild.AllIntersect(rect, result);

            if (dontSearch != 1 && LeftChild != null)
            {
                LeftChild.AllIntersect(rect, result);
            }
            if (dontSearch != 2 && RightChild != null)
            {
                RightChild.AllIntersect(rect, result);
            }
        }