merge method

void merge(
  1. Canvas other, {
  2. bool overwrite = false,
})

Merges other canvas into this canvas. If overwrite is true, cells that are written to in other (i.e. grid != 0) will completely replace the cells in this canvas.

Implementation

void merge(Canvas other, {bool overwrite = false}) {
  if (width != other.width || height != other.height) {
    throw ArgumentError(
      'Canvas dimensions must match: ${width}x$height vs ${other.width}x${other.height}',
    );
  }
  final len = width * height;
  for (var i = 0; i < len; i++) {
    final otherDots = other._grid[i];
    if (otherDots != 0) {
      if (overwrite) {
        _grid[i] = otherDots;
        _antiAliased[i] = other._antiAliased[i];
        _styles[i] = other._styles[i];
      } else {
        _grid[i] |= otherDots;
        _antiAliased[i] |= other._antiAliased[i];
        if (other._styles[i] != null) {
          _styles[i] = other._styles[i];
        }
      }
    }
  }
}