Reputation: 2811
I need to create an intersect method for rectangle class, that takes a rectangle and returning another rectangle representing the overlapping area.
for example, given:
if they are overlapping I should return a rectangle of point (400,420) width = 50 height = 60.
Upvotes: 5
Views: 1058
Reputation: 70122
Try using the CGRectIntersection
function, it will return the intersection of two CGRect
instances:
CGRect CGRectIntersection (
CGRect r1,
CGRect r2
);
There are quite a few useful functions detailed here:
http://blogs.oreilly.com/iphone/2008/12/useful-core-graphics-functions.html
Upvotes: 4