What’s the most efficient way to test if two ranges overlap?
Given two inclusive ranges [x1:x2] and [y1:y2], where x1 ≤ x2 and y1 ≤ y2, what is the most efficient way to test whether there is any overlap of the two ranges? A simple implementation is as follows: bool testOverlap(int x1, int x2, int y1, int y2) { return (x1 >= y1 && x1 <= … Read more