timohausmann / quadtree-ts

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

Remove/delete shape #1

Closed greenbech closed 11 months ago

greenbech commented 2 years ago

Thanks for a great package - good documentation and a clean implementation!

I wonder if a remove/delete API for shapes is on the roadmap? In my intended usecase the world is mostly static, but sometimes a line it split in two. It seems like a waiste of resources to rebuild the entire datastructure when just one node is changed/deleted. What's your thoughts on that?

timohausmann commented 2 years ago

I agree that this would be helpful. I could imagine methods to update/remove single shapes, and/or a static flag on shapes (so they would not be affected by clear).

Due to the recursive nature, skipping the rebuild could result in nodes without objects, but the benefits should outweight that.

jonit-dev commented 1 year ago

https://github.com/jonit-dev/quadtree-ts

jonit-dev commented 1 year ago

I forked and added the remove behavior

timohausmann commented 11 months ago

I refactored your code a bit and added tests and docs. In the simple example there are now "remove" buttons: https://timohausmann.github.io/quadtree-ts/examples/simple/

I also added a helper function "join" that can safely cleanup the vacant subnodes. This can be skipped with a "fast" flag.

Docs: https://timohausmann.github.io/quadtree-ts/documentation/classes/Quadtree.html#remove

If you have the time I'd be happy to hear your feedback.

npm install -S @timohausmann/quadtree-ts@latest

timohausmann commented 11 months ago

Alright fine, I will slap on an update method and example aswell:

https://timohausmann.github.io/quadtree-ts/examples/update/

https://timohausmann.github.io/quadtree-ts/documentation/classes/Quadtree.html#update

Please let me know if your issue isn't resolved.