Find efficiently in k-dimensional data
API
new Octree/new Quadtree(array<{[key]}>, <{key?: string = 'coords', transform?: function = x => x, depth?: number = 4}>)
add(array<{[key]}>)
: Add an array of itemsclosest(value)
: Search for the closest item bykey
valueremove(value)
: Remove an item from the tree bykey
value
;; // colors are 3-dimensional, so use Octree // simple hex-to-rgb (assuming no short formats, else see https://unpkg.com/color-tf/hexToRgb.js)const hexToRgb = s s s; const colors = Object; // Octree constructor needs an array of {[key], ...} objects, where key is configurable// We'll use 'hex' here, and add a 'transform' property to map those 'hex' values to 3D coordinatesconst tree = colors key: 'hex' transform: hexToRgb ;console; // { name: 'Majorelle Blue', hex: '#6050dc', d2: 273 }tree;console; // { name: 'Iris', hex: '#5a4fcf', d2: 402 }