timohausmann / quadtree-ts

Quadtree Typescript Implementation
https://timohausmann.github.io/quadtree-ts/
MIT License
125 stars 15 forks source link

Fast retrieve #4

Closed justin-m-lacy closed 2 years ago

justin-m-lacy commented 2 years ago

1) Updated quadtree.retrieve() to allow passing results array to retrieve to avoid creating arrays during retrieval. ( This option to allow reusing a results array is used in Unity physics hit test functions so I don't consider it too unreasonable.)

2) getIndex() not called if objects.length >0 since objects are only stored in leaf nodes.

All npm tests passed.

I don't consider this premature optimization because geometric queries are often performance critical by nature. (Graphics and game libraries, thousands of hit tests per frame, etc. ) I didn't test these changes were actually faster but it should be.

Don't know about the whitespace. VSCode likes to autoformat.