intersect method

Range<TYPE>? intersect(
  1. Range<TYPE> that
)

The intersection of two ranges is the set of all elements that are in both ranges.

that The other range to intersect with.

Returns a range that represents the intersection of the two ranges, or null if the ranges do not intersect.

Implementation

Range<TYPE>? intersect(Range<TYPE> that) {
  Range<TYPE>? result = newInstance();
  //if (this.start <= that.star && this.end >= that.end) {
  if (isSupersetOf(that)) {
    result = that;
  } else if (isSubsetOf(that)) {
    result = this;
  } else if (_esOverlap(that) || _esAdjacent(that)) {
    result
      .._startInclusive = that._startInclusive
      .._start = that._start
      .._end = _end
      .._endInclusive = _endInclusive;
  } else if (_seOverlap(that) || _seAdjacent(that)) {
    result
      .._startInclusive = _startInclusive
      .._start = _start
      .._end = that._end
      .._endInclusive = that._endInclusive;
  } else {
    result = null;
  }
  return result;
}