computeCellsize method

List<double> computeCellsize (int row1, int row2, int col1, int col2, int nrowsNew, int ncolsNew)

Used by compress: Returns the cellsize cellsizeRow, cellsizeCol (corresponding to the interval size in 1D). Returns null is nothing to compress.

Implementation

static List<double> computeCellsize(
    int row1, int row2, int col1, int col2, int nrowsNew, int ncolsNew) {
  Stopwatch stopwatch = new Stopwatch();
  stopwatch.start();
  // say 512 out of 2048, or 665 out of 2048
  int nrows = (row2 - row1 + 1).abs(); // +1: indices inclusive
  int ncols = (col2 - col1 + 1).abs();
  if (nrows == 0 || ncols == 0 || nrowsNew == 0 || ncolsNew == 0) {
    return null;
  }

  if (nrowsNew >= nrows && ncolsNew >= ncols)
    return null; // nothing to compress
  if (nrowsNew > nrows) nrowsNew = nrows;
  if (ncolsNew > ncols) ncolsNew = ncols;

  double cellsizeRow = nrows / nrowsNew;
  double cellsizeCol = ncols / ncolsNew;
  double cellArea = cellsizeRow * cellsizeCol;
  double newArea = nrows * ncols.toDouble();
  double ncells = newArea / cellArea;
  return [cellsizeRow, cellsizeCol, ncells];
}