speed property

double get speed

Gets the speed of this particle.

Implementation

double get speed => math.sqrt(speedSqr);
set speed (double value)

Sets the speed of this particle.

In case the value is 0, the Y component of the direction will be set to 1 making the speed of the particle 1, instead of 0. The logic behind this implementation is as follows: The ParticleBahaviour needs to the smallest amount of work for each particle as possible. If a speed field was provided to specify the velocity of the particle, it would require the 2 additional multiplications (one for each component of direction) when updating a particle.

Implementation

set speed(double value) {
  double mag = speed;
  if (mag == 0) {
    // TODO: maybe find a better solution for this case
    dx = 0.0;
    dy = value;
  } else {
    dx = dx / mag * value;
    dy = dy / mag * value;
  }
}