typedef struct { int left; // leftmost: leftmost int Top; // TopMost: uppermost int right; // the rightmost: rightmost int bottom; // bottommost: lowermost // actually a combination of two points is expressed conceptual boundary @ are: // left boundary, a right boundary // upper boundary, a lower boundary } Rect; BOOL isRectOverlap ( const the RECT R1 &, const the RECT & R2) { return !( ((r1.right < r2.left) || (r1.bottom > r2.top)) || ((r2.right < r1.left) || (r2.bottom > r1.top)) ) }
Two rectangles intersect, "the opposite event (" two rectangles do not intersect "is easier to express (case included fewer), the last of the opposite event can be negated:
Two such rectangles are r1 and r2:
the case where both disjoint as: r1 r2 on the left or on the side (Similarly, r1 or r2 on the left upper side), where the structure is necessary to use C concept provided by the industry, i.e. in the rightmost r1 r2 leftmost left, upper side in the minimum r1 r2 is the most.
((r1.right < r2.left) || (r1.bottom > r2.top))
((r2.right < r1.left) || (r2.bottom > r1.top))
Wish us again the meaning of Solutions to this question "opposite event" slightly Description:
opposite event (Complementary event, literally translated as complementary event)
P (Ac) = 1-P (A)
P (Ac) = 1-P (A )
More like often said "either", i.e. the entire sample space (sample space), an event P (A) P (A) and its opposite event P (Ac) P (Ac) , constitute the entire sample space, i.e. in the present embodiment, the sample space is: a combination of two rectangular form on a plane, event: intersection, it is naturally the opposite event: disjoint.
Note that, so as typedef struct rect four variables restriction member, the relationship between the rectangular irregular plane disposed herein can not be solved.