hasCollision method

bool hasCollision(
  1. T item,
  2. MapRectangle boundary
)

Checks if an item collides with any existing items in the index.

Uses grid-based lookup to efficiently check only items in nearby cells. Handles exceptions gracefully by assuming no collision on error.

item Item to check for collisions Returns true if collision detected, false otherwise

Implementation

bool hasCollision(T item, MapRectangle boundary) {
  final cells = _getCells(boundary);
  for (final cell in cells) {
    final cellItems = _grid[cell];
    if (cellItems != null) {
      for (final existing in cellItems) {
        try {
          if ((existing as RenderInfo).clashesWith((item as RenderInfo))) {
            return true;
          }
        } catch (error) {
          // If we can't determine collision, assume no collision
          continue;
        }
      }
    }
  }
  return false;
}