Skip to main content

Interval & Allen Relations

fabula::interval -- temporal intervals with Allen's 13-relation algebra.

Interval<T>

A half-open time interval [start, end). If end is None, the interval is open-ended (ongoing).

let bounded = Interval::new(1, 5); // [1, 5)
let open = Interval::open(3); // [3, inf)

Fields

NameTypeDescription
startTInclusive start of the interval.
endOption<T>Exclusive end, or None if open-ended.

Trait bounds

All methods require T: Ord + Clone.

Methods

Interval::new

Creates a bounded interval [start, end).

pub fn new(start: T, end: T) -> Self
ParameterTypeRequiredDefaultDescription
startTyes--Inclusive start.
endTyes--Exclusive end.

Returns: Interval<T>


Interval::open

Creates an open-ended interval [start, inf).

pub fn open(start: T) -> Self
ParameterTypeRequiredDefaultDescription
startTyes--Inclusive start.

Returns: Interval<T>


covers

Tests whether time t falls within this interval.

pub fn covers(&self, t: &T) -> bool
ParameterTypeRequiredDefaultDescription
t&Tyes--The time point to test.

Returns: bool -- true if start <= t and (end is None or t < end).


is_bounded

Tests whether this interval has an end.

pub fn is_bounded(&self) -> bool

Returns: bool -- true if end.is_some().


relation

Classifies the Allen relation between self and other. Returns None if either interval is open-ended and the relation cannot be determined.

pub fn relation(&self, other: &Interval<T>) -> Option<AllenRelation>
ParameterTypeRequiredDefaultDescription
other&Interval<T>yes--The interval to compare against.

Returns: Option<AllenRelation> -- one of 13 relations, or None if undetermined.


before

Tests whether self ends strictly before or at the start of other.

pub fn before(&self, other: &Interval<T>) -> bool
ParameterTypeRequiredDefaultDescription
other&Interval<T>yes--The interval to compare against.

Returns: bool -- true if self.end <= other.start. Returns false if self is open-ended.


meets

Tests whether self ends exactly where other starts.

pub fn meets(&self, other: &Interval<T>) -> bool
ParameterTypeRequiredDefaultDescription
other&Interval<T>yes--The interval to compare against.

Returns: bool -- true if self.end == other.start. Returns false if self is open-ended.


intersects

Tests whether two intervals share any time.

pub fn intersects(&self, other: &Interval<T>) -> bool
ParameterTypeRequiredDefaultDescription
other&Interval<T>yes--The interval to test against.

Returns: bool -- true if the intervals overlap. Handles open-ended intervals on either side.


Trait implementations

TraitBoundsNotes
DebugT: DebugDerived.
CloneT: CloneDerived.
PartialEqT: PartialEqDerived.
EqT: EqDerived.
HashT: HashDerived.
DisplayT: DisplayFormats as [start, end) or [start, inf).

AllenRelation

Allen's 13 mutually exclusive temporal relations between two bounded intervals A and B. Try them interactively in the Allen Interval Visualizer.

let a = Interval::new(1, 3);
let b = Interval::new(5, 7);
assert_eq!(a.relation(&b), Some(AllenRelation::Before));

Variants

VariantVisualDescription
BeforeAAA....BBBA ends before B starts. A gap separates them.
AfterBBB....AAAA starts after B ends. Inverse of Before.
MeetsAAABBBA ends exactly where B starts. No gap, no overlap.
MetByBBBAAAA starts exactly where B ends. Inverse of Meets.
OverlapsAAA__ / ..BBBA starts before B, A ends during B. Partial overlap, A first.
OverlappedBy..AAA / BBB__B starts before A, B ends during A. Partial overlap, B first.
StartsAA... / BBBBBA and B start together, A ends before B. A is a prefix of B.
StartedByAAAAA / BB...A and B start together, A ends after B. B is a prefix of A.
During.AAA. / BBBBBA is entirely within B. A starts after B, A ends before B.
ContainsAAAAA / .BBB.B is entirely within A. Inverse of During.
Finishes...AA / BBBBBA and B end together, A starts after B. A is a suffix of B.
FinishedByAAAAA / ...BBA and B end together, A starts before B. B is a suffix of A.
EqualsAAAAA / BBBBBA and B have identical start and end.

Methods

inverse

Returns the inverse relation (swaps A and B).

pub fn inverse(self) -> AllenRelation

Returns: AllenRelation -- the relation that holds when A and B are swapped.

InputOutput
BeforeAfter
AfterBefore
MeetsMetBy
MetByMeets
OverlapsOverlappedBy
OverlappedByOverlaps
StartsStartedBy
StartedByStarts
DuringContains
ContainsDuring
FinishesFinishedBy
FinishedByFinishes
EqualsEquals

is_before_or_meets

Tests whether the relation implies A ends before or exactly when B starts.

pub fn is_before_or_meets(self) -> bool

Returns: bool -- true for Before and Meets, false for all others.


Trait implementations

TraitNotes
DebugDerived.
CloneDerived.
CopyDerived.
PartialEqDerived.
EqDerived.
HashDerived.