setRegion method

void setRegion(
  1. int left,
  2. int top,
  3. int width,
  4. int height,
)

Sets a square region of the bit matrix to true.

@param left The horizontal position to begin at (inclusive) @param top The vertical position to begin at (inclusive) @param width The width of the region @param height The height of the region

Implementation

void setRegion(int left, int top, int width, int height) {
  if (top < 0 || left < 0) {
    throw ArgumentError('Left and top must be nonnegative');
  }
  if (height < 1 || width < 1) {
    throw ArgumentError('Height and width must be at least 1');
  }
  final right = left + width;
  final bottom = top + height;
  if (bottom > _height || right > _width) {
    throw ArgumentError('The region must fit inside the matrix');
  }
  for (int y = top; y < bottom; y++) {
    final offset = y * _rowSize;
    for (int x = left; x < right; x++) {
      _bits[offset + (x ~/ 32)] |= 1 << (x & 0x1f);
    }
  }
}