copyArtifactGrid function

void copyArtifactGrid(
  1. Artifact source,
  2. Artifact 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

void copyArtifactGrid(
  final Artifact source,
  final Artifact 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) {
        if (source.cellGet(x, y)) {
          target.cellSet(x + offsetX, y + offsetY, true);
        }
      }
    }
  }
}