PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

RECT operations

I see where I can do intersections on surface rects, but what about just rects?

And checking to see if a point is in a rect?
Hi fast_rx,

These are good suggestions, you can expect them to be added to one of the upcoming Edge releases. In the meantime you can use the following 2 functions:

Code:

//Check if 2 rectangles intersect
bool RectIntersect(RECT *rc1, RECT *rc2)
{
if (rc1 == NULL || rc2 == NULL)
return(false);
if (rc1->right <= rc1->left || rc1->bottom <= rc1->top)
return(false);
if (rc2->right <= rc2->left || rc2->bottom <= rc2->top)
return(false);
if (rc1->right <= rc2->left || rc1->left >= rc2->right)
return(false);
if (rc1->bottom <= rc2->top || rc1->top >= rc2->bottom)
return(false);
return(true);
}

//Check if a point is inside the rectangle
bool InRect(RECT *rc, POINT *pnt)
{
if (rc == NULL || pnt == NULL)
return(false);
if (pnt->x >= rc->left && pnt->x < rc->right)
if (pnt->y >= rc->top && pnt->y < rc->bottom)
return(true);
return(false);
}
There's a couple of other functions I've used in the past that you may want to consider...

Return the intersection of the two rects, not just true or false (for clipping and other uses). And bounding box of two rects or a rect and a point.