Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

when building kd-tree, sort break the binding between indces and points #16

Open
exialym opened this issue Mar 9, 2017 · 2 comments
Open

Comments

@exialym
Copy link

exialym commented Mar 9, 2017

No description provided.

@sunshichen
Copy link

How do you solve this problem? Is there anyway to get the nodes' indices of original buffer?

@benmaier
Copy link

I solved this by replacing line 29 (https://github.com/ubilabs/kd-tree-javascript/blob/master/kdTree.js#L29)

  function kdTree(points, metric, dimensions) {

with

  function kdTree(points, metric, dimensions) {
    
    points = points.slice();
    points.forEach(function(p, i){
      p.i = i;
    });

then, each result obiect in the nearest-array has its original position in the points-array saved in the .i attribute. Also, the slice prevents mutation of the point positions, which happened in my use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants