﻿<?phpxml version="1.0" encoding="utf-8"?>
<rss version="2.0" 
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
>
<channel>
<title>Common Interview Questions - Find if two given rectangles are overlapping or not</title>
<link>http://commoninterview.com/Programming_Interview_Questions/find-if-two-given-rectangles-are-overlapping-or-not-1/</link>
<description>There are two rectangles defined by corner points LowerRight and UpperLeft. The task is to write a function which would check if two given rectangles  ...</description>
<pubDate>Tue, 12 Jan 2010 23:29:40 MST</pubDate>
<language>en</language>
<item>
<title>Comment #183</title>
<link>http://commoninterview.com/Programming_Interview_Questions/find-if-two-given-rectangles-are-overlapping-or-not-1/#c183</link>
<pubDate>Fri, 16 Jul 2010 23:25:14 MDT</pubDate>
<dc:creator>orthotope</dc:creator>
<guid isPermaLink='false'>183</guid>
<description><![CDATA[This is not an answer, but I disagree with CommonInterview that "the actual 
test needed is to check if any of Rect1 corners are inside Rect2 and vice 
versa."  For example, suppose that two rectangles are arranged like a cross.  
The rectangles overlap, but none of the corners lie withing the other 
rectangle. <br/>1 Vote(s) ]]></description>
</item>

<item>
<title>Comment #120</title>
<link>http://commoninterview.com/Programming_Interview_Questions/find-if-two-given-rectangles-are-overlapping-or-not-1/#c120</link>
<pubDate>Wed, 21 Apr 2010 20:26:51 MDT</pubDate>
<dc:creator>CommonInterview</dc:creator>
<guid isPermaLink='false'>120</guid>
<description><![CDATA[Initially it looks like very hard problem and from looking on many possible variations it might look even harder.  

The key to notice is that the actual test needed is to check if any of Rect1 corners are inside Rect2 and vice versa. In other words those two rectangle will not overlap if rectangle Rect1 is above Rect2 or below Rect2 or left from Rect2 or right from Rect2.  

If any of those conditions are true rectangle don’t overlap… Just four checks ! 

bool  IsOverlap(Rect R1, Rect R2) 
{ 
return ((R1.LR.y &lt;= R2.UL.y) 
(R1.LR.x &gt;= R2.UL.x) &amp;&amp; 
(R1.UL.x &lt;= R2.LR.x) &amp;&amp; 
(R1.UL.y  &gt;= R2.LR.y) &amp;&amp; 
)} 
<br/>0 Vote(s) ]]></description>
</item>

</channel>
</rss>

