moveProxy method
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. It returns true if the proxy was re-inserted.
Implementation
@override
bool moveProxy(int proxyId, AABB aabb, Vector2 displacement) {
assert(aabb.isValid());
assert(0 <= proxyId && proxyId < _nodeCapacity);
final node = _nodes[proxyId];
assert(node.child1 == null);
final nodeAABB = node.aabb;
// 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 lowerBound = nodeAABB.lowerBound;
final 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 dx = displacement.x * settings.aabbMultiplier;
final 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;
}