subprotocol / verlet-js

A simple Verlet physics engine written in javascript
Other
3.76k stars 461 forks source link

Entity clicked event #16

Open SebastianCrow opened 9 years ago

SebastianCrow commented 9 years ago

Hi,

I found ability to react on entity click crucial for my project so I think it could be useful to contain it in default verlet-js behaviour. I've added entityClicked event and also made few performance improvements in nearestEntity function:

  1. selectionRadiusSquare computed at the beginning to avoid computations in every loop
  2. traditional for instead of for...in
  3. breaking last loop after successful PinConstraint finding (further looping is not needed)

Hope you'll enjoy it

Best Regards :)