From f3d24b3ba3e67abcb9a531dfc8095a5922ca83c0 Mon Sep 17 00:00:00 2001 From: Vladimir Agafonkin Date: Wed, 19 Apr 2023 19:11:15 +0300 Subject: [PATCH] fix index.neighbors freezing with just x/y args --- index.js | 2 +- test.js | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) 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);