markSegment method
Implementation
int markSegment({
required Offset start,
required Offset end,
required Size size,
required double brushWidth,
}) {
if (size.width <= 0 || size.height <= 0 || brushWidth <= 0) return 0;
final cellWidth = size.width / columns;
final cellHeight = size.height / rows;
final cellRadius =
math.sqrt(cellWidth * cellWidth + cellHeight * cellHeight) / 2;
final radius = brushWidth / 2 + cellRadius;
final minX = math.max(
0,
((math.min(start.dx, end.dx) - radius) / cellWidth).floor(),
);
final maxX = math.min(
columns - 1,
((math.max(start.dx, end.dx) + radius) / cellWidth).floor(),
);
final minY = math.max(
0,
((math.min(start.dy, end.dy) - radius) / cellHeight).floor(),
);
final maxY = math.min(
rows - 1,
((math.max(start.dy, end.dy) + radius) / cellHeight).floor(),
);
var added = 0;
for (var y = minY; y <= maxY; y++) {
for (var x = minX; x <= maxX; x++) {
final center = Offset((x + 0.5) * cellWidth, (y + 0.5) * cellHeight);
if (_distanceToSegment(center, start, end) > radius) continue;
final index = y * columns + x;
if (_cells[index]) continue;
_cells[index] = true;
_covered++;
added++;
}
}
return added;
}