Interval class
An interval between two points, start and end.
Interval can calculate unions, intersections, and differences between individual intervals:
final a = Interval(0, 3);
final b = Interval(2, 5);
print(a.union(b)); // [[0, 5]]
print(a.intersection(b)); // [2,3]
print(a.difference(b)); // [[0, 2]]
See IntervalTree for calculating more complex unions, intersections, and differences between collections of intervals.
Notice that the Interval class name unfortunately clashes with the Interval class from the Flutter animation library. However, there are two ways around this problem. Either use the syntax with list literals, or import either library with a name prefix, for example:
import 'package:interval_tree/interval_tree.dart' as ivt;
final interval = ivt.Interval(1, 2);
- Implemented types
- Annotations
-
- @immutable
Constructors
- Interval(dynamic start, dynamic end)
-
Creates an interval between
start
andend
points. - Interval.copy(Interval other)
-
Creates a copy of the
other
interval.
Properties
Methods
-
compareTo(
Interval other) → int -
Compares this interval to the
other
interval.override -
contains(
Interval other) → bool -
Returns
true
if this interval contains theother
interval. -
difference(
Interval other) → Iterable< Interval> ? -
Returns the difference between this interval and the
other
interval, ornull
if theother
interval contains this interval. -
intersection(
Interval other) → Interval? -
Returns the intersection between this interval and the
other
interval, ornull
if the intervals do not intersect. -
intersects(
Interval other) → bool -
Returns
true
if this interval intersects with theother
interval. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
Returns a string representation of this interval.
override
-
union(
Interval other) → Interval -
Returns the union of this interval and the
other
interval.
Operators
-
operator <(
Interval other) → bool -
Returns
true
if this interval start or ends before theother
interval. -
operator <=(
Interval other) → bool -
Returns
true
if this interval starts or ends before or same as theother
interval. -
operator ==(
Object other) → bool -
Returns
true
if this interval starts and ends same as theother
interval.override -
operator >(
Interval other) → bool -
Returns
true
if this interval starts or ends after theother
interval. -
operator >=(
Interval other) → bool -
Returns
true
if this interval starts or ends after or same as theother
interval.