updateVisibility method
Implementation
void updateVisibility(Size bounds) {
// Include a margin to account for particles near the edges of the viewport.
const margin = 50.0;
// Use local variables to avoid repeated property access
final double px = position.dx;
final double py = position.dy;
isVisible =
px >= -margin &&
px <= bounds.width + margin &&
py >= -margin &&
py <= bounds.height + margin;
}