query method

List<T> query(
  1. Rect bounds
)

Ultra-fast query with surgical caching

Implementation

List<T> query(Rect bounds) {
  // Use surgical cache during dragging for ultra-fast updates
  if (_isDragging && _shouldUseSurgicalCache(bounds)) {
    return _applySurgicalUpdates(bounds);
  }

  if (_shouldUseCache(bounds)) {
    return _cachedVisibleObjects;
  }

  final result = <T>[];

  // Use spatial grid for large object counts
  if (_objects.length > 50 && _spatialGrid.isNotEmpty) {
    _queryWithSpatialGrid(bounds, result);
  } else if (_objects.length > 20 && _spatialRects.isNotEmpty) {
    _queryWithSpatialRects(bounds, result);
  } else {
    _queryDirectIteration(bounds, result);
  }

  // Cache result for next query
  if (enableCaching) {
    _lastQueryBounds = bounds;
    _cachedVisibleObjects = List.from(result);
  }

  return result;
}