Skip to content

Commit

Permalink
COMMON: Add function to find the intersecting rectangle
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Hoops committed Sep 17, 2011
1 parent da74436 commit 3b9ab4f
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions common/rect.h
Expand Up @@ -169,6 +169,20 @@ struct Rect {
return (left < r.right) && (r.left < right) && (top < r.bottom) && (r.top < bottom);
}

/**
* Find the intersecting rectangle between this rectangle and the given rectangle
*
* @param r the intersecting rectangle
*
* @return the intersection of the rectangles or an empty rectangle if not intersecting
*/
Rect findIntersectingRect(const Rect &r) const {
if (!intersects(r))
return Rect();

return Rect(MAX(r.left, left), MAX(r.top, top), MIN(r.right, right), MIN(r.bottom, bottom));
}

/**
* Extend this rectangle so that it contains r
*
Expand Down

0 comments on commit 3b9ab4f

Please sign in to comment.