fix index.neighbors freezing with just x/y args

This commit is contained in:
Vladimir Agafonkin 2023-04-19 19:11:15 +03:00
parent 41481c5c5e
commit f3d24b3ba3
2 changed files with 7 additions and 1 deletions

View File

@ -247,7 +247,7 @@ export default class Flatbush {
}
}
nodeIndex = q.pop() >> 1;
nodeIndex = q.length ? q.pop() >> 1 : undefined;
}
q.clear();

View File

@ -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);