Fix the initial weather request in case last position is null

calculateGreatCircleDistance returns false immediately if any of the
arguments was null.

ref T324
This commit is contained in:
Roland Winklmeier
2018-09-06 15:04:40 +02:00
committed by Klaus Basan
parent 7a7f1f2df0
commit 3804612bed
6 changed files with 34 additions and 22 deletions

View File

@@ -229,12 +229,15 @@ namespace BlackSimPlugin
if (m_isWeatherActivated)
{
const auto currentPosition = CCoordinateGeodetic { situation.latitude(), situation.longitude() };
if (CWeatherScenario::isRealWeatherScenario(m_weatherScenarioSettings.get()) &&
calculateGreatCircleDistance(m_lastWeatherPosition, currentPosition).value(CLengthUnit::mi()) > 20)
if (CWeatherScenario::isRealWeatherScenario(m_weatherScenarioSettings.get()))
{
m_lastWeatherPosition = currentPosition;
const auto weatherGrid = CWeatherGrid { { "GLOB", currentPosition } };
requestWeatherGrid(weatherGrid, { this, &CSimulatorEmulated::injectWeatherGrid });
if (m_lastWeatherPosition.isNull() ||
calculateGreatCircleDistance(m_lastWeatherPosition, currentPosition).value(CLengthUnit::mi()) > 20)
{
m_lastWeatherPosition = currentPosition;
const auto weatherGrid = CWeatherGrid { { "GLOB", currentPosition } };
requestWeatherGrid(weatherGrid, { this, &CSimulatorEmulated::injectWeatherGrid });
}
}
}