query method

  1. @override
void query(
  1. TreeCallback callback,
  2. AABB aabb
)
override

Query an AABB for overlapping proxies. The callback class is called for each proxy that overlaps the supplied AABB.

Implementation

@override
void query(TreeCallback callback, AABB aabb) {
  assert(aabb.isValid());
  nodeStackIndex = 0;
  _nodeStack[nodeStackIndex++] = _root;

  while (nodeStackIndex > 0) {
    final node = _nodeStack[--nodeStackIndex];
    if (node == null) {
      continue;
    }

    if (AABB.testOverlap(node.aabb, aabb)) {
      if (node.child1 == null) {
        final proceed = callback.treeCallback(node.id);
        if (!proceed) {
          return;
        }
      } else {
        if (_nodeStack.length - nodeStackIndex - 2 <= 0) {
          final previousSize = _nodeStack.length;
          _nodeStack = _nodeStack +
              List.generate(
                previousSize,
                (i) => DynamicTreeNode(previousSize + i),
              );
        }
        _nodeStack[nodeStackIndex++] = node.child1;
        _nodeStack[nodeStackIndex++] = node.child2;
      }
    }
  }
}