mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-30 11:55:35 +08:00
refactor: Use chrono instead of plain ints
This commit is contained in:
@@ -831,25 +831,14 @@ namespace swift::misc::aviation
|
||||
return false;
|
||||
}
|
||||
|
||||
CLength CAircraftSituation::getDistancePerTime(const CTime &time, const CLength &min) const
|
||||
CLength CAircraftSituation::getDistancePerTime(std::chrono::milliseconds ms, const CLength &min) const
|
||||
{
|
||||
if (this->getGroundSpeed().isNull())
|
||||
{
|
||||
if (!min.isNull()) { return min; }
|
||||
return CLength(0, CLengthUnit::nullUnit());
|
||||
}
|
||||
const int ms = time.valueInteger(CTimeUnit::ms());
|
||||
return this->getDistancePerTime(ms, min);
|
||||
}
|
||||
|
||||
CLength CAircraftSituation::getDistancePerTime(int milliseconds, const CLength &min) const
|
||||
{
|
||||
if (this->getGroundSpeed().isNull())
|
||||
{
|
||||
if (!min.isNull()) { return min; }
|
||||
return CLength(0, CLengthUnit::nullUnit());
|
||||
}
|
||||
const double seconds = milliseconds / 1000.0;
|
||||
const double seconds = ms.count() / 1000.0;
|
||||
const double gsMeterSecond = this->getGroundSpeed().value(CSpeedUnit::m_s());
|
||||
const CLength d(seconds * gsMeterSecond, CLengthUnit::m());
|
||||
if (!min.isNull() && d < min) { return min; }
|
||||
@@ -858,7 +847,8 @@ namespace swift::misc::aviation
|
||||
|
||||
CLength CAircraftSituation::getDistancePerTime250ms(const CLength &min) const
|
||||
{
|
||||
return this->getDistancePerTime(250, min);
|
||||
using namespace std::chrono_literals;
|
||||
return this->getDistancePerTime(250ms, min);
|
||||
}
|
||||
|
||||
void CAircraftSituation::setCallsign(const CCallsign &callsign)
|
||||
|
||||
@@ -385,14 +385,9 @@ namespace swift::misc
|
||||
//! Situation looks like an aircraft not near ground
|
||||
bool canLikelySkipNearGroundInterpolation() const;
|
||||
|
||||
//! Distance per time
|
||||
physical_quantities::CLength
|
||||
getDistancePerTime(const physical_quantities::CTime &time,
|
||||
const physical_quantities::CLength &min = physical_quantities::CLength::null()) const;
|
||||
|
||||
//! Distance per milliseconds
|
||||
physical_quantities::CLength
|
||||
getDistancePerTime(int milliseconds,
|
||||
getDistancePerTime(std::chrono::milliseconds,
|
||||
const physical_quantities::CLength &min = physical_quantities::CLength::null()) const;
|
||||
|
||||
//! Distance per milliseconds (250ms)
|
||||
|
||||
Reference in New Issue
Block a user