title: How can I find an overlap between two given ranges?
body: <p>Is there an effective way to find the overlap between two ranges?</p>
  
  <p><a href="https://imgur.com/4INcpaw.jpg" rel="noreferrer"><img src="https://imgur.com/4INcpaw.jpg" alt="All cases tha possible"></a></p>
  
  <p>Practically, the two ranges marked as (a - c), and (b - d), and I assume (c > a) &amp;&amp; (d > b).</p>
  
  <pre><code>(b &lt;= a &lt;= d) which means if ((a &gt;= b) &amp;&amp; (d &gt; a))
  (b &lt;= c &lt;= d) which means if ((c &gt;= b) &amp;&amp; (d &gt;= c))
  (a &lt;= b &lt;= c) which means if ((b &gt; a) &amp;&amp; (c &gt; b))
  (a &lt;= d &lt;= c) which means if ((d &gt; a) &amp;&amp; (c &gt; d))
  </code></pre>
  
  <p>But it never ends, because in this way I can find only one range at the time, and in each if I have to check the other cases as well.</p>
  
  <p>For exemple, if the first condition (1) correct, I know what happening with the start of the range (a) I still need to check the others for the end of the range (c).</p>
  
  <p>Not to mention that all this works in the case that (c > a) &amp;&amp; (d > b), and not one of them is equal to another.</p>