kill method

void kill(
  1. int index
)

Removes the particle at index by moving the last live particle into its slot and shrinking the live set. The moved particle's index changes, so a reverse iteration (for (var i = aliveCount - 1; i >= 0; i--)) visits every particle exactly once even while killing.

Implementation

void kill(int index) {
  assert(index >= 0 && index < _aliveCount);
  final last = _aliveCount - 1;
  if (index != last) {
    _copy(last, index);
  }
  _aliveCount--;
}