diff --git a/index.js b/index.js index f398b8d..568596d 100644 --- a/index.js +++ b/index.js @@ -247,7 +247,7 @@ export default class Flatbush { } } - nodeIndex = q.pop() >> 1; + nodeIndex = q.length ? q.pop() >> 1 : undefined; } q.clear(); diff --git a/test.js b/test.js index 771ad29..a626691 100644 --- a/test.js +++ b/test.js @@ -155,6 +155,12 @@ test('k-nearest-neighbors query accepts filterFn', () => { assert.deepEqual(ids.sort(compare), [6, 16, 18, 24, 54, 80].sort(compare)); }); +test('performs a k-nearest-neighbors query with all items', () => { + const index = createIndex(); + const ids = index.neighbors(50, 50); + assert.deepEqual(ids.length, data.length >> 2); +}); + test('returns index of newly-added rectangle', () => { const count = 5; const index = new Flatbush(count);