diff --git a/index.js b/index.js index 4dce8d36..0d339b28 100644 --- a/index.js +++ b/index.js @@ -102,7 +102,7 @@ export default class Supercluster { } const tree = this.trees[this._limitZoom(zoom)]; - const ids = tree.range(lngX(minLng), latY(maxLat), lngX(maxLng), latY(minLat)); + const ids = tree.range(fround(lngX(minLng)), fround(latY(maxLat)), fround(lngX(maxLng)), fround(latY(minLat))); const data = tree.data; const clusters = []; for (const id of ids) { diff --git a/test/test.js b/test/test.js index 5fb05107..4f50b204 100644 --- a/test/test.js +++ b/test/test.js @@ -179,3 +179,15 @@ test('does not throw on zero items', () => { assert.deepEqual(index.getClusters([-180, -85, 180, 85], 0), []); }); }); + +test('returns points that lie exactly on the query bbox edge', () => { + const index = new Supercluster().load([ + {type: 'Feature', properties: {name: 'a'}, geometry: {type: 'Point', coordinates: [-123.211605, 43.972615]}}, + {type: 'Feature', properties: {name: 'b'}, geometry: {type: 'Point', coordinates: [-123.245515, 43.9150233333333]}}, + {type: 'Feature', properties: {name: 'c'}, geometry: {type: 'Point', coordinates: [-123.192528333333, 44.0307166666667]}}, + {type: 'Feature', properties: {name: 'd'}, geometry: {type: 'Point', coordinates: [-123.194573333333, 44.0107]}} + ]); + const bbox = [-123.245515, 43.9150233333333, -123.192528333333, 44.0307166666667]; + const names = index.getClusters(bbox, 16).map(p => p.properties.name).sort(); + assert.deepEqual(names, ['a', 'b', 'c', 'd']); +});