search method

List<T> search(
  1. RBushBox bbox
)

Looks for all items that intersect with bbox.

Implementation

List<T> search(RBushBox bbox) {
  _RBushNode<T> node = data;
  final List<T> result = [];

  if (!bbox.intersects(node)) return result;

  final List<_RBushNode<T>> nodesToSearch = [];

  while (true) {
    if (node.leaf) {
      for (final child in node.leafChildren) {
        if (bbox.intersects(toBBox(child))) {
          result.add(child);
        }
      }
    } else {
      for (final child in node.children) {
        if (bbox.intersects(child)) {
          if (bbox.contains(child)) {
            _all(child, result);
          } else {
            nodesToSearch.add(child);
          }
        }
      }
    }
    if (nodesToSearch.isEmpty) break;
    node = nodesToSearch.removeLast();
  }

  return result;
}