rangeUnchecked method

Matrix<T> rangeUnchecked(
  1. int rowStart,
  2. int rowEnd,
  3. int columnStart,
  4. int columnEnd,
)

Returns a mutable view onto the row and column ranges. The behavior is undefined if any of the ranges are out of bounds.

Implementation

Matrix<T> rangeUnchecked(
    int rowStart, int rowEnd, int columnStart, int columnEnd) {
  if (rowStart == 0 &&
      rowEnd == rowCount &&
      columnStart == 0 &&
      columnEnd == colCount) return this;
  return switch (this) {
    RangeMatrix<T>(
      matrix: final thisMatrix,
      rowStart: final thisRowStart,
      columnStart: final thisColumnStart
    ) =>
      RangeMatrix<T>(
          thisMatrix,
          thisRowStart + rowStart,
          thisRowStart + rowEnd,
          thisColumnStart + columnStart,
          thisColumnStart + columnEnd),
    _ => RangeMatrix<T>(this, rowStart, rowEnd, columnStart, columnEnd),
  };
}