intersection method
If this intersects other
, returns the intersection. Otherwise returns null
.
See intersects for determining if two ranges intersect.
final foo = Interval.open(1, 5);
final bar = Interval.closed(3, 7);
foo.intersection(bar); // [3..5), { x | 3 <= x < 5 }
Min.open(5).intersection(Min.closed(7)); // [7..+∞)
Max.open(5).intersection(Max.closed(7)); // (-∞..5)
Interval.open(1, 5).intersection(Interval.open(7, 9)); // null
Implementation
@override
@useResult Interval<T>? intersection(Range<T> other) => switch (other) {
Min<T> _ => Intersections.minInterval(other, this),
Interval<T> _ => Intersections.intervalInterval(this, other),
Max<T> _ => Intersections.maxInterval(other, this),
Unbound<T> _ => this,
};