SpatialGrid<T extends SpatialIndexable> class

Ultra-fast spatial grid system using grid-based hashing. This is the low-level implementation used by SpatialIndex. Optimized for large numbers of 2D objects with frequent position updates.

Constructors

SpatialGrid({double gridSize = 500.0, bool enableCaching = true})

Properties

activeCellKeys Iterable<String>
Gets all active grid cell keys for debug visualization.
no setter
enableCaching bool
final
gridSize double
final
hashCode int
The hash code for this object.
no setterinherited
isUsingSpatialGrid bool
Check if spatial grid is being used
no setter
objectCount int
Get total number of objects in the index
no setter
objects Iterable<T>
Get all objects (for type-based filtering)
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
stats SpatialIndexStats
Get performance statistics
no setter

Methods

addOrUpdate(T object) → void
Add or update an object in the spatial index
cellBounds(int cellX, int cellY) Rect
Converts grid coordinates to world bounds.
clear() → void
Clear all objects from the spatial index
countWhere(bool test(T object)) int
Count objects matching a predicate
endDragging() → void
End drag optimization mode and rebuild spatial index for dragged objects
flushPendingUpdates() → void
Force process any pending updates immediately
getActiveCellsInfo() List<CellDebugInfo>
Gets all cell bounds with their object counts for debug visualization.
getObject(String objectId) → T?
Get object by ID
getObjectCountInCell(String cellKey) int
Gets the object count for a specific cell.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
query(Rect bounds) List<T>
Ultra-fast query with surgical caching
queryPoint(Offset point, {double radius = 0}) List<T>
Query objects near a specific point for hit testing.
remove(String objectId) → void
Remove an object from the spatial index
startDragging(List<String> objectIds) → void
Start drag optimization mode for specified objects. During drag, spatial index is not updated. Call endDragging to rebuild.
toString() String
A string representation of this object.
inherited
updateDraggingObjects(List<T> objects) → void
Track dragging objects without updating spatial index during drag. Spatial index will be rebuilt when drag ends via endDragging.

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

parseCellKey(String cellKey) → (int, int)
Parses a cell key into its (x, y) coordinates.