Beispiel #1
0
// Create a proxy in the tree as a leaf node. We return the index
// of the node instead of a pointer so that we can grow
// the node pool.
int32 b2DynamicTree::CreateProxy(const b2AABB& aabb, void* userData)
{
	int32 proxyId = AllocateNode();

	printf("  inc aabb: %.2f %.2f to %.2f %.2f\n",
	       aabb.lowerBound.x, aabb.lowerBound.y,
	       aabb.upperBound.x, aabb.upperBound.y);

	// Fatten the aabb.
	b2Vec2 r(b2_aabbExtension, b2_aabbExtension);
	m_nodes[proxyId].aabb.lowerBound = aabb.lowerBound - r;
	m_nodes[proxyId].aabb.upperBound = aabb.upperBound + r;
	m_nodes[proxyId].userData = userData;

	InsertLeaf(proxyId);

	// Rebalance if necessary.
	int32 iterationCount = m_nodeCount >> 4;
	int32 tryCount = 0;
	int32 height = ComputeHeight();
	while (height > 64 && tryCount < 10)
	{
		Rebalance(iterationCount);
		height = ComputeHeight();
		++tryCount;
	}

	return proxyId;
}
Beispiel #2
0
int RBTree<T>::ComputeHeight(Node<T>* node) const
{
	if (root == NULL)
		return 0;
	else if (root!= NULL && root->left == NULL && root->right == NULL)
		return 1;
	else
		return (ComputeHeight(root->left) > ComputeHeight(root->right) ? ComputeHeight(root->left) : ComputeHeight(root->right))+1;
}
Beispiel #3
0
// Compute the height of a sub-tree.
int32 b2DynamicTree::ComputeHeight(int32 nodeId) const
{
	if (nodeId == b2_nullNode)
	{
		return 0;
	}

	b2Assert(0 <= nodeId && nodeId < m_nodeCapacity);
	b2DynamicTreeNode* node = m_nodes + nodeId;
	int32 height1 = ComputeHeight(node->child1);
	int32 height2 = ComputeHeight(node->child2);
	return 1 + b2Max(height1, height2);
}
/*****************************************************************
* MoveCenter(): Centers the rectangle on 'x' and 'y'
*
* Ins: x - the x coordinate to place the rectangle
*	   y - the y coordinate to place the rectangle
*
* Outs:
*
* Returns:
*
* Mod. Date:		      05/15/2015
* Mod. Initials:
*****************************************************************/
void CRectangle::MoveCenter(float x, float y)
{
	float width = ComputeWidth( );
	float height = ComputeHeight( );

	m_fLeft = x - width / 2.f;
	m_fRight = x + width / 2.f;
	m_fTop = y - height / 2.f;
	m_fBottom = y + height / 2.f;
}
void b2DynamicTree::Validate() const
{
	ValidateStructure(m_root);
	ValidateMetrics(m_root);

	int32 freeCount = 0;
	int32 freeIndex = m_freeList;
	while (freeIndex != b2_nullNode)
	{
		b2Assert(0 <= freeIndex && freeIndex < m_nodeCapacity);
		freeIndex = m_nodes[freeIndex].next;
		++freeCount;
	}

	b2Assert(GetHeight() == ComputeHeight());

	b2Assert(m_nodeCount + freeCount == m_nodeCapacity);
}
int32 b2DynamicTree::ComputeHeight() const
{
	int32 height = ComputeHeight(m_root);
	return height;
}
Beispiel #7
0
int RBTree<T>::Height() const {
	return ComputeHeight(root);
}
 int VectorGraphic::getHeight() const
 {
     // See my comment above about cheating a bit here...
     return std::for_each(myPath.begin(), myPath.end(), ComputeHeight());
 }
Beispiel #9
0
int32 b2DynamicTree::ComputeHeight() const
{
	return ComputeHeight(m_root);
}