title: Detect if two rectangles can be combined into a single rectangle
body: <p>I'm looking for an algorithm that takes two rectangles defined by (xa1,ya1,xa2,ya2) and (xb1,yb1,xb2,yb2), checks if they can be combined into a single rectangle and if they can, returns the new rectangle. An example:</p>
  
  <pre><code>xa1=0,ya1=0,xa2=320,ya2=119
  xb1=0,yb1=120,xb2=320,yb2=239
  </code></pre>
  
  <p>These two rectangles can be combined into the following rectangle:</p>
  
  <pre><code>xc1=0,yc1=0,xc2=320,yc2=240
  </code></pre>
  
  <p>How would you implement such an algorithm? Thanks!</p>