mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-01 05:26:45 +08:00
* Default unit is more clearly stated in one place, not restated in many different places, and is not always the SI unit * Converter strategy pattern in CMeasurementUnit, covering linear, affine, and different kinds of sexagesimal units * General reorganization of CMeasurementUnit construction and CPhysicalQuantity methods, not removing any behvaiour * Move duplicated method unitFromSymbol from derived classes into base class CMeasurementUnit * For DBus, CPhysicalQuantity marshals both in its own unit and in the default unit
134 lines
2.5 KiB
C++
134 lines
2.5 KiB
C++
/* Copyright (C) 2013 VATSIM Community / contributors
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
#ifndef BLACKMISC_MATHEMATICS_H
|
|
#define BLACKMISC_MATHEMATICS_H
|
|
#include <QtCore/qmath.h>
|
|
#include <cmath>
|
|
|
|
namespace BlackMisc
|
|
{
|
|
namespace Math
|
|
{
|
|
|
|
/*!
|
|
* \brief Math utils
|
|
*/
|
|
class CMath
|
|
{
|
|
public:
|
|
|
|
/*!
|
|
* \brief Calculates the hypotenuse of x and y without overflow
|
|
* \param x
|
|
* \param y
|
|
* \return
|
|
*/
|
|
static double hypot(double x, double y);
|
|
|
|
/*!
|
|
* \brief Calculates the square of x
|
|
* \param x
|
|
* \return
|
|
*/
|
|
static inline double square(double x)
|
|
{
|
|
return x * x;
|
|
}
|
|
|
|
/*!
|
|
* \brief Calculates x to the power of three
|
|
* \param x
|
|
* \return
|
|
*/
|
|
static inline double cubic(const double x)
|
|
{
|
|
return x * x * x;
|
|
}
|
|
|
|
/*!
|
|
* \brief Calculates the real cubic root
|
|
* \param x
|
|
* \return
|
|
*/
|
|
static double cubicRootReal(double x);
|
|
|
|
/*!
|
|
* \brief Utility round method
|
|
* \param value
|
|
* \param digits
|
|
* \return
|
|
*/
|
|
static double round(double value, int digits);
|
|
|
|
/*!
|
|
* \brief Round by given epsilon, e.g.
|
|
* \param value
|
|
* \param epsilon
|
|
* \return
|
|
*/
|
|
static double roundEpsilon(double value, double 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)
|
|
{
|
|
return value < 0 ? ceil(value - epsilon) : floor(value + epsilon);
|
|
}
|
|
|
|
/*!
|
|
* \brief Fractional part of value
|
|
* \param value
|
|
*/
|
|
static inline double fract(double value)
|
|
{
|
|
double unused;
|
|
return modf(value, &unused);
|
|
}
|
|
|
|
/*!
|
|
* \brief PI
|
|
* \return
|
|
*/
|
|
static const double &PIHALF()
|
|
{
|
|
static double pi = 2.0 * qAtan(1.0);
|
|
return pi;
|
|
}
|
|
|
|
/*!
|
|
* \brief PI
|
|
* \return
|
|
*/
|
|
static const double &PI()
|
|
{
|
|
static double pi = 4.0 * qAtan(1.0);
|
|
return pi;
|
|
}
|
|
|
|
/*!
|
|
* \brief PI * 2
|
|
* \return
|
|
*/
|
|
static const double &PI2()
|
|
{
|
|
static double pi2 = 8.0 * qAtan(1.0);
|
|
return pi2;
|
|
}
|
|
|
|
private:
|
|
/*!
|
|
* \brief Deleted
|
|
*/
|
|
CMath();
|
|
};
|
|
|
|
} // namespace
|
|
} // namespace
|
|
#endif // guard
|