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

faster insertion and a static kdtree without node hierarchy #19

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ In computer science, a [k-d tree](http://en.wikipedia.org/wiki/K-d_tree) (short
### Usage

#### Using global exports
When you include the kd-tree script via HTML, the global variables *kdTree* and *BinaryHeap* will be exported.
When you include the kd-tree script via HTML, the global variables `kdTree`, `staticKdTree` and `BinaryHeap` will be exported.

```js
// Create a new tree from a list of points, a distance function, and a
Expand Down Expand Up @@ -44,6 +44,10 @@ tree.remove(point);
tree.balanceFactor();
```

The `staticKdTree` only shuffle the point array in place and does not build a separate hierarchy of nodes.
So it only proposes to build a tree from an array of points together with the *nearest* method.
Its advantage is that it does no memory allocation.

#### Using RequireJS
```js
requirejs(['path/to/kdTree.js'], function (ubilabs) {
Expand Down Expand Up @@ -87,7 +91,7 @@ var distance = function(a, b){
return Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2);
}

var tree = new kdTree(points, distance, ["x", "y"]);
var tree = new staticKdTree(points, distance, ["x", "y"]);

var nearest = tree.nearest({ x: 5, y: 5 }, 2);

Expand Down
3 changes: 2 additions & 1 deletion examples/basic/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ <h3>Controls</h3>
}
neighbors = $("#neighbors").val();
useTree = $("#useTree").attr('checked') ? true : false;
tree = new kdTree(points, distance, ["x", "y"]);
tree = new staticKdTree(points, distance, ["x", "y"]);
//tree = new kdTree(points, distance, ["x", "y"]);
}

$(function(){
Expand Down
11 changes: 1 addition & 10 deletions kdTree-min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading