span method
Returns the minimal interval enclosing this interval and other
.
Implementation
Interval<T> span(Interval<T> other) {
if (isEmpty) {
return other;
} else if (other.isEmpty) {
return this;
}
// Find lower bound.
var newLower = lower;
if (other.lower.isUnbounded) {
newLower = other.lower;
} else if (lower.isBounded) {
final cmp = comparator(lower.endpoint, other.lower.endpoint);
if (cmp > 0 || (cmp == 0 && other.lower.isClosed)) {
newLower = other.lower;
}
}
// Find upper bound.
var newUpper = upper;
if (other.upper.isUnbounded) {
newUpper = other.upper;
} else if (upper.isBounded) {
final cmp = comparator(upper.endpoint, other.upper.endpoint);
if (cmp < 0 || (cmp == 0 && other.upper.isClosed)) {
newUpper = other.upper;
}
}
return Interval<T>._(newLower, newUpper, comparator);
}