From 23455166cf54871860d342f1915a909881a204a8 Mon Sep 17 00:00:00 2001 From: Siarhei Fedartsou Date: Thu, 30 May 2024 10:38:36 +0200 Subject: [PATCH] Get rid of boost::math::constants::* in favor of std::numbers --- include/util/cheap_ruler.hpp | 3 ++- include/util/trigonometry_table.hpp | 4 ---- include/util/web_mercator.hpp | 4 ++-- src/extractor/intersection/intersection_analysis.cpp | 9 +++++---- src/extractor/intersection/mergable_road_detector.cpp | 4 ++-- src/guidance/roundabout_handler.cpp | 2 +- 6 files changed, 12 insertions(+), 14 deletions(-) diff --git a/include/util/cheap_ruler.hpp b/include/util/cheap_ruler.hpp index 67df8d6f2..d26e36c1c 100644 --- a/include/util/cheap_ruler.hpp +++ b/include/util/cheap_ruler.hpp @@ -6,6 +6,7 @@ #include #include #include +#include namespace mapbox { @@ -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) diff --git a/include/util/trigonometry_table.hpp b/include/util/trigonometry_table.hpp index cc272903b..3186df831 100644 --- a/include/util/trigonometry_table.hpp +++ b/include/util/trigonometry_table.hpp @@ -356,11 +356,7 @@ 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. * std::numbers::inv_pi * 0xFFFF; -#endif inline double atan2_lookup(double y, double x) { diff --git a/include/util/web_mercator.hpp b/include/util/web_mercator.hpp index c7fab1259..9fcfa07c3 100644 --- a/include/util/web_mercator.hpp +++ b/include/util/web_mercator.hpp @@ -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(yToLat(g)); } diff --git a/src/extractor/intersection/intersection_analysis.cpp b/src/extractor/intersection/intersection_analysis.cpp index 4ea3985ec..7ee296f11 100644 --- a/src/extractor/intersection/intersection_analysis.cpp +++ b/src/extractor/intersection/intersection_analysis.cpp @@ -6,6 +6,7 @@ #include "util/coordinate_calculation.hpp" #include +#include namespace osrm::extractor::intersection { @@ -79,11 +80,11 @@ namespace { double findAngleBisector(double alpha, double beta) { - alpha *= M_PI / 180.; - beta *= M_PI / 180.; + alpha *= std::numbers::pi / 180.; + beta *= std::numbers::pi / 180.; const auto average = - 180. * std::atan2(std::sin(alpha) + std::sin(beta), std::cos(alpha) + std::cos(beta)) / - M_PI; + 180. * std::atan2(std::sin(alpha) + std::sin(beta), std::cos(alpha) + std::cos(beta)) * + std::numbers::inv_pi; return std::fmod(average + 360., 360.); } diff --git a/src/extractor/intersection/mergable_road_detector.cpp b/src/extractor/intersection/mergable_road_detector.cpp index 449a15e9e..adfb601cb 100644 --- a/src/extractor/intersection/mergable_road_detector.cpp +++ b/src/extractor/intersection/mergable_road_detector.cpp @@ -351,7 +351,7 @@ bool MergableRoadDetector::IsCircularShape(const NodeID intersection_node, // ---- ---- // \ / // ------- - const auto constexpr CIRCULAR_POLYGON_ISOPERIMETRIC_LOWER_BOUND = 0.85 / (4 * M_PI); + const auto constexpr CIRCULAR_POLYGON_ISOPERIMETRIC_LOWER_BOUND = 0.85 / (4 * std::numbers::pi); if (connect_again && coordinates_to_the_left.front() == coordinates_to_the_left.back()) { // if the left and right roads connect again and are closed polygons ... const auto area = util::coordinate_calculation::computeArea(coordinates_to_the_left); @@ -359,7 +359,7 @@ bool MergableRoadDetector::IsCircularShape(const NodeID intersection_node, const auto area_to_squared_perimeter_ratio = std::abs(area) / (perimeter * perimeter); // then don't merge roads if A/L² is greater than the lower bound - BOOST_ASSERT(area_to_squared_perimeter_ratio <= 1. / (4 * M_PI)); + BOOST_ASSERT(area_to_squared_perimeter_ratio <= 1. / (4 * std::numbers::pi)); if (area_to_squared_perimeter_ratio >= CIRCULAR_POLYGON_ISOPERIMETRIC_LOWER_BOUND) return true; } diff --git a/src/guidance/roundabout_handler.cpp b/src/guidance/roundabout_handler.cpp index 82998a4e1..451ebf7bf 100644 --- a/src/guidance/roundabout_handler.cpp +++ b/src/guidance/roundabout_handler.cpp @@ -337,7 +337,7 @@ RoundaboutType RoundaboutHandler::getRoundaboutType(const NodeID nid) const return RoundaboutType::RoundaboutIntersection; } - const double radius = roundabout_length / (2 * M_PI); + const double radius = roundabout_length * 0.5 * std::numbers::inv_pi; // Looks like a rotary: large roundabout with dedicated name // do we have a dedicated name for the rotary, if not its a roundabout