IntersectRect determines whether two rectangles intersect and calculates that intersection. The intersection of the rectangles is stored in pdest, and is determined by comparing their components. The right-most x1, bottom-most y1, left-most x2, and top-most y2 are selected. The following expression is used to determine the components of the intersection:
(result.x1, result.y1, result.x2, result.y2) = (max(r1.x1, r2.x1), max(r1.y1, r2.y1), min(r1.x2, r2.x2), min(r1.y2, r2.y2)
Parameters |
Description |
Rect<T> * pdest |
A pointer holding the intersection of the two rectangles. If the rectangles do not intersect, pdest is left un-initialized. |
const Rect<T> & r |
A rectangle whose components are compared to those of the current rectangle in order to determine intersection. |
A Boolean value of 1 (true) if the rectangles intersect and 0 (false) if they do not.
Rect r1(0.0, 0.0, 7.0, 7.0); Rect r2(2.0, 3.0, 8.0, 9.0); Rect r3(8.0, 9.0, 8.0, 9.0); Rect dest; r1.IntersectRect(&dest, r2); // Returns 1 (true) since the rectangles intersect. dest holds (2.00000, 3.00000, 7.00000, 7.00000) r1.IntersectRect(&dest, r3); // Returns 0 (false) since the rectangles do not intersect. dest remains uninitialized