Overlapping intervalsΒΆ

Checking if two intervals overlap is covered on this page:

http://www.rgrjr.com/emacs/overlap.html

which shows intervals

(s_1, e_1)

(s_2, e_2)

overlap if

(s_2 < e_1) \wedge (s_1 < e_2)

If the intervals are specified by a width

(s_1, (s_1+w_1))

(s_2, (s_2+w_2))

then the overlap test is

(s_2 < (s_1 + w_1)) \wedge (s_1 < (s_2 + w_2))

and the expression

a < (b + c)

is equivalent to evaluating

a - b - c

then checking that the result is negative by examining the sign bit.