Get rid of boost::math::constants::* in favor of std::numbers

This commit is contained in:
Siarhei Fedartsou 2024-05-30 10:27:46 +02:00
parent 0ea757ed02
commit 2adbf35ffe
6 changed files with 21 additions and 32 deletions

View File

@ -6,7 +6,7 @@
#include <utility>
#include <vector>
#include <boost/math/constants/constants.hpp>
#include <numbers>
namespace osrm::engine::map_matching
{
@ -21,10 +21,8 @@ struct NormalDistribution
// FIXME implement log-probability version since it's faster
double Density(const double val) const
{
using namespace boost::math::constants;
const double x = val - mean;
return 1.0 / (std::sqrt(two_pi<double>()) * standard_deviation) *
return 1.0 / (std::sqrt(2 * std::numbers::pi) * standard_deviation) *
std::exp(-x * x / (standard_deviation * standard_deviation));
}

View File

@ -4,7 +4,7 @@
#include "util/integer_range.hpp"
#include <boost/assert.hpp>
#include <boost/math/constants/constants.hpp>
#include <numbers>
#include <cmath>
@ -14,7 +14,7 @@
namespace osrm::engine::map_matching
{
static const double log_2_pi = std::log(2. * boost::math::constants::pi<double>());
static const double log_2_pi = std::log(2. * std::numbers::pi);
static const double IMPOSSIBLE_LOG_PROB = -std::numeric_limits<double>::infinity();
static const double MINIMAL_LOG_PROB = std::numeric_limits<double>::lowest();
static const std::size_t INVALID_STATE = std::numeric_limits<std::size_t>::max();

View File

@ -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 * (1. / std::numbers::pi)); }
} // namespace detail
const constexpr static double METERS_PER_DEGREE_LAT = 110567.0;

View File

@ -6,7 +6,7 @@
#include <limits>
#include <boost/math/constants/constants.hpp>
#include <numbers>
namespace osrm::util
{
@ -359,22 +359,22 @@ constexpr unsigned short atan_table[4096] = {
#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;
const constexpr double SCALING_FACTOR = 4. / std::numbers::pi * 0xFFFF;
#endif
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 +405,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;

View File

@ -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;

View File

@ -146,7 +146,6 @@ double bearing(const Coordinate coordinate_1, const Coordinate coordinate_2)
double computeAngle(const Coordinate first, const Coordinate second, const Coordinate third)
{
using namespace boost::math::constants;
using namespace coordinate_calculation;
if (first == second || second == third)
@ -163,7 +162,7 @@ double computeAngle(const Coordinate first, const Coordinate second, const Coord
const double v2y =
web_mercator::latToY(toFloating(third.lat)) - web_mercator::latToY(toFloating(second.lat));
double angle = (atan2_lookup(v2y, v2x) - atan2_lookup(v1y, v1x)) * 180. / pi<double>();
double angle = (atan2_lookup(v2y, v2x) - atan2_lookup(v1y, v1x)) * 180. / std::numbers::pi;
while (angle < 0.)
{