docs: protected void rebuildTree() {
      final int dim = root.getDimensionality();
      double t = estimateThreshold(root) / leaves;
      t *= t;
      // Never decrease the threshold.
      thresholdsq = t > thresholdsq ? t : thresholdsq;
      LOG.debug("New squared threshold: " + thresholdsq);
  
      LeafIterator iter = new LeafIterator(root); // Will keep the old root.
      assert (iter.valid());
      ClusteringFeature first = iter.get();
  
      leaves = 0;
      // Make a new root node:
      root = new TreeNode(dim, capacity);
      root.children[0] = first;
      root.addToStatistics(first);
      ++leaves;
      for(iter.advance(); iter.valid(); iter.advance()) {
        TreeNode other = insert(root, iter.get());
        // Handle root overflow:
        if(other != null) {
          TreeNode newnode = new TreeNode(dim, capacity);
          newnode.addToStatistics(newnode.children[0] = root);
          newnode.addToStatistics(newnode.children[1] = other);
          root = newnode;
        }
      }
    }