copy method
Implementation
QuadTree<T> copy() {
QuadTree<T> copy = QuadTree(xFun, yFun, _x0, _y0, _x1, _y1);
QuadNode<T>? node = _root;
List<Map<String, dynamic>> nodes = [];
QuadNode<T>? child;
if (node == null) {
return copy;
}
if (!node.hasChild) {
copy._root = leafCopy(node);
return copy;
}
copy._root = QuadNode(length: 4);
nodes = [
{'source': node, 'target': copy._root}
];
Map<String, dynamic> nodeTmp;
while (nodes.isNotEmpty) {
nodeTmp = nodes.removeLast();
for (int i = 0; i < 4; ++i) {
child = nodeTmp['source'][i];
if (child == null) {
continue;
}
if (child.hasChild) {
var tmp = {'source': child, 'target': nodeTmp['target'][i] = QuadNode(length: 4)};
nodes.add(tmp);
} else {
nodeTmp['target'][i] = leafCopy(child);
}
}
}
return copy;
}