ubilabs / kd-tree-javascript

JavaScript k-d Tree Implementation
MIT License
642 stars 109 forks source link

Trying to fix remove func #25 #31

Closed mariosgit closed 1 year ago

mariosgit commented 1 year ago

Findings:

buildTree

When given a set of points with same coordinates in a dimension, they end up in left and right part of the tree. Is this within spec? Not sure. However the nodeSearch function expects exactly this and will fail and returns nothing, thus nothing is removed.

My fix is a search for differences in the coordinates and split there. This can lead to unbalanced trees, optimizing is left to the user :)

removeNode

This function resorts the tree when a root node is removed, results where strange, I skipped it and instead I rebuild the subtree using the buildTree func.

Sideeffects

Sorry my editor did reformat some of the code.

Did not rebuild min.js

mariosgit commented 1 year ago

My usecase looked like this, in the jsfiddle it seems to work.

https://jsfiddle.net/rphak8ut/34/