getStats method

Map<String, dynamic> getStats()

Gathers statistics about the tree structure

Implementation

Map<String, dynamic> getStats() {
  int nodeCount = 1; // Count this node
  int leafCount = isLeaf ? 1 : 0;
  int particleCount = particles.length;
  int currentMaxDepth = depth;
  int compressedNodes = isCompressed ? 1 : 0;
  int sparseNodes = children.length < 4 && !isLeaf ? 1 : 0;

  // Aggregate statistics from children
  for (final CompressedQuadTreeNode child in children.values) {
    final childStats = child.getStats();
    nodeCount += childStats['nodes'] as int;
    leafCount += childStats['leaves'] as int;
    particleCount += childStats['particles'] as int;
    currentMaxDepth = math.max(
      currentMaxDepth,
      childStats['maxDepth'] as int,
    );
    compressedNodes += childStats['compressedNodes'] as int;
    sparseNodes += childStats['sparseNodes'] as int;
  }

  return {
    'nodes': nodeCount,
    'leaves': leafCount,
    'particles': particleCount,
    'maxDepth': currentMaxDepth,
    'compressedNodes': compressedNodes,
    'sparseNodes': sparseNodes,
    'compressionRatio': compressedNodes / nodeCount,
    'sparsityRatio': sparseNodes / nodeCount,
  };
}