diff --git a/quad.js b/quad.js index e0c9f84..cfb977c 100644 --- a/quad.js +++ b/quad.js @@ -195,12 +195,15 @@ module.exports = function cluster (srcPoints, options) { if (typeof options.d === 'number') d = [options.d, options.d] else if (options.d.length) d = options.d - maxLevel = Math.max( - Math.ceil(-log2(Math.abs(d[0]) / (bounds[2] - bounds[0]))), - Math.ceil(-log2(Math.abs(d[1]) / (bounds[3] - bounds[1]))), + maxLevel = Math.min( + Math.max( + Math.ceil(-log2(Math.abs(d[0]) / (bounds[2] - bounds[0]))), + Math.ceil(-log2(Math.abs(d[1]) / (bounds[3] - bounds[1]))) + ), maxLevel ) } + maxLevel = Math.min(maxLevel, levels.length) // return levels of details if (options.lod) { diff --git a/test.js b/test.js index 0ed4567..33ea534 100644 --- a/test.js +++ b/test.js @@ -37,11 +37,13 @@ t('quad: max depth', t => { t.end() }) -t('quad: lod method', t => { +t.only('quad: lod method', t => { let points = [0,0, 1,1, 2,2, 3,3, 4,4, 5,5, 6,6, 7,7] let index = cluster(points) + t.deepEqual(index.range({lod: true, d: 1e-10}), [[0,1], [1,3], [3,6], [6,8]]) + t.deepEqual(index.range({lod: true, level: 400}), [[0,1], [1,3], [3,6], [6,8]]) t.deepEqual(index.range({lod: true}), [[0,1], [1,3], [3,6], [6,8]]) t.deepEqual(index.range([1,6], {lod: true}), [[0,1], [1,2], [3,4], [6,7]])