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

Pick dtype for the index array automatically and set the default dtype for coordinates to Float32Array #22

Merged
merged 3 commits into from
Sep 7, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix datatype of the index-vector to uint. Change default value for co…
…ordinate values to `Float32Array`.
  • Loading branch information
flekschas committed Sep 6, 2018
commit 6931b46a3106cbcbe05ad8cc177afefc2933d238
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Creates an index from the given points.
- `points`: Input array of points.
- `getX`, `getY`: Functions to get `x` and `y` from an input point. By default, it assumes `[x, y]` format.
- `nodeSize`: Size of the KD-tree node, `64` by default. Higher means faster indexing but slower search, and vise versa.
- `arrayType`: Array type to use for storing indices and coordinate values. `Array` by default, but if your coordinates are integer values, `Int32Array` makes things a bit faster.
- `arrayType`: Array type to use for storing coordinate values. `Float32Array` by default, but if your coordinates are integer values, `Int32Array` makes things a bit faster.

```js
var index = kdbush(points, (p) => p.x, (p) => p.y, 64, Int32Array);
Expand Down
6 changes: 4 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ export default function kdbush(points, getX, getY, nodeSize, ArrayType) {
function KDBush(points, getX, getY, nodeSize, ArrayType) {
getX = getX || defaultGetX;
getY = getY || defaultGetY;
ArrayType = ArrayType || Array;
ArrayType = ArrayType || Float32Array;
flekschas marked this conversation as resolved.
Show resolved Hide resolved

this.nodeSize = nodeSize || 64;
this.points = points;

this.ids = new ArrayType(points.length);
const IndexArrayType = points.length < 65536 ? Uint16Array : Uint32Array;

this.ids = new IndexArrayType(points.length);
this.coords = new ArrayType(points.length * 2);

for (var i = 0; i < points.length; i++) {
Expand Down