mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-02 23:25:53 +08:00
Ref T111, lat/lng/angle changes
* get struct CAngle::DegMinSecFractionalSec to obtain parts * round to epsilon utility functions and fix (qint64)
This commit is contained in:
committed by
Mathew Sutcliffe
parent
77546a46b1
commit
e55480737e
@@ -53,10 +53,12 @@ namespace BlackMisc
|
||||
|
||||
double CMathUtils::roundEpsilon(double value, double epsilon)
|
||||
{
|
||||
if (epsilon == 0) { return value; } // avoid division by 0
|
||||
double fractpart, intpart;
|
||||
fractpart = modf(value, &intpart);
|
||||
if (fractpart == 0) return value; // do not mess any "integers" to the worse
|
||||
qint64 ri = qRound(value / epsilon);
|
||||
if (fractpart == 0) { return value; } // do not mess any "integers" to the worse
|
||||
const double roundValue = value / epsilon;
|
||||
qint64 ri = qRound64(roundValue);
|
||||
double rv = static_cast<double>(ri) * epsilon; // do not loose any range here
|
||||
return rv;
|
||||
}
|
||||
@@ -113,5 +115,15 @@ namespace BlackMisc
|
||||
return multiplier * divisor;
|
||||
}
|
||||
|
||||
QString CMathUtils::fractionalPartAsString(double value, int width)
|
||||
{
|
||||
double intpart;
|
||||
const double fractpart = modf(value, &intpart);
|
||||
const QString f = QString::number(fractpart);
|
||||
const QString fInt = f.length() < 3 ? QString("0") : f.mid(2);
|
||||
if (width < 0) { return fInt; }
|
||||
if (fInt.length() >= width) { return fInt.left(width); }
|
||||
return fInt.leftJustified(width, '0');
|
||||
}
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -21,7 +21,6 @@ namespace BlackMisc
|
||||
{
|
||||
namespace Math
|
||||
{
|
||||
|
||||
//! Math utils
|
||||
class BLACKMISC_EXPORT CMathUtils
|
||||
{
|
||||
@@ -103,10 +102,13 @@ namespace BlackMisc
|
||||
//! Random number between low and high
|
||||
static int randomInteger(int low, int high);
|
||||
|
||||
//! Round numToRound to the nearest multiple of multiple
|
||||
//! Round numToRound to the nearest multiple of divisor
|
||||
static int roundToMultipleOf(int value, int divisor);
|
||||
};
|
||||
|
||||
//! Fractional part as integer string, e.g. 3.12 -> 12 / 3.012 -> 012
|
||||
//! \remark because of leading 0 returned as string
|
||||
static QString fractionalPartAsString(double value, int width = -1);
|
||||
};
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
|
||||
Reference in New Issue
Block a user