checkForBounce function
Implementation
Offset checkForBounce(
double nextX, double nextY, double maxX, double maxY, Particle particle) {
if (nextX > maxX) {
// Exceeding right bound
particle.updateVelocity =
Offset(-particle.currentVelocity.dx, particle.currentVelocity.dy);
nextX = maxX;
} else if (nextX < 0) {
// Exceeding left bound
particle.updateVelocity =
Offset(-particle.currentVelocity.dx, particle.currentVelocity.dy);
nextX = 0;
}
if (nextY > maxY) {
// Exceeding bottom bound
particle.updateVelocity =
Offset(particle.currentVelocity.dx, -particle.currentVelocity.dy);
nextY = maxY;
} else if (nextY < 0) {
// Exceeding top bound
particle.updateVelocity =
Offset(particle.currentVelocity.dx, -particle.currentVelocity.dy);
nextY = 0;
}
return Offset(nextX, nextY);
}