UNPKG

d3-octree

Version:

Three-dimensional recursive spatial subdivision.

21 lines (19 loc) 1.13 kB
import Octant from "./octant.js"; export default function(callback) { var octs = [], q, node = this._root, child, x0, y0, z0, x1, y1, z1; if (node) octs.push(new Octant(node, this._x0, this._y0, this._z0, this._x1, this._y1, this._z1)); while (q = octs.pop()) { if (!callback(node = q.node, x0 = q.x0, y0 = q.y0, z0 = q.z0, x1 = q.x1, y1 = q.y1, z1 = q.z1) && node.length) { var xm = (x0 + x1) / 2, ym = (y0 + y1) / 2, zm = (z0 + z1) / 2; if (child = node[7]) octs.push(new Octant(child, xm, ym, zm, x1, y1, z1)); if (child = node[6]) octs.push(new Octant(child, x0, ym, zm, xm, y1, z1)); if (child = node[5]) octs.push(new Octant(child, xm, y0, zm, x1, ym, z1)); if (child = node[4]) octs.push(new Octant(child, x0, y0, zm, xm, ym, z1)); if (child = node[3]) octs.push(new Octant(child, xm, ym, z0, x1, y1, zm)); if (child = node[2]) octs.push(new Octant(child, x0, ym, z0, xm, y1, zm)); if (child = node[1]) octs.push(new Octant(child, xm, y0, z0, x1, ym, zm)); if (child = node[0]) octs.push(new Octant(child, x0, y0, z0, xm, ym, zm)); } } return this; }