Skip to content

Instantly share code, notes, and snippets.

@SZanlongo
Created September 2, 2018 15:03
Show Gist options
  • Save SZanlongo/38a9799e97981c1d241a4b373ecbac76 to your computer and use it in GitHub Desktop.
Save SZanlongo/38a9799e97981c1d241a4b373ecbac76 to your computer and use it in GitHub Desktop.
Test two ranges intersectFrom: https://stackoverflow.com/q/3269434

What does it mean for the ranges to overlap? It means there exists some number C which is in both ranges, i.e.

x1 <= C <= x2

and

y1 <= C <= y2

Now, if we are allowed to assume that the ranges are well-formed (so that x1 <= x2 and y1 <= y2) then it is sufficient to test

x1 <= y2 && y1 <= x2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment