mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 23:05:36 +08:00
Fixes 2,4,6 refs #287
https://dev.vatsim-germany.org/issues/287#note-14
This commit is contained in:
@@ -292,12 +292,13 @@ namespace BlackCore
|
||||
} // for each
|
||||
|
||||
// this part needs to be synchronized
|
||||
this->m_lock.lockForWrite();
|
||||
this->m_updateTimestamp = updateTimestampFromFile;
|
||||
this->m_aircrafts = aircrafts;
|
||||
this->m_atcStations = atcStations;
|
||||
this->m_voiceServers = voiceServers;
|
||||
this->m_lock.unlock();
|
||||
{
|
||||
QWriteLocker wl(&this->m_lock);
|
||||
this->m_updateTimestamp = updateTimestampFromFile;
|
||||
this->m_aircrafts = aircrafts;
|
||||
this->m_atcStations = atcStations;
|
||||
this->m_voiceServers = voiceServers;
|
||||
}
|
||||
} // read success
|
||||
|
||||
nwReply->close();
|
||||
|
||||
@@ -135,8 +135,9 @@ namespace BlackMisc
|
||||
/*
|
||||
* Distance to planne
|
||||
*/
|
||||
const CLength &CAirport::calculcateDistanceAndBearingToPlane(const CCoordinateGeodetic &position)
|
||||
CLength CAirport::calculcateDistanceAndBearingToPlane(const CCoordinateGeodetic &position, bool updateValues)
|
||||
{
|
||||
if (!updateValues) return Geo::greatCircleDistance(this->m_position, position);
|
||||
this->m_distanceToPlane = Geo::greatCircleDistance(this->m_position, position);
|
||||
this->m_bearingToPlane = Geo::initialBearing(this->m_position, position);
|
||||
return this->m_distanceToPlane;
|
||||
|
||||
@@ -97,12 +97,8 @@ namespace BlackMisc
|
||||
//! Valid ICAO code
|
||||
bool hasValidIcaoCode() const { return !this->getIcao().isEmpty(); }
|
||||
|
||||
/*!
|
||||
* Calculcate distance and bearing to plane, set it, and return distance
|
||||
* \param position other position
|
||||
* \return
|
||||
*/
|
||||
const BlackMisc::PhysicalQuantities::CLength &calculcateDistanceAndBearingToPlane(const BlackMisc::Geo::CCoordinateGeodetic &position);
|
||||
//! Calculcate distance and bearing to plane, set it, and return distance
|
||||
BlackMisc::PhysicalQuantities::CLength calculcateDistanceAndBearingToPlane(const BlackMisc::Geo::CCoordinateGeodetic &position, bool updateValues = true);
|
||||
|
||||
//! \copydoc ICoordinateGeodetic::latitude
|
||||
virtual const BlackMisc::Geo::CLatitude &latitude() const override
|
||||
|
||||
@@ -62,7 +62,7 @@ namespace BlackMisc
|
||||
}
|
||||
|
||||
/*
|
||||
* airports within range
|
||||
* Airports within range
|
||||
*/
|
||||
CAirportList CAirportList::findWithinRange(const BlackMisc::Geo::ICoordinateGeodetic &coordinate, const PhysicalQuantities::CLength &range) const
|
||||
{
|
||||
@@ -73,7 +73,7 @@ namespace BlackMisc
|
||||
}
|
||||
|
||||
/*
|
||||
* Distances to own plane
|
||||
* Distances, bearing to own plane
|
||||
*/
|
||||
void CAirportList::calculcateDistanceAndBearingToPlane(const Geo::CCoordinateGeodetic &position)
|
||||
{
|
||||
@@ -83,19 +83,15 @@ namespace BlackMisc
|
||||
});
|
||||
}
|
||||
|
||||
void CAirportList::removeIfOutsideRange(const Geo::CCoordinateGeodetic &position, const CLength &maxDistance, bool updateDistance)
|
||||
/*
|
||||
* Remove outside range
|
||||
*/
|
||||
void CAirportList::removeIfOutsideRange(const Geo::CCoordinateGeodetic &position, const CLength &maxDistance, bool updateValues)
|
||||
{
|
||||
CLength d;
|
||||
for (CAirportList::iterator i = begin(); i != end();)
|
||||
{
|
||||
if (updateDistance)
|
||||
{
|
||||
d = i->calculcateDistanceAndBearingToPlane(position);
|
||||
}
|
||||
else
|
||||
{
|
||||
d = i->greatCircleDistance(position);
|
||||
}
|
||||
d = i->calculcateDistanceAndBearingToPlane(position, updateValues);
|
||||
if (maxDistance < d)
|
||||
{
|
||||
i = this->erase(i);
|
||||
|
||||
@@ -256,8 +256,9 @@ namespace BlackMisc
|
||||
/*
|
||||
* Distance to planne
|
||||
*/
|
||||
const CLength &CAtcStation::calculcateDistanceToPlane(const CCoordinateGeodetic &position)
|
||||
CLength CAtcStation::calculcateDistanceToPlane(const CCoordinateGeodetic &position, bool update)
|
||||
{
|
||||
if (!update) return Geo::greatCircleDistance(this->m_position, position);
|
||||
this->m_distanceToPlane = Geo::greatCircleDistance(this->m_position, position);
|
||||
return this->m_distanceToPlane;
|
||||
}
|
||||
|
||||
@@ -172,12 +172,8 @@ namespace BlackMisc
|
||||
//! Valid distance?
|
||||
bool hasValidDistance() const { return !this->m_distanceToPlane.isNull();}
|
||||
|
||||
/*!
|
||||
* Calculcate distance to plane, set it, and also return it
|
||||
* \param position other position
|
||||
* \return
|
||||
*/
|
||||
const BlackMisc::PhysicalQuantities::CLength &calculcateDistanceToPlane(const BlackMisc::Geo::CCoordinateGeodetic &position);
|
||||
//! Calculcate distance to plane, set it, and also return it
|
||||
BlackMisc::PhysicalQuantities::CLength calculcateDistanceToPlane(const BlackMisc::Geo::CCoordinateGeodetic &position, bool update = true);
|
||||
|
||||
//! Is station online (or just booked)?
|
||||
bool isOnline() const { return m_isOnline; }
|
||||
|
||||
@@ -189,7 +189,7 @@ namespace BlackMisc
|
||||
/*
|
||||
* Great circle distance
|
||||
*/
|
||||
CLength ICoordinateGeodetic::greatCircleDistance(const ICoordinateGeodetic &otherCoordinate)
|
||||
CLength ICoordinateGeodetic::greatCircleDistance(const ICoordinateGeodetic &otherCoordinate) const
|
||||
{
|
||||
return Geo::greatCircleDistance((*this), otherCoordinate);
|
||||
}
|
||||
@@ -197,7 +197,7 @@ namespace BlackMisc
|
||||
/*
|
||||
* Initial bearing
|
||||
*/
|
||||
CAngle ICoordinateGeodetic::initialBearing(const ICoordinateGeodetic &otherCoordinate)
|
||||
CAngle ICoordinateGeodetic::initialBearing(const ICoordinateGeodetic &otherCoordinate) const
|
||||
{
|
||||
return Geo::initialBearing((*this), otherCoordinate);
|
||||
}
|
||||
|
||||
@@ -55,10 +55,10 @@ namespace BlackMisc
|
||||
}
|
||||
|
||||
//! Great circle distance
|
||||
BlackMisc::PhysicalQuantities::CLength greatCircleDistance(const ICoordinateGeodetic &otherCoordinate);
|
||||
BlackMisc::PhysicalQuantities::CLength greatCircleDistance(const ICoordinateGeodetic &otherCoordinate) const;
|
||||
|
||||
//! Initial bearing
|
||||
BlackMisc::PhysicalQuantities::CAngle initialBearing(const ICoordinateGeodetic &otherCoordinate);
|
||||
BlackMisc::PhysicalQuantities::CAngle initialBearing(const ICoordinateGeodetic &otherCoordinate) const;
|
||||
|
||||
//! In range
|
||||
static bool indexInRange(int index);
|
||||
|
||||
@@ -92,22 +92,8 @@ namespace BlackMisc
|
||||
*/
|
||||
double CMath::normalizeDegrees(double degrees)
|
||||
{
|
||||
if (degrees == 0.0 || degrees == 360.0 || degrees == -360.0) return 0.0;
|
||||
if (degrees > 0)
|
||||
{
|
||||
while (degrees >= 360.0)
|
||||
{
|
||||
degrees -= 360.0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while (degrees < 0.0)
|
||||
{
|
||||
degrees += 360.0;
|
||||
}
|
||||
}
|
||||
return degrees;
|
||||
double result = std::fmod(degrees, 360.0);
|
||||
return (result >= 0.0) ? result : result + 360.0;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -13,148 +13,83 @@ namespace BlackMisc
|
||||
namespace Math
|
||||
{
|
||||
|
||||
/*!
|
||||
* \brief Math utils
|
||||
*/
|
||||
//! Math utils
|
||||
class CMath
|
||||
{
|
||||
public:
|
||||
|
||||
/*!
|
||||
* \brief Calculates the hypotenuse of x and y without overflow
|
||||
* \param x
|
||||
* \param y
|
||||
* \return
|
||||
*/
|
||||
//! Calculates the hypotenuse of x and y without overflow
|
||||
static double hypot(double x, double y);
|
||||
|
||||
/*!
|
||||
* \brief Calculates the square of x
|
||||
* \param x
|
||||
* \return
|
||||
*/
|
||||
//! Calculates the square of x
|
||||
static inline double square(double x)
|
||||
{
|
||||
return x * x;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Calculates x to the power of three
|
||||
* \param x
|
||||
* \return
|
||||
*/
|
||||
//! Calculates x to the power of three
|
||||
static inline double cubic(const double x)
|
||||
{
|
||||
return x * x * x;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Calculates the real cubic root
|
||||
* \param x
|
||||
* \return
|
||||
*/
|
||||
//! Calculates the real cubic root
|
||||
static double cubicRootReal(double x);
|
||||
|
||||
/*!
|
||||
* \brief Utility round method
|
||||
* \param value
|
||||
* \param digits
|
||||
* \return
|
||||
*/
|
||||
//! Utility round method
|
||||
static double round(double value, int digits);
|
||||
|
||||
/*!
|
||||
* \brief Round by given epsilon, e.g.
|
||||
* \param value
|
||||
* \param epsilon
|
||||
* \return
|
||||
*/
|
||||
//! Round by given epsilon
|
||||
static double roundEpsilon(double value, double epsilon);
|
||||
|
||||
/*!
|
||||
* \brief Epsilon safe equal
|
||||
* \param v1
|
||||
* \param v2
|
||||
* \param epsilon
|
||||
* \return
|
||||
*/
|
||||
//! Epsilon safe equal
|
||||
static bool epsilonEqual(double v1, double v2, double epsilon = 1E-06);
|
||||
|
||||
/*!
|
||||
* \brief Nearest integer not greater in magnitude than value, correcting for epsilon
|
||||
* \param value
|
||||
* \param epsilon
|
||||
*/
|
||||
//! Nearest integer not greater in magnitude than value, correcting for epsilon
|
||||
static inline double trunc(double value, double epsilon = 1e-10)
|
||||
{
|
||||
return value < 0 ? ceil(value - epsilon) : floor(value + epsilon);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Fractional part of value
|
||||
* \param value
|
||||
*/
|
||||
//! Fractional part of value
|
||||
static inline double fract(double value)
|
||||
{
|
||||
double unused;
|
||||
return modf(value, &unused);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief PI
|
||||
* \return
|
||||
*/
|
||||
//! PI / 2
|
||||
static const double &PIHALF()
|
||||
{
|
||||
static double pi = 2.0 * qAtan(1.0);
|
||||
return pi;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief PI
|
||||
* \return
|
||||
*/
|
||||
//! PI
|
||||
static const double &PI()
|
||||
{
|
||||
static double pi = 4.0 * qAtan(1.0);
|
||||
return pi;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief PI * 2
|
||||
* \return
|
||||
*/
|
||||
//! PI * 2
|
||||
static const double &PI2()
|
||||
{
|
||||
static double pi2 = 8.0 * qAtan(1.0);
|
||||
return pi2;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Degree to radians
|
||||
* \param degree
|
||||
* \return
|
||||
*/
|
||||
//! Degrees to radians
|
||||
static double deg2rad(double degree);
|
||||
|
||||
/*!
|
||||
* \brief Radians to degrees
|
||||
* \param radians
|
||||
* \return
|
||||
*/
|
||||
//! Radians to degrees
|
||||
static double rad2deg(double radians);
|
||||
|
||||
/*!
|
||||
* \brief Normalize to 0..360 degrees
|
||||
* \param degrees
|
||||
* \return
|
||||
*/
|
||||
//! Normalize: 0≤ degrees <360
|
||||
static double normalizeDegrees(double degrees);
|
||||
|
||||
private:
|
||||
/*!
|
||||
* \brief No objects, just static
|
||||
*/
|
||||
//! No objects, just static
|
||||
CMath();
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user