intersection method
Returns the intersection between this interval and the other
interval,
or null
if the intervals do not intersect.
In other words, the returned interval contains the points that are also
in the other
interval.
final a = Interval(0, 3);
final b = Interval(2, 5);
print(a.intersection(b)); // [[2, 3]]
Notice that a.intersection(b) = b.intersection(a)
.
The returned interval may be null
if the intervals do not intersect.
final a = Interval(0, 2);
final b = Interval(3, 5);
print(b.intersection(a)); // null
Implementation
Interval? intersection(Interval other) {
if (!intersects(other)) return null;
return Interval(_max(start, other.start), _min(end, other.end));
}