mergeArtifact method

void mergeArtifact(
  1. Artifact toMerge
)

Merges the current artifact with another artifact in-place.

Implementation

void mergeArtifact(final Artifact toMerge) {
  // Create a new rectangle that encompasses both artifacts
  final IntRect newRect = IntRect.fromLTRB(
    min(rectFound.left, toMerge.rectFound.left),
    min(rectFound.top, toMerge.rectFound.top),
    max(rectFound.right, toMerge.rectFound.right),
    max(rectFound.bottom, toMerge.rectFound.bottom),
  );

  // Create a new grid that can fit both artifacts
  final Artifact newGrid = Artifact(newRect.width, newRect.height);

  // Copy both grids onto the new grid with correct offsets
  Artifact.copyArtifactGrid(
    this,
    newGrid,
    (rectFound.left - newRect.left),
    (rectFound.top - newRect.top),
  );

  Artifact.copyArtifactGrid(
    toMerge,
    newGrid,
    (toMerge.rectFound.left - newRect.left),
    (toMerge.rectFound.top - newRect.top),
  );

  // Update this artifact with the merged data
  setGrid(newGrid.matrix, newGrid.cols);
}