phetsims / collision-lab

"Collision Lab" is an educational simulation in HTML5, by PhET Interactive Simulations.
GNU General Public License v3.0
6 stars 4 forks source link

Removed usage of CollisionLabUtils.forEachPossiblePair #170

Closed brandonLi8 closed 4 years ago

brandonLi8 commented 4 years ago

Related to #169 @jonathanolson in 6c83cc605276e21a7cd0d9c99a7f06185075ce5f, you removed the usage of CollisionLabUtils.forEachPossiblePair.

This was used to detect collisions between every pair of balls (ie ball1 can collide with ball2 or ball3 etc.).

However, you replaced this with

    for ( let i = 1; i < this.ballSystem.balls.length; i++ ) {
      const ball1 = this.ballSystem.balls[ i - 1 ];
      const ball2 = this.ballSystem.balls[ i ];
      ...

which loops through each adjacent ball.

Loading the sim locally, as expected, most ball-ball collisions are no longer being detected, and only adjacent balls are being collided together (ie. ball1 and ball2 are colliding but ball1 and ball3 are not colliding).

jonathanolson commented 4 years ago

Yikes, thank you for noticing! I'll inspect all of the changes I made there.

jonathanolson commented 4 years ago

Should be fixed, can you verify? (We don't want to create closures in those situations).

brandonLi8 commented 4 years ago

Seems fine to me. Closing.