Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 336
JohnBigs Avatar asked Oct 05 '22 00:10

JohnBigs


1 Answers

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

like image 134
ColinE Avatar answered Oct 13 '22 11:10

ColinE