1
0
mirror of https://github.com/d3/d3.git synced 2025-12-08 19:46:24 +00:00
d3/docs/components/quadtreeVisitParent.js
2023-06-11 17:39:33 -07:00

16 lines
891 B
JavaScript

export default function quadtree_visitParent(callback) {
let quads = [], q, node = this._root, parent, child, x0, y0, x1, y1, xm, ym;
if (node) quads.push({node, x0: this._x0, y0: this._y0, x1: this._x1, y1: this._y1});
while ((q = quads.pop())) {
node = q.node, parent = q.parent;
if (parent) callback(parent.x0, parent.y0, parent.x1, parent.y1);
if (!node.length) continue;
x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1, xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
if ((child = node[3])) quads.push({parent: q, node: child, x0: xm, y0: ym, x1: x1, y1: y1});
if ((child = node[2])) quads.push({parent: q, node: child, x0: x0, y0: ym, x1: xm, y1: y1});
if ((child = node[1])) quads.push({parent: q, node: child, x0: xm, y0: y0, x1: x1, y1: ym});
if ((child = node[0])) quads.push({parent: q, node: child, x0: x0, y0: y0, x1: xm, y1: ym});
}
return this;
}