private final DynamicTreeNode allocateNode() { if (m_freeList == NULL_NODE) { assert (m_nodeCount == m_nodeCapacity); DynamicTreeNode[] old = m_nodes; m_nodeCapacity *= 2; m_nodes = new DynamicTreeNode[m_nodeCapacity]; System.arraycopy(old, 0, m_nodes, 0, old.length); // Build a linked list for the free list. for (int i = m_nodeCapacity - 1; i >= m_nodeCount; i--) { m_nodes[i] = new DynamicTreeNode(i); m_nodes[i].parent = (i == m_nodeCapacity - 1) ? null : m_nodes[i + 1]; m_nodes[i].height = -1; } m_freeList = m_nodeCount; } int nodeId = m_freeList; final DynamicTreeNode treeNode = m_nodes[nodeId]; m_freeList = treeNode.parent != null ? treeNode.parent.id : NULL_NODE; treeNode.parent = null; treeNode.child1 = null; treeNode.child2 = null; treeNode.height = 0; treeNode.userData = null; ++m_nodeCount; return treeNode; }
@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; }
public DynamicTree() { m_root = null; m_nodeCount = 0; m_nodeCapacity = 16; m_nodes = new DynamicTreeNode[16]; // Build a linked list for the free list. for (int i = m_nodeCapacity - 1; i >= 0; i--) { m_nodes[i] = new DynamicTreeNode(i); m_nodes[i].parent = (i == m_nodeCapacity - 1) ? null : m_nodes[i + 1]; m_nodes[i].height = -1; } m_freeList = 0; for (int i = 0; i < drawVecs.length; i++) { drawVecs[i] = new Vec2(); } }
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 final DynamicTreeNode allocateNode() { if (m_freeList == NULL_NODE) { assert (m_nodeCount == m_nodeCapacity); DynamicTreeNode[] old = m_nodes; m_nodeCapacity *= 2; m_nodes = new DynamicTreeNode[m_nodeCapacity]; System.arraycopy(old, 0, m_nodes, 0, old.length); // Build a linked list for the free list. for (int i = m_nodeCapacity - 1; i >= m_nodeCount; i--) { m_nodes[i] = new DynamicTreeNode(i); m_nodes[i].parent = (i == m_nodeCapacity - 1) ? null : m_nodes[i + 1]; m_nodes[i].height = -1; } m_freeList = m_nodeCount; } int nodeId = m_freeList; final DynamicTreeNode treeNode = m_nodes[nodeId]; m_freeList = treeNode.parent != null ? treeNode.parent.id : NULL_NODE; treeNode.parent = null; treeNode.child1 = null; treeNode.child2 = null; treeNode.height = 0; treeNode.userData = null; ++m_nodeCount; return treeNode; }
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); }
public DynamicTree() { m_root = null; m_nodeCount = 0; m_nodeCapacity = 16; m_nodes = new DynamicTreeNode[16]; // Build a linked list for the free list. for (int i = m_nodeCapacity - 1; i >= 0; i--) { m_nodes[i] = new DynamicTreeNode(i); m_nodes[i].parent = (i == m_nodeCapacity - 1) ? null : m_nodes[i + 1]; m_nodes[i].height = -1; } m_freeList = 0; for (int i = 0; i < drawVecs.length; i++) { drawVecs[i] = new Vec2(); } }
assert (0 <= proxyId && proxyId < m_nodeCapacity); final DynamicTreeNode node = m_nodes[proxyId]; assert (node.isLeaf());
private final DynamicTreeNode allocateNode() { if (m_freeList == NULL_NODE) { assert (m_nodeCount == m_nodeCapacity); DynamicTreeNode[] old = m_nodes; m_nodeCapacity *= 2; m_nodes = new DynamicTreeNode[m_nodeCapacity]; System.arraycopy(old, 0, m_nodes, 0, old.length); // Build a linked list for the free list. for (int i = m_nodeCapacity - 1; i >= m_nodeCount; i--) { m_nodes[i] = new DynamicTreeNode(i); m_nodes[i].parent = (i == m_nodeCapacity - 1) ? null : m_nodes[i + 1]; m_nodes[i].height = -1; } m_freeList = m_nodeCount; } int nodeId = m_freeList; final DynamicTreeNode treeNode = m_nodes[nodeId]; m_freeList = treeNode.parent != null ? treeNode.parent.id : NULL_NODE; treeNode.parent = null; treeNode.child1 = null; treeNode.child2 = null; treeNode.height = 0; treeNode.userData = null; ++m_nodeCount; return treeNode; }
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); }
private final DynamicTreeNode allocateNode() { if (m_freeList == NULL_NODE) { assert (m_nodeCount == m_nodeCapacity); DynamicTreeNode[] old = m_nodes; m_nodeCapacity *= 2; m_nodes = new DynamicTreeNode[m_nodeCapacity]; System.arraycopy(old, 0, m_nodes, 0, old.length); // Build a linked list for the free list. for (int i = m_nodeCapacity - 1; i >= m_nodeCount; i--) { m_nodes[i] = new DynamicTreeNode(i); m_nodes[i].parent = (i == m_nodeCapacity - 1) ? null : m_nodes[i + 1]; m_nodes[i].height = -1; } m_freeList = m_nodeCount; } int nodeId = m_freeList; final DynamicTreeNode treeNode = m_nodes[nodeId]; m_freeList = treeNode.parent != null ? treeNode.parent.id : NULL_NODE; treeNode.parent = null; treeNode.child1 = null; treeNode.child2 = null; treeNode.height = 0; treeNode.userData = null; ++m_nodeCount; return treeNode; }
if (node.isLeaf()) { node.parent = null; nodes[count] = i;
private final DynamicTreeNode allocateNode() { if (m_freeList == NULL_NODE) { assert (m_nodeCount == m_nodeCapacity); DynamicTreeNode[] old = m_nodes; m_nodeCapacity *= 2; m_nodes = new DynamicTreeNode[m_nodeCapacity]; System.arraycopy(old, 0, m_nodes, 0, old.length); // Build a linked list for the free list. for (int i = m_nodeCapacity - 1; i >= m_nodeCount; i--) { m_nodes[i] = new DynamicTreeNode(i); m_nodes[i].parent = (i == m_nodeCapacity - 1) ? null : m_nodes[i + 1]; m_nodes[i].height = -1; } m_freeList = m_nodeCount; } int nodeId = m_freeList; final DynamicTreeNode treeNode = m_nodes[nodeId]; m_freeList = treeNode.parent != null ? treeNode.parent.id : NULL_NODE; treeNode.parent = null; treeNode.child1 = null; treeNode.child2 = null; treeNode.height = 0; treeNode.userData = null; ++m_nodeCount; return treeNode; }
public DynamicTree() { m_root = null; m_nodeCount = 0; m_nodeCapacity = 16; m_nodes = new DynamicTreeNode[16]; // Build a linked list for the free list. for (int i = m_nodeCapacity - 1; i >= 0; i--) { m_nodes[i] = new DynamicTreeNode(i); m_nodes[i].parent = (i == m_nodeCapacity - 1) ? null : m_nodes[i + 1]; m_nodes[i].height = -1; } m_freeList = 0; for (int i = 0; i < drawVecs.length; i++) { drawVecs[i] = new Vec2(); } }
if (node.isLeaf()) { subInput.p1.x = p1x; subInput.p1.y = p1y;
public DynamicTree() { m_root = null; m_nodeCount = 0; m_nodeCapacity = 16; m_nodes = new DynamicTreeNode[16]; // Build a linked list for the free list. for (int i = m_nodeCapacity - 1; i >= 0; i--) { m_nodes[i] = new DynamicTreeNode(i); m_nodes[i].parent = (i == m_nodeCapacity - 1) ? null : m_nodes[i + 1]; m_nodes[i].height = -1; } m_freeList = 0; for (int i = 0; i < drawVecs.length; i++) { drawVecs[i] = new Vec2(); } }
if (A.isLeaf() || A.height < 2) { return iA;
public DynamicTree() { m_root = null; m_nodeCount = 0; m_nodeCapacity = 16; m_nodes = new DynamicTreeNode[16]; // Build a linked list for the free list. for (int i = m_nodeCapacity - 1; i >= 0; i--) { m_nodes[i] = new DynamicTreeNode(i); m_nodes[i].parent = (i == m_nodeCapacity - 1) ? null : m_nodes[i + 1]; m_nodes[i].height = -1; } m_freeList = 0; m_insertionCount = 0; for (int i = 0; i < drawVecs.length; i++) { drawVecs[i] = new Vec2(); } }