padTopBottom method
Adds padding to the top and bottom of the matrix.
This method inserts blank lines at the top and bottom of the matrix data, effectively adding padding to the matrix.
Parameters:
paddingTop: The number of blank lines to add at the top of the matrix.paddingBottom: The number of blank lines to add at the bottom of the matrix.
The method modifies the matrix in place by:
- Creating blank lines (rows filled with
falsevalues). - Inserting the specified number of blank lines at the top of the matrix.
- Appending the specified number of blank lines at the bottom of the matrix.
- Updating the total number of rows in the matrix.
Implementation
void padTopBottom({
required final int paddingTop,
required final int paddingBottom,
}) {
final int newRows = rows + paddingTop + paddingBottom;
final Uint8List newMatrix = Uint8List(newRows * cols);
// Copy old matrix into the new padded matrix
for (int y = 0; y < rows; y++) {
for (int x = 0; x < cols; x++) {
newMatrix[(y + paddingTop) * cols + x] = _matrix[y * cols + x];
}
}
// Replace old matrix
_matrix = newMatrix;
}