From a2de3a16e43d5107ae35ff5ab96344f75c70bb67 Mon Sep 17 00:00:00 2001 From: Roland Winklmeier Date: Sat, 26 Mar 2016 21:24:49 +0100 Subject: [PATCH] CWeatherGrid utility classes Renamed Cavok to ClearWeather since CAVOK does not mean no clouds. Find methods. refs #612 --- src/blackmisc/weather/weathergrid.cpp | 22 +++++++++++++++++++++- src/blackmisc/weather/weathergrid.h | 11 +++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/blackmisc/weather/weathergrid.cpp b/src/blackmisc/weather/weathergrid.cpp index 529376521..933cefec5 100644 --- a/src/blackmisc/weather/weathergrid.cpp +++ b/src/blackmisc/weather/weathergrid.cpp @@ -8,9 +8,11 @@ */ #include "weathergrid.h" +#include "blackmisc/geo/coordinategeodetic.h" using namespace BlackMisc::PhysicalQuantities; using namespace BlackMisc::Aviation; +using namespace BlackMisc::Geo; namespace BlackMisc { @@ -20,7 +22,25 @@ namespace BlackMisc CSequence(other) { } - const CWeatherGrid &CWeatherGrid::getCavokGrid() + CWeatherGrid CWeatherGrid::findWithinRange(const ICoordinateGeodetic &coordinate, const PhysicalQuantities::CLength &range) const + { + return findBy([&](const CGridPoint & gridPoint) + { + return calculateGreatCircleDistance(gridPoint.getPosition(), coordinate) <= range; + }); + } + + CWeatherGrid CWeatherGrid::findClosest(int number, const ICoordinateGeodetic &coordinate) const + { + CWeatherGrid closest = partiallySorted(number, [ & ](const CGridPoint & a, const CGridPoint & b) + { + return calculateEuclideanDistanceSquared(a.getPosition(), coordinate) < calculateEuclideanDistanceSquared(b.getPosition(), coordinate); + }); + closest.truncate(number); + return closest; + } + + const CWeatherGrid &CWeatherGrid::getClearWeatherGrid() { static const CVisibilityLayer visibilityLayer( CAltitude(0, CAltitude::MeanSeaLevel, CLengthUnit::m()), diff --git a/src/blackmisc/weather/weathergrid.h b/src/blackmisc/weather/weathergrid.h index 6e7b25fec..a6f54ab1f 100644 --- a/src/blackmisc/weather/weathergrid.h +++ b/src/blackmisc/weather/weathergrid.h @@ -15,6 +15,7 @@ #include "gridpoint.h" #include "blackmisc/blackmiscexport.h" #include "blackmisc/sequence.h" +#include "blackmisc/geo/geoobjectlist.h" namespace BlackMisc { @@ -39,8 +40,14 @@ namespace BlackMisc //! Construct from a base class object. CWeatherGrid(const CSequence &other); - //! CAVOK grid - static const BlackMisc::Weather::CWeatherGrid &getCavokGrid(); + //! \copydoc Geo::IGeoObjectList::findWithinRange + CWeatherGrid findWithinRange(const BlackMisc::Geo::ICoordinateGeodetic &coordinate, const BlackMisc::PhysicalQuantities::CLength &range) const; + + //! \copydoc Geo::IGeoObjectList::findClosest + CWeatherGrid findClosest(int number, const BlackMisc::Geo::ICoordinateGeodetic &coordinate) const; + + //! Clear weather grid + static const BlackMisc::Weather::CWeatherGrid &getClearWeatherGrid(); //! Thunderstorm grid static const BlackMisc::Weather::CWeatherGrid &getThunderStormGrid();