title: Are two rectangles overlapping each other?
body: <p>I studied this <a href="https://stackoverflow.com/questions/306316/determine-if-two-rectangles-overlap-each-other">question</a>, and followed the answer to implement my own version in Java. I think it is close... but still incorrect. Could you please give me some suggestion on the error?</p>
  
  <p>The full source code can be found <a href="http://hostcode.sourceforge.net/view/891" rel="nofollow noreferrer">here</a>:</p>
  
  <pre><code>// Determine if it is inside
  boolean isInside = ((r1x1 &gt;= r2x1) &amp;&amp; (r1x2 &gt;= r2x2) 
          &amp;&amp; (r1y1 &gt;= r2y1) &amp;&amp; (r1y2 &lt;= r2y2));
  
  // Determine if it is overlap
  boolean isOverLap = (!(r1x1 &gt;= r2x2) &amp;&amp; !(r1x2 &lt;= r2x2)
          &amp;&amp; !(r1y2 &gt;= r2y1) &amp;&amp; !(r1y1 &lt;= r2y2));
  
  // Determine if it is NOT overlap
  boolean isNotOverLap = ((r1x1 &gt;= r2x2) || (r1x2 &lt;= r2x2)
          || (r1y2 &gt;= r2y1) || (r1y1 &lt;= r2y2));
  </code></pre>
  
  <p>According to the textbook I am studying, this is supposed to be: <code>r2 overlap r1</code>. But my program output <code>r2 does not overlap r1</code>. </p>
  
  <pre><code>Enter the r1's center x, y coordinates, width and height
  1 2 3 5.5
  Enter the r2's center x, y coordinates, width and height
  3 4 4.5 5
  Rectangle 1: (-0.50, 4.75), (2.50, -0.75)
  Rectangle 2: (0.75, 6.50), (5.25, 1.50)
  r2 does not overlap r1
  </code></pre>