Artifact.fromPoints constructor

Artifact.fromPoints(
  1. List<Point<int>> connectedPoints
)

Creates a new Artifact from a list of connected points.

This factory method takes a list of points that form a connected region and creates a new Artifact that contains just this region.

Parameters:

  • connectedPoints: A list of Point<int> representing connected cells.

Returns: A new Artifact containing only the connected region, with its location set to the top-left corner of the bounding box of the points.

Implementation

factory Artifact.fromPoints(List<Point<int>> connectedPoints) {
  // Create a new matrix for the isolated region
  final int minX = connectedPoints.map((point) => point.x).reduce(min);
  final int minY = connectedPoints.map((point) => point.y).reduce(min);
  final int maxX = connectedPoints.map((point) => point.x).reduce(max);
  final int maxY = connectedPoints.map((point) => point.y).reduce(max);

  final int regionWidth = maxX - minX + 1;
  final int regionHeight = maxY - minY + 1;

  final Artifact artifact = Artifact(regionWidth, regionHeight);
  artifact.locationFound = IntOffset(minX, minY);
  artifact.locationAdjusted = artifact.locationFound;

  for (final Point<int> point in connectedPoints) {
    final int localX = (point.x - minX);
    final int localY = (point.y - minY);
    artifact.cellSet(localX, localY, true);
  }
  return artifact;
}