insert method

void insert(
  1. T item,
  2. double x,
  3. double y
)

Inserts item at position (x, y). The same item may be inserted at multiple positions; each insertion is independent.

Example:

final SpatialGrid<String> g = SpatialGrid<String>(10)
  ..insert('a', 1, 1)
  ..insert('b', 5, 5);
g.queryRadius(0, 0, 3); // ['a']

Audited: 2026-06-12 11:26 EDT

Implementation

void insert(T item, double x, double y) {
  final (int, int) key = (_cell(x), _cell(y));
  _cells.putIfAbsent(key, () => <_Entry<T>>[]).add(_Entry<T>(item, x, y));
  _size++;
}