query method

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.

@param callback @param araabbgAABB

Implementation

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

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

    if (AABB.testOverlap(node.aabb, aabb)) {
      if (node.child1 == null) {
        bool proceed = callback.treeCallback(node.id);
        if (!proceed) {
          return;
        }
      } else {
        if (nodeStack.length - nodeStackIndex - 2 <= 0) {
          List<DynamicTreeNode> newBuffer =
              List<DynamicTreeNode>(nodeStack.length * 2);
          BufferUtils.arraycopy(nodeStack, 0, newBuffer, 0, nodeStack.length);
          nodeStack = newBuffer;
        }
        nodeStack[nodeStackIndex++] = node.child1;
        nodeStack[nodeStackIndex++] = node.child2;
      }
    }
  }
}