splitArtifactByColumns static method
Splits the given artifact into multiple column slices based on the offsets.
Each entry in offsets marks the start column of a new slice.
The function returns a list of Artifact objects, where each slice represents
a vertical portion of the original artifactToSplit while maintaining its relative position.
artifactToSplit: The original artifact to split.offsets: A list of column indices where splits should occur.- Returns: A list of artifacts representing the split columns while preserving
locationFound.
Implementation
static List<Artifact> splitArtifactByColumns(
final Artifact artifactToSplit,
List<int> offsets,
) {
List<Artifact> result = [];
// Handle the first segment (from 0 to first offset)
if (offsets.isNotEmpty && offsets[0] > 0) {
Artifact firstSegment = Artifact(offsets[0], artifactToSplit.rows);
// Copy the relevant columns
for (int x = 0; x < offsets[0]; x++) {
for (int y = 0; y < artifactToSplit.rows; y++) {
firstSegment.cellSet(x, y, artifactToSplit.cellGet(x, y));
}
}
// Set location properties
firstSegment.locationFound = IntOffset(
artifactToSplit.locationFound.x,
artifactToSplit.locationFound.y,
);
firstSegment.locationAdjusted = IntOffset(
artifactToSplit.locationAdjusted.x,
artifactToSplit.locationAdjusted.y,
);
firstSegment.wasPartOfSplit = true;
result.add(firstSegment);
}
// Handle middle segments and last segment
for (int i = 0; i < offsets.length; i++) {
int columnStart = offsets[i];
int columnEnd = (i < offsets.length - 1)
? offsets[i + 1]
: artifactToSplit.cols;
// Skip if this segment has no width
if (columnEnd <= columnStart) {
continue;
}
// Create segment
Artifact segment = Artifact(
columnEnd - columnStart,
artifactToSplit.rows,
);
// Copy the relevant columns
for (int x = columnStart; x < columnEnd; x++) {
for (int y = 0; y < artifactToSplit.rows; y++) {
segment.cellSet(x - columnStart, y, artifactToSplit.cellGet(x, y));
}
}
// Set location properties
segment.locationFound = IntOffset(
artifactToSplit.locationFound.x + columnStart,
artifactToSplit.locationFound.y,
);
segment.locationAdjusted = IntOffset(
artifactToSplit.locationAdjusted.x + columnStart,
artifactToSplit.locationAdjusted.y,
);
segment.wasPartOfSplit = true;
result.add(segment);
}
return result;
}