Merge pointtree stable sort fix from newnet branch.
parent
b553072b90
commit
73772a54fe
|
@ -67,9 +67,14 @@ void PointTree::clear()
|
|||
points.clear();
|
||||
}
|
||||
|
||||
static bool pointTreeSortFunction(std::pair<uint64_t, void *> const &a, std::pair<uint64_t, void *> const &b)
|
||||
{
|
||||
return a.first < b.first; // Sort only by position, not by pointer address, even if two units are in the same place.
|
||||
}
|
||||
|
||||
void PointTree::sort()
|
||||
{
|
||||
std::sort(points.begin(), points.end());
|
||||
std::stable_sort(points.begin(), points.end(), pointTreeSortFunction); // Stable sort to avoid unspecified behaviour when two objects are in exactly the same place.
|
||||
}
|
||||
|
||||
//#define DUMP_IMAGE // All x and y coordinates must be in range -500 to 499, if dumping an image.
|
||||
|
|
|
@ -65,7 +65,7 @@ POINT_TREE *pointTreeCreate(void);
|
|||
void pointTreeDestroy(POINT_TREE *pointTree);
|
||||
|
||||
void pointTreeInsert(POINT_TREE *pointTree, void *point, int32_t x, int32_t y);
|
||||
void pointTreeClear(void);
|
||||
void pointTreeClear(POINT_TREE *pointTree);
|
||||
|
||||
// Must sort after inserting, and before querying.
|
||||
void pointTreeSort(POINT_TREE *pointTree);
|
||||
|
|
Loading…
Reference in New Issue