Skip to content

Commit

Permalink
move FlatQueue init to finish()
Browse files Browse the repository at this point in the history
  • Loading branch information
leeoniya committed Aug 30, 2022
1 parent 4293e90 commit 8f728af
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,6 @@ export default class Flatbush {
new Uint16Array(this.data, 2, 1)[0] = nodeSize;
new Uint32Array(this.data, 4, 1)[0] = numItems;
}

// a priority queue for k-nearest-neighbors queries
this._queue = new FlatQueue();
}

add(minX, minY, maxX, maxY) {
Expand Down Expand Up @@ -131,6 +128,9 @@ export default class Flatbush {
throw new Error(`Added ${this._pos >> 2} items when expected ${this.numItems}.`);
}

// a priority queue for k-nearest-neighbors queries
this._queue = new FlatQueue();

if (this.numItems <= this.nodeSize) {
// only one node, skip sorting and just fill the root box
this._boxes[this._pos++] = this.minX;
Expand Down

0 comments on commit 8f728af

Please sign in to comment.