UNPKG

@antv/layout

Version:
84 lines (72 loc) 2.42 kB
import tree_add, { addAll } from './add.js'; import tree_cover from './cover.js'; import tree_data from './data.js'; import tree_extent from './extent.js'; import tree_find from './find.js'; import { findAllWithinRadius } from './findAll.js'; import tree_remove, { removeAll } from './remove.js'; import tree_root from './root.js'; import tree_size from './size.js'; import tree_visit from './visit.js'; import tree_visitAfter from './visitAfter.js'; import tree_x, { defaultX } from './x.js'; import tree_y, { defaultY } from './y.js'; import tree_z, { defaultZ } from './z.js'; function octree(nodes, x, y, z) { var tree = new Octree(x == null ? defaultX : x, y == null ? defaultY : y, z == null ? defaultZ : z, NaN, NaN, NaN, NaN, NaN, NaN); return nodes == null ? tree : tree.addAll(nodes); } function Octree(x, y, z, x0, y0, z0, x1, y1, z1) { this._x = x; this._y = y; this._z = z; this._x0 = x0; this._y0 = y0; this._z0 = z0; this._x1 = x1; this._y1 = y1; this._z1 = z1; this._root = undefined; } function leaf_copy(leaf) { var copy = {data: leaf.data}, next = copy; while (leaf = leaf.next) next = next.next = {data: leaf.data}; return copy; } var treeProto = octree.prototype = Octree.prototype; treeProto.copy = function() { var copy = new Octree(this._x, this._y, this._z, this._x0, this._y0, this._z0, this._x1, this._y1, this._z1), node = this._root, nodes, child; if (!node) return copy; if (!node.length) return copy._root = leaf_copy(node), copy; nodes = [{source: node, target: copy._root = new Array(8)}]; while (node = nodes.pop()) { for (var i = 0; i < 8; ++i) { if (child = node.source[i]) { if (child.length) nodes.push({source: child, target: node.target[i] = new Array(8)}); else node.target[i] = leaf_copy(child); } } } return copy; }; treeProto.add = tree_add; treeProto.addAll = addAll; treeProto.cover = tree_cover; treeProto.data = tree_data; treeProto.extent = tree_extent; treeProto.find = tree_find; treeProto.findAllWithinRadius = findAllWithinRadius; treeProto.remove = tree_remove; treeProto.removeAll = removeAll; treeProto.root = tree_root; treeProto.size = tree_size; treeProto.visit = tree_visit; treeProto.visitAfter = tree_visitAfter; treeProto.x = tree_x; treeProto.y = tree_y; treeProto.z = tree_z; export { octree as default }; //# sourceMappingURL=octree.js.map