mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 23:05:36 +08:00
Refactoring math functions
Remove unused math header Move math constants to own file Remove unused math methods
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2013
|
||||
/* Copyright (C) 2022
|
||||
* swift project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
@@ -8,14 +8,20 @@
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef BLACKMISC_MATH_MATH_H
|
||||
#define BLACKMISC_MATH_MATH_H
|
||||
#ifndef BLACKMISC_MATH_CONSTANTS_H
|
||||
#define BLACKMISC_MATH_CONSTANTS_H
|
||||
|
||||
/*!
|
||||
* \namespace BlackMisc::Math
|
||||
* \brief Math classes such as vectors, matrices, and utility methods.
|
||||
*/
|
||||
namespace BlackMisc::Math
|
||||
{
|
||||
//! PI
|
||||
constexpr double c_pi = 3.1415926535897932;
|
||||
|
||||
#include "blackmisc/math/mathutils.h"
|
||||
//! PI / 2
|
||||
constexpr double c_pihalf = c_pi / 2;
|
||||
|
||||
//! PI * 2
|
||||
constexpr double c_pi2 = c_pi * 2;
|
||||
|
||||
} // ns
|
||||
|
||||
#endif // guard
|
||||
@@ -6,6 +6,7 @@
|
||||
* or distributed except according to the terms contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "blackmisc/math/constants.h"
|
||||
#include "blackmisc/math/mathutils.h"
|
||||
#include "blackmisc/verify.h"
|
||||
|
||||
@@ -17,12 +18,6 @@
|
||||
|
||||
namespace BlackMisc::Math
|
||||
{
|
||||
double CMathUtils::cubicRootReal(double x)
|
||||
{
|
||||
const double result = std::pow(qAbs(x), 1.0 / 3.0);
|
||||
return x < 0 ? -result : result;
|
||||
}
|
||||
|
||||
double CMathUtils::round(double value, int digits)
|
||||
{
|
||||
// gosh, is there no Qt method for this??? It's year 2013
|
||||
@@ -35,11 +30,6 @@ namespace BlackMisc::Math
|
||||
return rv;
|
||||
}
|
||||
|
||||
QString CMathUtils::roundAsString(double value, int digits)
|
||||
{
|
||||
return QString::number(round(value, digits));
|
||||
}
|
||||
|
||||
double CMathUtils::roundEpsilon(double value, double epsilon)
|
||||
{
|
||||
if (epsilonZeroLimits(epsilon)) { return value; } // avoid division by 0
|
||||
@@ -64,12 +54,12 @@ namespace BlackMisc::Math
|
||||
|
||||
double CMathUtils::deg2rad(double degree)
|
||||
{
|
||||
return degree * CMathUtils::PI() / 180.0;
|
||||
return degree * c_pi / 180.0;
|
||||
}
|
||||
|
||||
double CMathUtils::rad2deg(double radians)
|
||||
{
|
||||
return radians * 180.0 / CMathUtils::PI();
|
||||
return radians * 180.0 / c_pi;
|
||||
}
|
||||
|
||||
double CMathUtils::normalizeDegrees180(double degrees)
|
||||
|
||||
@@ -28,27 +28,9 @@ namespace BlackMisc::Math
|
||||
//! No objects, just static
|
||||
CMathUtils() = delete;
|
||||
|
||||
//! Calculates the square of x
|
||||
static inline double square(double x)
|
||||
{
|
||||
return x * x;
|
||||
}
|
||||
|
||||
//! Calculates x to the power of three
|
||||
static inline double cubic(const double x)
|
||||
{
|
||||
return x * x * x;
|
||||
}
|
||||
|
||||
//! Calculates the real cubic root
|
||||
static double cubicRootReal(double x);
|
||||
|
||||
//! Utility round method
|
||||
static double round(double value, int digits);
|
||||
|
||||
//! Utility round method, returning as string
|
||||
static QString roundAsString(double value, int digits);
|
||||
|
||||
//! Round by given epsilon
|
||||
static double roundEpsilon(double value, double epsilon);
|
||||
|
||||
@@ -79,27 +61,6 @@ namespace BlackMisc::Math
|
||||
return modf(value, &unused);
|
||||
}
|
||||
|
||||
//! PI / 2
|
||||
static const double &PIHALF()
|
||||
{
|
||||
static double pi = 2.0 * qAtan(1.0);
|
||||
return pi;
|
||||
}
|
||||
|
||||
//! PI
|
||||
static const double &PI()
|
||||
{
|
||||
static double pi = 4.0 * qAtan(1.0);
|
||||
return pi;
|
||||
}
|
||||
|
||||
//! PI * 2
|
||||
static const double &PI2()
|
||||
{
|
||||
static double pi2 = 8.0 * qAtan(1.0);
|
||||
return pi2;
|
||||
}
|
||||
|
||||
//! Degrees to radians
|
||||
static double deg2rad(double degree);
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "blackmisc/pq/angle.h"
|
||||
#include "blackmisc/iconlist.h"
|
||||
#include "blackmisc/icons.h"
|
||||
#include "blackmisc/math/constants.h"
|
||||
#include "blackmisc/math/mathutils.h"
|
||||
|
||||
#include <cmath>
|
||||
@@ -79,12 +80,12 @@ namespace BlackMisc::PhysicalQuantities
|
||||
|
||||
double CAngle::piFactor() const
|
||||
{
|
||||
return Math::CMathUtils::round(this->value(CAngleUnit::rad()) / CMathUtils::PI(), 6);
|
||||
return Math::CMathUtils::round(this->value(CAngleUnit::rad()) / c_pi, 6);
|
||||
}
|
||||
|
||||
const double &CAngle::PI()
|
||||
{
|
||||
return CMathUtils::PI();
|
||||
return c_pi;
|
||||
}
|
||||
|
||||
double CAngle::sin() const
|
||||
|
||||
Reference in New Issue
Block a user