boids icon indicating copy to clipboard operation
boids copied to clipboard

nClosestBoids: use Schwartzian transform

Open paddor opened this issue 4 years ago • 1 comments

I just watched Destin's video. Pretty cool how you explained Boid's algorithm. I got curious and had a look at boid.js. This TODO caught my attention even though the function is never called. But yeah, I changed it to use a Schwartzian transform.

My Javascript skills are mediocre at best, so don't expect the most beautiful and idiomatic syntax. I wish the Javascript standard had something like Ruby's sort_by, but apparently that's not the case.

Stay safe.

paddor avatar May 01 '20 22:05 paddor

Another easy improvement is to use the square of the distance instead of the distance. We don't need all those sqrts.

Also, in the distance function there are repeated subtractions, but the interpreter might optimize that out - I'm not sure.

beauxq avatar Oct 22 '21 13:10 beauxq