mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-04 16:56:53 +08:00
refs #484 Optimize getClosestObjects by using CSequence::partiallySort.
This commit is contained in:
@@ -48,6 +48,17 @@ namespace BlackMisc
|
||||
});
|
||||
}
|
||||
|
||||
template <class OBJ, class CONTAINER>
|
||||
CONTAINER IGeoObjectList<OBJ, CONTAINER>::findClosest(int number, const ICoordinateGeodetic &coordinate) const
|
||||
{
|
||||
CONTAINER closest = this->container().partiallySorted(number, [ & ](const OBJ & a, const OBJ & b)
|
||||
{
|
||||
return calculateEuclideanDistanceSquared(a, coordinate) < calculateEuclideanDistanceSquared(b, coordinate);
|
||||
});
|
||||
closest.truncate(number);
|
||||
return closest;
|
||||
}
|
||||
|
||||
template <class OBJ, class CONTAINER>
|
||||
void IGeoObjectWithRelativePositionList<OBJ, CONTAINER>::calculcateDistanceAndBearingToPosition(const ICoordinateGeodetic &position)
|
||||
{
|
||||
@@ -82,13 +93,19 @@ namespace BlackMisc
|
||||
this->container().sort([ & ](const OBJ & a, const OBJ & b) { return a.getDistanceToOwnAircraft() < b.getDistanceToOwnAircraft(); });
|
||||
}
|
||||
|
||||
template <class OBJ, class CONTAINER>
|
||||
void IGeoObjectWithRelativePositionList<OBJ, CONTAINER>::partiallySortByDistanceToOwnAircraft(int number)
|
||||
{
|
||||
this->container().partiallySort(number, [ & ](const OBJ & a, const OBJ & b) { return a.getDistanceToOwnAircraft() < b.getDistanceToOwnAircraft(); });
|
||||
}
|
||||
|
||||
template <class OBJ, class CONTAINER>
|
||||
CONTAINER IGeoObjectWithRelativePositionList<OBJ, CONTAINER>::getClosestObjects(int number) const
|
||||
{
|
||||
if (number < 1) { return CONTAINER(); }
|
||||
if (this->container().size() >= number) { return (this->container()); }
|
||||
CONTAINER closest(this->container());
|
||||
closest.sortByDistanceToOwnAircraft();
|
||||
closest.partiallySortByDistanceToOwnAircraft(number);
|
||||
closest.truncate(number);
|
||||
return closest;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user