From: Daniel Finnie Date: 2007-02-23T04:51:01+09:00 Subject: Re: Range#overlap? I have made some tests for the code and shown the results at http://pastie.caboo.se/42266 . Please check the assertions with # I assume by them, the paper referenced went way over my head. Dan Pierre-Charles David wrote: > FWIW, people working with temporal logics and event algebras define 13 > possible relationships between two intervals (see Fig. 4 page 10 of > [1]), with a precise (if not always intuitive) vocabulary. > > In Ruby, these would be (not tested): > > class Range > # self: |---| > # other: |---| > def before?(other) > self.end < other.begin > end > > # self: |---| > # other: |---| > def after?(other) > other.before? self > end > > # self: |---| > # other: |---| > def meets?(other) > self.end == other.begin > end > > # self: |---| > # other: |---| > def met_by?(other) > other.meets?(self) > end > > # self: |---| > # other: |---| > def overlaps?(other) > (self.begin < other.begin) and other.include?(self.end) > end > > # self: |---| > # other: |---| > def overlapped_by?(other) > other.overlaps?(self) > end > > # self: |-----| > # other: |---| > def finished_by?(other) > (self.begin < other.begin) and (self.end == other.end) > end > > # self: |-----| > # other: |---| > def started_by?(other) > (self.begin == other.begin) and (self.end > other.end) > end > > # self: |---| > # other: |-----| > def starts?(other) > other.started_by?(self) > end > > # self: |---| > # other: |-----| > def finishes?(other) > other.finished_by?(self) > end > > # self: |-------| > # other: |---| > def contains?(other) > (self.begin < other.begin) and (self.end > other.end) > end > > # self: |---| > # other: |---| > def equals?(other) > (self.begin == other.begin) and (self.end == other.end) > end > > # self: |---| > # other: |-------| > def during?(other) > other.contains?(self) > end > end > > [1] Allen, J.F. and Ferguson, G. Actions and Events in Interval > Temporal Logic, J. Logic and Computation 4, 5, 1994. > http://tinyurl.com/2twek7 >