@Override public final void destroyProxy(int proxyId) { assert (0 <= proxyId && proxyId < m_nodeCapacity); DynamicTreeNode node = m_nodes[proxyId]; assert (node.isLeaf()); removeLeaf(node); freeNode(node); }
@Override public int getMaxBalance() { int maxBalance = 0; for (int i = 0; i < m_nodeCapacity; ++i) { final DynamicTreeNode node = m_nodes[i]; if (node.height <= 1) { continue; } assert (node.isLeaf() == false); DynamicTreeNode child1 = node.child1; DynamicTreeNode child2 = node.child2; int balance = MathUtils.abs(child2.height - child1.height); maxBalance = MathUtils.max(maxBalance, balance); } return maxBalance; }
private final int computeHeight(DynamicTreeNode node) { assert (0 <= node.id && node.id < m_nodeCapacity); if (node.isLeaf()) { return 0; } int height1 = computeHeight(node.child1); int height2 = computeHeight(node.child2); return 1 + MathUtils.max(height1, height2); }
private void validateStructure(DynamicTreeNode node) { if (node == null) { return; } assert (node == m_nodes[node.id]); if (node == m_root) { assert (node.parent == null); } DynamicTreeNode child1 = node.child1; DynamicTreeNode child2 = node.child2; if (node.isLeaf()) { assert (child1 == null); assert (child2 == null); assert (node.height == 0); return; } assert (child1 != null && 0 <= child1.id && child1.id < m_nodeCapacity); assert (child2 != null && 0 <= child2.id && child2.id < m_nodeCapacity); assert (child1.parent == node); assert (child2.parent == node); validateStructure(child1); validateStructure(child2); }
assert (0 <= proxyId && proxyId < m_nodeCapacity); final DynamicTreeNode node = m_nodes[proxyId]; assert (node.isLeaf());
private void validateMetrics(DynamicTreeNode node) { if (node == null) { return; } DynamicTreeNode child1 = node.child1; DynamicTreeNode child2 = node.child2; if (node.isLeaf()) { assert (child1 == null); assert (child2 == null); assert (node.height == 0); return; } assert (child1 != null && 0 <= child1.id && child1.id < m_nodeCapacity); assert (child2 != null && 0 <= child2.id && child2.id < m_nodeCapacity); int height1 = child1.height; int height2 = child2.height; int height; height = 1 + MathUtils.max(height1, height2); assert (node.height == height); AABB aabb = new AABB(); aabb.combine(child1.aabb, child2.aabb); assert (aabb.lowerBound.equals(node.aabb.lowerBound)); assert (aabb.upperBound.equals(node.aabb.upperBound)); validateMetrics(child1); validateMetrics(child2); }
if (node.isLeaf()) { node.parent = null; nodes[count] = i;
if (node.isLeaf()) { subInput.p1.x = p1x; subInput.p1.y = p1y;
if (A.isLeaf() || A.height < 2) { return iA;