190 while (
m_nodes[index].IsLeaf() ==
false)
202 float32 cost = 2.0f * combinedArea;
205 float32 inheritanceCost = 2.0f * (combinedArea - area);
213 cost1 = aabb.GetPerimeter() + inheritanceCost;
220 float32 newArea = aabb.GetPerimeter();
221 cost1 = (newArea - oldArea) + inheritanceCost;
230 cost2 = aabb.GetPerimeter() + inheritanceCost;
237 float32 newArea = aabb.GetPerimeter();
238 cost2 = newArea - oldArea + inheritanceCost;
242 if (cost < cost1 && cost < cost2)
258 int32 sibling = index;
271 if (
m_nodes[oldParent].child1 == sibling)
327 if (
m_nodes[parent].child1 == leaf)
339 if (
m_nodes[grandParent].child1 == parent)
554 return totalArea / rootArea;
570 return 1 +
b2Max(height1, height2);
640 height = 1 +
b2Max(height1, height2);
674 int32 maxBalance = 0;
688 maxBalance =
b2Max(maxBalance, balance);
723 int32 iMin = -1, jMin = -1;
724 for (
int32 i = 0; i < count; ++i)
728 for (
int32 j = i + 1; j < count; ++j)
743 int32 index1 = nodes[iMin];
744 int32 index2 = nodes[jMin];
756 child1->
parent = parentIndex;
757 child2->
parent = parentIndex;
759 nodes[jMin] = nodes[count-1];
760 nodes[iMin] = parentIndex;
void BASE_IMPEXP memcpy(void *dest, size_t destSize, const void *src, size_t copyCount) MRPT_NO_THROWS
#define b2_aabbMultiplier
~b2DynamicTree()
Destroy the tree, freeing the node pool.
void ValidateMetrics(int32 index) const
void Combine(const b2AABB &aabb)
Combine an AABB into this one.
bool MoveProxy(int32 proxyId, const b2AABB &aabb1, const b2Vec2 &displacement)
b2Vec2 lowerBound
the lower vertex
b2AABB aabb
Enlarged AABB.
bool Contains(const b2AABB &aabb) const
Does this aabb contain the provided AABB.
void RemoveLeaf(int32 node)
int32 Balance(int32 index)
void Validate() const
Validate this tree. For testing.
void ValidateStructure(int32 index) const
void DestroyProxy(int32 proxyId)
Destroy a proxy. This asserts if the id is invalid.
void FreeNode(int32 node)
void InsertLeaf(int32 node)
void RebuildBottomUp()
Build an optimal tree. Very expensive. For testing.
uint32 m_path
This is used to incrementally traverse the tree for re-balancing.
int32 ComputeHeight() const
void ShiftOrigin(const b2Vec2 &newOrigin)
int32 CreateProxy(const b2AABB &aabb, void *userData)
Create a proxy. Provide a tight fitting AABB and a userData pointer.
GLint GLint GLint GLint GLint GLint GLsizei GLsizei height
float32 GetAreaRatio() const
Get the ratio of the sum of the node areas to the root area.
T root(const T v0, const T v1)
b2DynamicTree()
Constructing the tree initializes the node pool.
A node in the dynamic tree. The client does not interact with this directly.
An axis aligned bounding box.
GLdouble GLdouble GLdouble r
float32 GetPerimeter() const
Get the perimeter length.
GLuint GLuint GLsizei count
void * b2Alloc(int32 size)
Implement this function to use your own memory allocator.
GLdouble GLdouble GLdouble b
int32 GetMaxBalance() const
void b2Free(void *mem)
If you implement b2Alloc, you should also implement this function.
b2Vec2 upperBound
the upper vertex