Get rid of boost::math::constants::* and M_PI in favor of std::numbers (#6916)

This commit is contained in:
Siarhei Fedartsou
2024-05-30 19:40:56 +02:00
committed by GitHub
parent a9b1bd88d3
commit fb9d1cefcc
13 changed files with 35 additions and 48 deletions
@@ -6,6 +6,7 @@
#include "util/coordinate_calculation.hpp"
#include <boost/optional/optional_io.hpp>
#include <numbers>
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.);
}
@@ -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;
}
+1 -1
View File
@@ -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
+1 -2
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::inv_pi;
while (angle < 0.)
{