About "b2DynamicTree::InsertLeaf"

Here is the code:
"
int32 child1 = m_nodes[index].child1;
int32 child2 = m_nodes[index].child2;

float32 area = m_nodes[index].aabb.GetPerimeter();

b2AABB combinedAABB;
combinedAABB.Combine(m_nodes[index].aabb, leafAABB);
float32 combinedArea = combinedAABB.GetPerimeter();

// Cost of creating a new parent for this node and the new leaf
float32 cost = 2.0f * combinedArea;

// Minimum cost of pushing the leaf further down the tree
float32 inheritanceCost = 2.0f * (combinedArea - area);

// Cost of descending into child1
float32 cost1;
if (m_nodes[child1].IsLeaf())
{
b2AABB aabb;
aabb.Combine(leafAABB, m_nodes[child1].aabb);
cost1 = aabb.GetPerimeter() + inheritanceCost;
}
else
{
b2AABB aabb;
aabb.Combine(leafAABB, m_nodes[child1].aabb);
float32 oldArea = m_nodes[child1].aabb.GetPerimeter();
float32 newArea = aabb.GetPerimeter();
cost1 = (newArea - oldArea) + inheritanceCost;
}

// Cost of descending into child2
float32 cost2;
if (m_nodes[child2].IsLeaf())
{
b2AABB aabb;
aabb.Combine(leafAABB, m_nodes[child2].aabb);
cost2 = aabb.GetPerimeter() + inheritanceCost;
}
else
{
b2AABB aabb;
aabb.Combine(leafAABB, m_nodes[child2].aabb);
float32 oldArea = m_nodes[child2].aabb.GetPerimeter();
float32 newArea = aabb.GetPerimeter();
cost2 = newArea - oldArea + inheritanceCost;
}

// Descend according to the minimum cost.
if (cost < cost1 && cost < cost2)
{
break;
}

// Descend
if (cost1 < cost2)
{
index = child1;
}
else
{
index = child2;
}
"
I don't know why using the Perimeter of AABB insert the leaf. But "inheritanceCost" could be unused. Like this:

"
int32 child1 = m_nodes[index].child1;
int32 child2 = m_nodes[index].child2;

float32 area = m_nodes[index].aabb.GetPerimeter();

//b2AABB combinedAABB;
//combinedAABB.Combine(m_nodes[index].aabb, leafAABB);
//float32 combinedArea = combinedAABB.GetPerimeter();


// Cost of creating a new parent for this node and the new leaf
float32 cost = 2.0f * area;//2.0f * combinedArea;

// Minimum cost of pushing the leaf further down the tree
//float32 inheritanceCost = 2.0f * (combinedArea - area);


// Cost of descending into child1
float32 cost1;
if (m_nodes[child1].IsLeaf())
{
b2AABB aabb;
aabb.Combine(leafAABB, m_nodes[child1].aabb);
cost1 = aabb.GetPerimeter();// + inheritanceCost;
}
else
{
b2AABB aabb;
aabb.Combine(leafAABB, m_nodes[child1].aabb);
float32 oldArea = m_nodes[child1].aabb.GetPerimeter();
float32 newArea = aabb.GetPerimeter();
cost1 = (newArea - oldArea);// + inheritanceCost;
}

// Cost of descending into child2
float32 cost2;
if (m_nodes[child2].IsLeaf())
{
b2AABB aabb;
aabb.Combine(leafAABB, m_nodes[child2].aabb);
cost2 = aabb.GetPerimeter();// + inheritanceCost;
}
else
{
b2AABB aabb;
aabb.Combine(leafAABB, m_nodes[child2].aabb);
float32 oldArea = m_nodes[child2].aabb.GetPerimeter();
float32 newArea = aabb.GetPerimeter();
cost2 = newArea - oldArea;// + inheritanceCost;
}
"

I don't know the theory of AABB tree, Plz tell me ~ thx ~

Original thread: https://box2d.org/forum/viewtopic.php?t=9876