point-cluster
Advanced tools
Comparing version
{ | ||
"name": "point-cluster", | ||
"version": "3.0.3", | ||
"version": "3.1.0", | ||
"description": "Fast nd point clustering.", | ||
@@ -48,2 +48,3 @@ "main": "index.js", | ||
"clamp": "^1.0.1", | ||
"dtype": "^2.0.0", | ||
"flatten-vertex-data": "^1.0.0", | ||
@@ -50,0 +51,0 @@ "is-obj": "^1.0.1", |
21
quad.js
@@ -17,2 +17,3 @@ /** | ||
const isObj = require('is-obj') | ||
const dtype = require('dtype') | ||
@@ -28,2 +29,3 @@ | ||
maxDepth: 'depth maxDepth maxdepth level maxLevel maxlevel levels', | ||
dtype: 'type dtype format out dst output destination' | ||
// sort: 'sortBy sortby sort', | ||
@@ -44,3 +46,12 @@ // pick: 'pick levelPoint', | ||
let n = srcPoints.length >>> 1 | ||
let ids = new Uint32Array(n) | ||
let ids | ||
if (!options.dtype) options.dtype = 'array' | ||
if (typeof options.dtype === 'string') { | ||
ids = new (dtype(options.dtype))(n) | ||
} | ||
else if (options.dtype) { | ||
ids = options.dtype | ||
if (Array.isArray(ids)) ids.length = n | ||
} | ||
for (let i = 0; i < n; ++i) { | ||
@@ -71,3 +82,9 @@ ids[i] = i | ||
for (let level = 0; level < levels.length; level++) { | ||
ids.set(levels[level], offset) | ||
let levelItems = levels[level] | ||
if (ids.set) ids.set(levelItems, offset) | ||
else { | ||
for (let i = 0, l = levelItems.length; i < l; i++) { | ||
ids[i + offset] = levelItems[i] | ||
} | ||
} | ||
let nextOffset = offset + levels[level].length | ||
@@ -74,0 +91,0 @@ offsets[level] = [offset, nextOffset] |
@@ -46,2 +46,3 @@ # point-cluster [](https://travis-ci.org/dfcreative/point-cluster) [](http://github.com/badges/stability-badges) | ||
`depth` | `256` | Max number of levels. Points below the indicated level are grouped into single level. | ||
`output` | `'array'` | Output data array or data format. For available formats see [dtype](https://npmjs.org/package/dtype). | ||
<!-- `node` | `1` | Min size of node, ie. tree traversal is stopped once the node contains less than the indicated number of points. --> | ||
@@ -48,0 +49,0 @@ <!-- `sort` | `'z'` | Sort values within levels by `x`-, `y`-coordinate, `z`-curve or `r` - point radius. `z` is the fastest for init, `x` or `y` are faster for `lod` and `r` is the most data-relevant. --> |
13
test.js
@@ -12,8 +12,19 @@ 'use strict' | ||
t.deepEqual(index.slice(), [0, 1,3,2, 4,5, 6]) | ||
t.deepEqual(index.subarray(), [0, 1,3,2, 4,5, 6]) | ||
t.end() | ||
}) | ||
t('quad: output container', t => { | ||
let points = [.15,.8, .2,.15, .6,.6, .6,.45, .8,.1, .9,.6, .91,.61] | ||
let arr = [] | ||
let index = cluster(points, {bounds: [0,0,1,1], output: arr}) | ||
t.deepEqual(arr.slice(), [0, 1,3,2, 4,5, 6]) | ||
t.equal(index, arr) | ||
t.end() | ||
}) | ||
t('quad: max depth', t => { | ||
@@ -20,0 +31,0 @@ let points = [] |
30326
3%706
3.52%89
1.14%9
12.5%+ Added