If you were dealing with, given two ranges [x1:x2]
and [y1:y2]
, natural / anti-natural order ranges at the same time where:
x1 <= x2 && y1 <= y2
or x1 >= x2 && y1 >= y2
then you may want to use this to check:
they are overlapped <=> (y2 - x1) * (x2 - y1) >= 0
where only four operations are involved: