getActiveCellsInfo method

List<CellDebugInfo> getActiveCellsInfo()

Gets all cell bounds with their object counts for debug visualization.

Returns a list of records containing the cell bounds and the number of objects in that cell, broken down by type.

Implementation

List<CellDebugInfo> getActiveCellsInfo() {
  return _spatialGrid.entries.map((entry) {
    final (cellX, cellY) = parseCellKey(entry.key);
    final objects = entry.value;

    // Count objects by type based on ID prefix
    int nodes = 0, ports = 0, connections = 0, annotations = 0;
    for (final id in objects) {
      if (id.startsWith('node_')) {
        nodes++;
      } else if (id.startsWith('port_')) {
        ports++;
      } else if (id.startsWith('conn_')) {
        connections++;
      } else if (id.startsWith('annot_')) {
        annotations++;
      }
    }

    return CellDebugInfo(
      bounds: cellBounds(cellX, cellY),
      cellX: cellX,
      cellY: cellY,
      nodeCount: nodes,
      portCount: ports,
      connectionCount: connections,
      annotationCount: annotations,
    );
  }).toList();
}