copyGrid static method

void copyGrid(
  1. Matrix source,
  2. Matrix target,
  3. int offsetX,
  4. int offsetY,
)

Copies the contents of a source Matrix into a target Matrix, with an optional offset.

This method copies the values from the source Matrix into the target Matrix, starting at the specified offset coordinates. If the source Matrix extends beyond the bounds of the target Matrix, only the portion that fits within the target Matrix will be copied.

Parameters:

  • source: The Matrix to copy from.
  • target: The Matrix to copy into.
  • offsetX: The horizontal offset to apply when copying the source into the target.
  • offsetY: The vertical offset to apply when copying the source into the target.

Implementation

static void copyGrid(
  final Matrix source,
  final Matrix target,
  final int offsetX,
  final int offsetY,
) {
  for (int y = 0; y < source.rows; y++) {
    for (int x = 0; x < source.cols; x++) {
      if (y + offsetY < target.rows && x + offsetX < target.cols) {
        target._data[y + offsetY][x + offsetX] |= source._data[y][x];
      }
    }
  }
}