intersects method
Returns whether this and the other range have at least one element in
common.
Implementation
bool intersects(RangeBounds<C> range) {
final startMatches = switch (startBound) {
InclusiveBound(value: final thisStart) => switch (range.endBound) {
InclusiveBound(value: final otherEnd) =>
thisStart.compareTo(otherEnd) <= 0,
ExclusiveBound(value: final otherEnd) =>
thisStart.compareTo(otherEnd) < 0,
UnboundedBound() => true,
},
ExclusiveBound(value: final thisStart) => switch (range.endBound) {
InclusiveBound(value: final otherEnd) ||
ExclusiveBound(value: final otherEnd) =>
thisStart.compareTo(otherEnd) < 0,
UnboundedBound() => true,
},
UnboundedBound() => true,
};
final endMatches = switch (endBound) {
InclusiveBound(value: final thisEnd) => switch (range.startBound) {
InclusiveBound(value: final otherStart) =>
thisEnd.compareTo(otherStart) >= 0,
ExclusiveBound(value: final otherStart) =>
thisEnd.compareTo(otherStart) > 0,
UnboundedBound() => true,
},
ExclusiveBound(value: final thisEnd) => switch (range.startBound) {
InclusiveBound(value: final otherStart) ||
ExclusiveBound(value: final otherStart) =>
thisEnd.compareTo(otherStart) > 0,
UnboundedBound() => true,
},
UnboundedBound() => true,
};
return startMatches && endMatches;
}