intersects method
Returns true
if a non-empty range exists between this and other
.
See intersection for computing the intersection of two ranges.
This method is reflexive and symmetric.
Examples
final a = Interval.closed(1, 4);
final b = Interval.closed(1, 4);
a.intersects(b); // true, [1..4] intersects [1..4]
final a = Interval.closed(1, 4);
final b = Interval.closedOpen(2, 3);
a.intersects(b); // true, [1..4] intersects [2..3]
final a = Interval.openClosed(3, 6);
final b = Interval.openClosed(2, 8);
a.intersects(b); // true, (3..6] intersects (4..8]
final a = Interval.openClosed(3, 6);
final b = Interval.closedOpen(1, 2);
a.intersects(b); // false, (3..6] does not intersect (1..2]
final a = Interval.closedOpen(1, 3);
final b = Interval.closedOpen(3, 5);
a.besides(b); // false, [1..3) does not intersect [3..5)
Implementation
@override
@useResult bool intersects(Range<T> other) {
if (other is Min<T>) {
return Intersects.minInterval(other, this);
} else if (other is Max<T>) {
return Intersects.maxInterval(other, this);
} else if (other is Interval<T>) {
return Intersects.intervalInterval(this, other);
} else {
return true;
}
}