forEach method

void forEach(
  1. bool cb(
    1. int id,
    2. double left,
    3. double top,
    4. double width,
    5. double height,
    )
)

Visit all objects in this node and its children. The walk stops when it iterates over all objects or when the callback returns false.

Implementation

@pragma('vm:prefer-inline')
void forEach(
  bool Function(
    int id,
    double left,
    double top,
    double width,
    double height,
  ) cb,
) {
  if (isEmpty) return;
  if (subdivided) {
    _northWest!.forEach(cb);
    _northEast!.forEach(cb);
    _southWest!.forEach(cb);
    _southEast!.forEach(cb);
  } else {
    final objects = tree._objects;
    int offset;
    for (final id in _ids) {
      offset = id * QuadTree._objectSize;
      final next = cb(
        id, // id of the object
        objects[offset + 0], // left
        objects[offset + 1], // top
        objects[offset + 2], // width
        objects[offset + 3], // height
      );
      if (next) continue;
      return;
    }
  }
}