hasCollision method
Checks if an item collides with any existing items in the index.
Uses grid-based lookup to efficiently check only items in nearby cells.
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) {
if (existing.clashesWith(item)) {
return true;
}
}
}
}
return false;
}