/* Copyright (C) 2015 * swift project Community / Contributors * * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, * including this file, may be copied, modified, propagated, or distributed except according to the terms * contained in the LICENSE file. */ #include "blackmisc/geo/geoobjectlist.h" #include "blackmisc/geo/coordinategeodetic.h" #include "blackmisc/aviation/atcstationlist.h" #include "blackmisc/aviation/airportlist.h" #include "blackmisc/aviation/atcstationlist.h" #include "blackmisc/simulation/simulatedaircraft.h" #include "blackmisc/simulation/simulatedaircraftlist.h" #include "blackmisc/simulation/xplane/navdatareference.h" using namespace BlackMisc::PhysicalQuantities; namespace BlackMisc { namespace Geo { template IGeoObjectList::IGeoObjectList() { } template const CONTAINER &IGeoObjectList::container() const { return static_cast(*this); } template CONTAINER &IGeoObjectList::container() { return static_cast(*this); } template IGeoObjectWithRelativePositionList::IGeoObjectWithRelativePositionList() { } template CONTAINER IGeoObjectList::findWithinRange(const ICoordinateGeodetic &coordinate, const PhysicalQuantities::CLength &range) const { return this->container().findBy([&](const OBJ & geoObj) { return calculateGreatCircleDistance(geoObj, coordinate) <= range; }); } template CONTAINER IGeoObjectList::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 void IGeoObjectWithRelativePositionList::calculcateAndUpdateRelativeDistanceAndBearing(const ICoordinateGeodetic &position) { for (OBJ &geoObj : this->container()) { geoObj.calculcateAndUpdateRelativeDistanceAndBearing(position); } } template void IGeoObjectWithRelativePositionList::removeIfOutsideRange(const Geo::ICoordinateGeodetic &position, const CLength &maxDistance, bool updateValues) { this->container().removeIf([ & ](OBJ & geoObj) { return updateValues ? geoObj.calculcateAndUpdateRelativeDistanceAndBearing(position) > maxDistance : geoObj.calculateGreatCircleDistance(position) > maxDistance; }); } template void IGeoObjectWithRelativePositionList::sortByRange(const BlackMisc::Geo::ICoordinateGeodetic &position, bool updateValues) { if (updateValues) { this->calculcateAndUpdateRelativeDistanceAndBearing(position); } this->container().sort([ & ](const OBJ & a, const OBJ & b) { return a.getRelativeDistance() < b.getRelativeDistance(); }); } template void IGeoObjectWithRelativePositionList::sortByDistanceToOwnAircraft() { this->container().sort([ & ](const OBJ & a, const OBJ & b) { return a.getRelativeDistance() < b.getRelativeDistance(); }); } template void IGeoObjectWithRelativePositionList::partiallySortByDistanceToOwnAircraft(int number) { this->container().partiallySort(number, [ & ](const OBJ & a, const OBJ & b) { return a.getRelativeDistance() < b.getRelativeDistance(); }); } template CONTAINER IGeoObjectWithRelativePositionList::getClosestObjects(int number) const { if (number < 1) { return CONTAINER(); } if (this->container().size() >= number) { return (this->container()); } CONTAINER closest(this->container()); closest.partiallySortByDistanceToOwnAircraft(number); closest.truncate(number); return closest; } // see here for the reason of thess forward instantiations // https://isocpp.org/wiki/faq/templates#separate-template-fn-defn-from-decl //! \cond PRIVATE template class BLACKMISC_EXPORT_DEFINE_TEMPLATE IGeoObjectList; template class BLACKMISC_EXPORT_DEFINE_TEMPLATE IGeoObjectList; template class BLACKMISC_EXPORT_DEFINE_TEMPLATE IGeoObjectList; template class BLACKMISC_EXPORT_DEFINE_TEMPLATE IGeoObjectList; template class BLACKMISC_EXPORT_DEFINE_TEMPLATE IGeoObjectWithRelativePositionList; template class BLACKMISC_EXPORT_DEFINE_TEMPLATE IGeoObjectWithRelativePositionList; template class BLACKMISC_EXPORT_DEFINE_TEMPLATE IGeoObjectWithRelativePositionList; //! \endcond } // namespace } // namespace