drawBatch method
Draw all batched lines using a single paint object
This method iterates through opacity levels and draws all lines with the same opacity together, minimizing GPU state changes.
Implementation
void drawBatch(Canvas canvas, Paint paint, Color baseColor) {
// Sort by opacity to ensure consistent ordering
final sortedOpacities = linesByOpacity.keys.toList()..sort();
for (final opacity in sortedOpacities) {
// Update paint color once per opacity level
paint.color = baseColor.withAlpha(opacity);
// Draw all lines with this opacity
final lines = linesByOpacity[opacity]!;
for (final (p1, p2) in lines) {
canvas.drawLine(p1, p2, paint);
}
}
}