moveProxy method

bool moveProxy (int proxyId, AABB aabb, Vector2 displacement)
override

Move a proxy with a swepted AABB. If the proxy has moved outside of its fattened AABB, then the proxy is removed from the tree and re-inserted. Otherwise the function returns immediately.

@return true if the proxy was re-inserted.

Implementation

bool moveProxy(int proxyId, final AABB aabb, Vector2 displacement) {
  assert(0 <= proxyId && proxyId < _nodeCapacity);
  final int node = proxyId;
  assert(_child1[node] == NULL_NODE);

  final AABB nodeAABB = _aabb[node];
  // if (nodeAABB.contains(aabb)) {
  if (nodeAABB.lowerBound.x <= aabb.lowerBound.x &&
      nodeAABB.lowerBound.y <= aabb.lowerBound.y &&
      aabb.upperBound.x <= nodeAABB.upperBound.x &&
      aabb.upperBound.y <= nodeAABB.upperBound.y) {
    return false;
  }

  _removeLeaf(node);

  // Extend AABB
  final Vector2 lowerBound = nodeAABB.lowerBound;
  final Vector2 upperBound = nodeAABB.upperBound;
  lowerBound.x = aabb.lowerBound.x - Settings.aabbExtension;
  lowerBound.y = aabb.lowerBound.y - Settings.aabbExtension;
  upperBound.x = aabb.upperBound.x + Settings.aabbExtension;
  upperBound.y = aabb.upperBound.y + Settings.aabbExtension;

  // Predict AABB displacement.
  final double dx = displacement.x * Settings.aabbMultiplier;
  final double dy = displacement.y * Settings.aabbMultiplier;
  if (dx < 0.0) {
    lowerBound.x += dx;
  } else {
    upperBound.x += dx;
  }

  if (dy < 0.0) {
    lowerBound.y += dy;
  } else {
    upperBound.y += dy;
  }

  _insertLeaf(proxyId);
  return true;
}