countOnPixels method
Counts the number of "on" pixels within an optional rectangle.
If rect is omitted, counts all pixels in the artifact.
Implementation
int countOnPixels({IntRect? rect}) {
final IntRect bounds = rect ?? IntRect.fromLTWH(0, 0, cols, rows);
if (bounds.isEmpty) {
return 0;
}
int count = 0;
for (int y = bounds.top; y < bounds.bottom; y++) {
for (int x = bounds.left; x < bounds.right; x++) {
if (cellGet(x, y)) {
count++;
}
}
}
return count;
}