JohnBigs
JohnBigs

Reputation: 2811

Given two rectangles, return another rectangle representing the overlapping area

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:

enter image description here

if they are overlapping I should return a rectangle of point (400,420) width = 50 height = 60.

Upvotes: 5

Views: 1058

Answers (1)

ColinE
ColinE

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

Related Questions