revert quickSort change in commit http://code.google.com/p/bullet/source/detail?r=2527 and fix the underlying sort issue
in VoronoiFractureDemo (store intermediate values in memory to avoid problems) @todo: rewrite the island management to avoid sort for better performance Thanks to Peter Kyme for the report, fixes Issue 607
This commit is contained in:
@@ -184,7 +184,12 @@ struct pointCmp
|
|||||||
{
|
{
|
||||||
bool operator()(const btVector3& p1, const btVector3& p2) const
|
bool operator()(const btVector3& p1, const btVector3& p2) const
|
||||||
{
|
{
|
||||||
return ((p1-curVoronoiPoint).length2() < (p2-curVoronoiPoint).length2());
|
float v1 = (p1-curVoronoiPoint).length2();
|
||||||
|
float v2 = (p2-curVoronoiPoint).length2();
|
||||||
|
bool result0 = v1 < v2;
|
||||||
|
//bool result1 = ((btScalar)(p1-curVoronoiPoint).length2()) < ((btScalar)(p2-curVoronoiPoint).length2());
|
||||||
|
//apparently result0 is not always result1, because extended precision used in registered is different from precision when values are stored in memory
|
||||||
|
return result0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -377,8 +377,10 @@ void btSimulationIslandManager::buildAndProcessIslands(btDispatcher* dispatcher,
|
|||||||
|
|
||||||
int numManifolds = int (m_islandmanifold.size());
|
int numManifolds = int (m_islandmanifold.size());
|
||||||
|
|
||||||
//we should do radix sort, it it much faster (O(n) instead of O (n log2(n))
|
//tried a radix sort, but quicksort/heapsort seems still faster
|
||||||
|
//@todo rewrite island management
|
||||||
m_islandmanifold.quickSort(btPersistentManifoldSortPredicate());
|
m_islandmanifold.quickSort(btPersistentManifoldSortPredicate());
|
||||||
|
//m_islandmanifold.heapSort(btPersistentManifoldSortPredicate());
|
||||||
|
|
||||||
//now process all active islands (sets of manifolds for now)
|
//now process all active islands (sets of manifolds for now)
|
||||||
|
|
||||||
|
|||||||
@@ -313,46 +313,34 @@ protected:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename L>
|
|
||||||
int partition (const L& CompareFunc, int lo, int hi, int pivotIndex)
|
|
||||||
{
|
|
||||||
if (pivotIndex != lo)
|
|
||||||
swap (lo, pivotIndex);
|
|
||||||
|
|
||||||
pivotIndex = lo;
|
|
||||||
lo++;
|
|
||||||
while (lo <= hi)
|
|
||||||
{
|
|
||||||
//if (m_data[low] <= m_data[pivotIndex]) -> we don't have a <= so we use !(b<a) as a<=b
|
|
||||||
if (!CompareFunc(m_data[pivotIndex],m_data[lo]))
|
|
||||||
lo++;
|
|
||||||
else if (CompareFunc(m_data[pivotIndex],m_data[hi]))
|
|
||||||
hi--;
|
|
||||||
else
|
|
||||||
swap(lo,hi);
|
|
||||||
}
|
|
||||||
if (hi != pivotIndex)
|
|
||||||
swap(pivotIndex, hi);
|
|
||||||
return hi;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename L>
|
template <typename L>
|
||||||
void quickSortInternal(const L& CompareFunc,int lo, int hi)
|
void quickSortInternal(const L& CompareFunc,int lo, int hi)
|
||||||
{
|
{
|
||||||
if (lo>=hi)
|
// lo is the lower index, hi is the upper index
|
||||||
return;
|
// of the region of array a that is to be sorted
|
||||||
int pivotIndex = (lo+hi)/2;
|
int i=lo, j=hi;
|
||||||
pivotIndex = partition(CompareFunc,lo,hi,pivotIndex);
|
T x=m_data[(lo+hi)/2];
|
||||||
|
|
||||||
// recursion, exclude the pivot
|
// partition
|
||||||
if (lo<pivotIndex)
|
do
|
||||||
{
|
{
|
||||||
quickSortInternal( CompareFunc, lo, pivotIndex-1);
|
while (CompareFunc(m_data[i],x))
|
||||||
}
|
i++;
|
||||||
if (pivotIndex<hi)
|
while (CompareFunc(x,m_data[j]))
|
||||||
|
j--;
|
||||||
|
if (i<=j)
|
||||||
{
|
{
|
||||||
quickSortInternal( CompareFunc, pivotIndex+1, hi);
|
swap(i,j);
|
||||||
|
i++; j--;
|
||||||
}
|
}
|
||||||
|
} while (i<=j);
|
||||||
|
|
||||||
|
// recursion
|
||||||
|
if (lo<j)
|
||||||
|
quickSortInternal( CompareFunc, lo, j);
|
||||||
|
if (i<hi)
|
||||||
|
quickSortInternal( CompareFunc, i, hi);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user