If there are two rectangles, return another rectangle representing the overlapping area

I need to create an intersection method for the rectangle class that takes a rectangle and returns another rectangle representing the overlapping area.

for example, given:

enter image description here

if they overlap, I have to return the rectangle of the point (400 420) width = 50 height = 60.

+5
source share
1 answer

Try using a function CGRectIntersection, it will return the intersection of two instances CGRect:

CGRect CGRectIntersection (
   CGRect r1,
   CGRect r2
);

There are several useful features here:

http://blogs.oreilly.com/iphone/2008/12/useful-core-graphics-functions.html

+4
source

All Articles