Get rid of boost::math::constants::* and M_PI in favor of std::numbers (#6916)
This commit is contained in:
committed by
GitHub
parent
a9b1bd88d3
commit
fb9d1cefcc
@@ -4,6 +4,7 @@
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <limits>
|
||||
#include <numbers>
|
||||
#include <tuple>
|
||||
#include <utility>
|
||||
|
||||
@@ -37,7 +38,7 @@ class CheapRuler
|
||||
static constexpr double FE = 1.0 / 298.257223563; // flattening
|
||||
|
||||
static constexpr double E2 = FE * (2 - FE);
|
||||
static constexpr double RAD = M_PI / 180.0;
|
||||
static constexpr double RAD = std::numbers::pi / 180.0;
|
||||
|
||||
public:
|
||||
explicit CheapRuler(double latitude)
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include "util/coordinate.hpp"
|
||||
|
||||
#include <boost/math/constants/constants.hpp>
|
||||
#include <numbers>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
@@ -23,17 +23,9 @@ const constexpr double RAD_TO_DEGREE = 1. / DEGREE_TO_RAD;
|
||||
// The IUGG value for the equatorial radius is 6378.137 km (3963.19 miles)
|
||||
const constexpr long double EARTH_RADIUS = 6372797.560856;
|
||||
|
||||
inline double degToRad(const double degree)
|
||||
{
|
||||
using namespace boost::math::constants;
|
||||
return degree * (pi<double>() / 180.0);
|
||||
}
|
||||
inline double degToRad(const double degree) { return degree * (std::numbers::pi / 180.0); }
|
||||
|
||||
inline double radToDeg(const double radian)
|
||||
{
|
||||
using namespace boost::math::constants;
|
||||
return radian * (180.0 * (1. / pi<double>()));
|
||||
}
|
||||
inline double radToDeg(const double radian) { return radian * (180.0 * std::numbers::inv_pi); }
|
||||
} // namespace detail
|
||||
|
||||
const constexpr static double METERS_PER_DEGREE_LAT = 110567.0;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#include <limits>
|
||||
|
||||
#include <boost/math/constants/constants.hpp>
|
||||
#include <numbers>
|
||||
|
||||
namespace osrm::util
|
||||
{
|
||||
@@ -356,25 +356,21 @@ constexpr unsigned short atan_table[4096] = {
|
||||
0xffe0, 0xffea, 0xfff4, 0xffff};
|
||||
|
||||
// max value is pi/4
|
||||
#ifdef _MSC_VER // TODO: remove as soon as boost allows C++14 features with Visual Studio
|
||||
const constexpr double SCALING_FACTOR = 4. / M_PI * 0xFFFF;
|
||||
#else
|
||||
const constexpr double SCALING_FACTOR = 4. / boost::math::constants::pi<double>() * 0xFFFF;
|
||||
#endif
|
||||
const constexpr double SCALING_FACTOR = 4. * std::numbers::inv_pi * 0xFFFF;
|
||||
|
||||
inline double atan2_lookup(double y, double x)
|
||||
{
|
||||
using namespace boost::math::constants;
|
||||
static constexpr auto half_pi = std::numbers::pi * 0.5;
|
||||
|
||||
if (std::abs(x) < std::numeric_limits<double>::epsilon())
|
||||
{
|
||||
if (y >= 0.)
|
||||
{
|
||||
return half_pi<double>();
|
||||
return half_pi;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -half_pi<double>();
|
||||
return -half_pi;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -405,25 +401,25 @@ inline double atan2_lookup(double y, double x)
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
angle = pi<double>() - angle;
|
||||
angle = std::numbers::pi - angle;
|
||||
break;
|
||||
case 2:
|
||||
angle = -angle;
|
||||
break;
|
||||
case 3:
|
||||
angle = -pi<double>() + angle;
|
||||
angle = -std::numbers::pi + angle;
|
||||
break;
|
||||
case 4:
|
||||
angle = half_pi<double>() - angle;
|
||||
angle = half_pi - angle;
|
||||
break;
|
||||
case 5:
|
||||
angle = half_pi<double>() + angle;
|
||||
angle = half_pi + angle;
|
||||
break;
|
||||
case 6:
|
||||
angle = -half_pi<double>() + angle;
|
||||
angle = -half_pi + angle;
|
||||
break;
|
||||
case 7:
|
||||
angle = -half_pi<double>() - angle;
|
||||
angle = -half_pi - angle;
|
||||
break;
|
||||
}
|
||||
return angle;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include "util/coordinate.hpp"
|
||||
|
||||
#include <boost/math/constants/constants.hpp>
|
||||
#include <numbers>
|
||||
|
||||
namespace osrm::util::web_mercator
|
||||
{
|
||||
@@ -14,7 +14,7 @@ const constexpr double RAD_TO_DEGREE = 1. / DEGREE_TO_RAD;
|
||||
// radius used by WGS84
|
||||
const constexpr double EARTH_RADIUS_WGS84 = 6378137.0;
|
||||
// earth circumference devided by 2
|
||||
const constexpr double MAXEXTENT = EARTH_RADIUS_WGS84 * boost::math::constants::pi<double>();
|
||||
const constexpr double MAXEXTENT = EARTH_RADIUS_WGS84 * std::numbers::pi;
|
||||
// ^ math functions are not constexpr since they have side-effects (setting errno) :(
|
||||
const constexpr double EPSG3857_MAX_LATITUDE = 85.051128779806592378; // 90(4*atan(exp(pi))/pi-1)
|
||||
const constexpr double MAX_LONGITUDE = 180.0;
|
||||
@@ -103,8 +103,8 @@ inline void pixelToDegree(const double shift, double &x, double &y)
|
||||
const double b = shift / 2.0;
|
||||
x = (x - b) / shift * 360.0;
|
||||
// FIXME needs to be simplified
|
||||
const double g = (y - b) / -(shift / (2 * M_PI)) / detail::DEGREE_TO_RAD;
|
||||
static_assert(detail::DEGREE_TO_RAD / (2 * M_PI) - 1 / 360. < 0.0001, "");
|
||||
const double g = (y - b) / -(shift * 0.5 * std::numbers::inv_pi) / detail::DEGREE_TO_RAD;
|
||||
static_assert(detail::DEGREE_TO_RAD * 0.5 * std::numbers::inv_pi - 1 / 360. < 0.0001, "");
|
||||
y = static_cast<double>(yToLat(g));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user