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