buildFromParticles method

void buildFromParticles(
  1. List particles,
  2. List<int> visibleParticles
)

Bulk builds the tree from a list of particles particles: Complete list of particle objects visibleParticles: Indices of particles to include in tree

Optimization:

  • Clears existing tree first
  • Performs bulk insertion followed by memory optimization

Implementation

void buildFromParticles(
  List<dynamic> particles, // Using dynamic to match original interface
  List<int> visibleParticles,
) {
  clear(); // Reset the tree

  // Insert all visible particles
  for (final i in visibleParticles) {
    if (i < particles.length) {
      final p = particles[i];
      // Create QuadTreeParticle with index and position
      insert(QuadTreeParticle(i, p.position.dx, p.position.dy));
    }
  }

  // Optimize memory after bulk insertion
  _root.optimizeMemory();
}