From d19ab42d0af3c221faf570f92a9db5431d006b70 Mon Sep 17 00:00:00 2001 From: Bart Louwers Date: Tue, 13 Aug 2024 01:26:49 +0200 Subject: [PATCH] Replace `M_PI` with `std::numbers:pi` (#2713) --- include/mbgl/math/angles.hpp | 10 ++++---- include/mbgl/util/projection.hpp | 4 +++- platform/glfw/glfw_view.cpp | 5 +++- src/mbgl/gfx/polyline_generator.cpp | 7 ++++-- src/mbgl/layout/symbol_layout.cpp | 10 ++++---- src/mbgl/layout/symbol_projection.cpp | 8 +++++-- src/mbgl/map/transform.cpp | 14 ++++++----- src/mbgl/map/transform_state.cpp | 14 +++++++---- .../render_location_indicator_layer.cpp | 8 +++++-- src/mbgl/style/expression/within.cpp | 6 ++++- src/mbgl/text/check_max_angle.cpp | 5 +++- src/mbgl/text/quads.cpp | 5 +++- src/mbgl/tile/geometry_tile_data.cpp | 8 +++++-- src/mbgl/util/camera.cpp | 8 +++++-- src/mbgl/util/geo.cpp | 5 +++- src/mbgl/util/math.hpp | 3 ++- src/mbgl/util/tile_cover.cpp | 5 +++- test/api/custom_drawable_layer.test.cpp | 5 +++- test/map/transform.test.cpp | 13 +++++++---- test/text/get_anchors.test.cpp | 23 +++++++++++-------- test/util/bounding_volumes.test.cpp | 13 ++++++----- test/util/camera.test.cpp | 11 +++++---- 22 files changed, 126 insertions(+), 64 deletions(-) diff --git a/include/mbgl/math/angles.hpp b/include/mbgl/math/angles.hpp index 8419ee087..71bb30765 100644 --- a/include/mbgl/math/angles.hpp +++ b/include/mbgl/math/angles.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include namespace mbgl { namespace util { @@ -12,7 +12,7 @@ namespace util { * @return Radians as double. */ constexpr double deg2rad(double deg) noexcept { - return deg * M_PI / 180.0; + return deg * std::numbers::pi / 180.0; } /** @@ -22,7 +22,7 @@ constexpr double deg2rad(double deg) noexcept { * @return Radians as float. */ constexpr float deg2radf(float deg) noexcept { - return deg * static_cast(M_PI) / 180.0F; + return deg * std::numbers::pi_v / 180.0F; } /** @@ -32,7 +32,7 @@ constexpr float deg2radf(float deg) noexcept { * @return Degrees as double. */ constexpr double rad2deg(double rad) noexcept { - return rad * 180.0 / M_PI; + return rad * 180.0 / std::numbers::pi; } /** @@ -42,7 +42,7 @@ constexpr double rad2deg(double rad) noexcept { * @return Degrees as float. */ constexpr float rad2degf(float rad) noexcept { - return rad * 180.0F / static_cast(M_PI); + return rad * 180.0F / std::numbers::pi_v; } } // namespace util diff --git a/include/mbgl/util/projection.hpp b/include/mbgl/util/projection.hpp index 86f1ebcbb..d1c1b13ab 100644 --- a/include/mbgl/util/projection.hpp +++ b/include/mbgl/util/projection.hpp @@ -6,6 +6,8 @@ #include #include +#include + namespace mbgl { class ProjectedMeters { @@ -65,7 +67,7 @@ public: static LatLng latLngForProjectedMeters(const ProjectedMeters& projectedMeters) { double latitude = util::rad2deg(2 * std::atan(std::exp(projectedMeters.northing() / util::EARTH_RADIUS_M)) - - (M_PI / 2.0)); + (std::numbers::pi / 2.0)); double longitude = util::rad2deg(projectedMeters.easting()) / util::EARTH_RADIUS_M; latitude = util::clamp(latitude, -util::LATITUDE_MAX, util::LATITUDE_MAX); diff --git a/platform/glfw/glfw_view.cpp b/platform/glfw/glfw_view.cpp index a3e7226d5..ff9c6a426 100644 --- a/platform/glfw/glfw_view.cpp +++ b/platform/glfw/glfw_view.cpp @@ -59,6 +59,9 @@ #include #include #include +#include + +using namespace std::numbers; #if defined(MLN_RENDER_BACKEND_OPENGL) && !defined(MBGL_LAYER_LOCATION_INDICATOR_DISABLE_ALL) #include @@ -765,7 +768,7 @@ void GLFWView::updateAnimatedAnnotations() { const double period = 10; const double x = dt / period * 360 - 180; - const double y = std::sin(dt / period * M_PI * 2.0) * 80; + const double y = std::sin(dt / period * pi * 2.0) * 80; map->updateAnnotation(animatedAnnotationIDs[i], mbgl::SymbolAnnotation{{x, y}, "default_marker"}); } } diff --git a/src/mbgl/gfx/polyline_generator.cpp b/src/mbgl/gfx/polyline_generator.cpp index 7a7ac7b84..78909890e 100644 --- a/src/mbgl/gfx/polyline_generator.cpp +++ b/src/mbgl/gfx/polyline_generator.cpp @@ -11,6 +11,9 @@ #endif #include +#include + +using namespace std::numbers; namespace mbgl { namespace gfx { @@ -27,7 +30,7 @@ namespace { * * The newly created vertices are placed SHARP_CORNER_OFFSET pixels from the corner. */ -const float COS_HALF_SHARP_CORNER = std::cos(75.0f / 2.0f * (static_cast(M_PI) / 180.0f)); +const float COS_HALF_SHARP_CORNER = std::cos(75.0f / 2.0f * (pi_v / 180.0f)); constexpr float SHARP_CORNER_OFFSET = 15.0f; // Angle per triangle for approximating round line joins. @@ -360,7 +363,7 @@ void PolylineGenerator::generate(const GeometryCoordinates& coordinates // Pick the number of triangles for approximating round join by // based on the angle between normals. - const auto n = static_cast(::round((approxAngle * 180 / M_PI) / DEG_PER_TRIANGLE)); + const auto n = static_cast(::round((approxAngle * 180 / pi) / DEG_PER_TRIANGLE)); for (unsigned m = 1; m < n; ++m) { double t = static_cast(m) / n; diff --git a/src/mbgl/layout/symbol_layout.cpp b/src/mbgl/layout/symbol_layout.cpp index 7051712f0..bee82a066 100644 --- a/src/mbgl/layout/symbol_layout.cpp +++ b/src/mbgl/layout/symbol_layout.cpp @@ -18,6 +18,10 @@ #include +#include + +using namespace std::numbers; + namespace mbgl { using namespace style; @@ -838,7 +842,7 @@ void SymbolLayout::createBucket(const ImagePositions&, index = iconBuffer.placedSymbols.size() - 1; PlacedSymbol& iconSymbol = iconBuffer.placedSymbols.back(); iconSymbol.angle = (allowVerticalPlacement && writingMode == WritingModeType::Vertical) - ? static_cast(M_PI_2) + ? pi_v / 2 : 0.0f; iconSymbol.vertexStartIndex = addSymbols( iconBuffer, sizeData, iconQuads, symbolInstance.anchor, iconSymbol, feature.sortKey); @@ -968,9 +972,7 @@ std::size_t SymbolLayout::addSymbolGlyphQuads(SymbolBucket& bucket, placedIconIndex); placedIndex = bucket.text.placedSymbols.size() - 1; PlacedSymbol& placedSymbol = bucket.text.placedSymbols.back(); - placedSymbol.angle = (allowVerticalPlacement && writingMode == WritingModeType::Vertical) - ? static_cast(M_PI_2) - : 0.0f; + placedSymbol.angle = (allowVerticalPlacement && writingMode == WritingModeType::Vertical) ? pi_v / 2 : 0.0f; bool firstSymbol = true; for (const auto& symbolQuad : glyphQuads) { diff --git a/src/mbgl/layout/symbol_projection.cpp b/src/mbgl/layout/symbol_projection.cpp index 57ab09242..57052a0b0 100644 --- a/src/mbgl/layout/symbol_projection.cpp +++ b/src/mbgl/layout/symbol_projection.cpp @@ -5,6 +5,10 @@ #include #include +#include + +using namespace std::numbers; + namespace mbgl { /* @@ -198,10 +202,10 @@ std::optional placeGlyphAlongLine(const float offsetX, // The label needs to be flipped to keep text upright. // Iterate in the reverse direction. dir *= -1; - angle = static_cast(M_PI); + angle = pi_v; } - if (dir < 0) angle += static_cast(M_PI); + if (dir < 0) angle += pi_v; int32_t currentIndex = dir > 0 ? anchorSegment : anchorSegment + 1; diff --git a/src/mbgl/map/transform.cpp b/src/mbgl/map/transform.cpp index f099c8201..5f7fcfcf8 100644 --- a/src/mbgl/map/transform.cpp +++ b/src/mbgl/map/transform.cpp @@ -12,9 +12,11 @@ #include #include -#include #include #include +#include + +using namespace std::numbers; namespace mbgl { @@ -25,8 +27,8 @@ static double _normalizeAngle(double angle, double anchorAngle) { return 0; } - angle = util::wrap(angle, -M_PI, M_PI); - if (angle == -M_PI) angle = M_PI; + angle = util::wrap(angle, -pi, pi); + if (angle == -pi) angle = pi; double diff = std::abs(angle - anchorAngle); if (std::abs(angle - util::M2PI - anchorAngle) < diff) { angle -= util::M2PI; @@ -148,7 +150,7 @@ void Transform::easeTo(const CameraOptions& camera, const AnimationOptions& anim double frameZoom = util::interpolate(startZoom, zoom, t); state.setLatLngZoom(frameLatLng, frameZoom); if (bearing != startBearing) { - state.setBearing(util::wrap(util::interpolate(startBearing, bearing, t), -M_PI, M_PI)); + state.setBearing(util::wrap(util::interpolate(startBearing, bearing, t), -pi, pi)); } if (padding != startEdgeInsets) { // Interpolate edge insets @@ -319,7 +321,7 @@ void Transform::flyTo(const CameraOptions& camera, const AnimationOptions& anima LatLng frameLatLng = Projection::unproject(framePoint, startScale); state.setLatLngZoom(frameLatLng, frameZoom); if (bearing != startBearing) { - state.setBearing(util::wrap(util::interpolate(startBearing, bearing, k), -M_PI, M_PI)); + state.setBearing(util::wrap(util::interpolate(startBearing, bearing, k), -pi, pi)); } if (padding != startEdgeInsets) { @@ -646,7 +648,7 @@ double Transform::getMaxPitchForEdgeInsets(const EdgeInsets& insets) const { // clipping plane. const double tangentOfFovAboveCenterAngle = 1.03 * (height / 2.0 + centerOffsetY) / (1.5 * height); const double fovAboveCenter = std::atan(tangentOfFovAboveCenterAngle); - return M_PI * 0.5 - fovAboveCenter; + return pi * 0.5 - fovAboveCenter; // e.g. Maximum pitch of 60 degrees is when perspective center's offset from // the top is 84% of screen height. } diff --git a/src/mbgl/map/transform_state.cpp b/src/mbgl/map/transform_state.cpp index 4d33c89dd..d00ef81fe 100644 --- a/src/mbgl/map/transform_state.cpp +++ b/src/mbgl/map/transform_state.cpp @@ -9,11 +9,15 @@ #include #include +#include + +using namespace std::numbers; + namespace mbgl { namespace { LatLng latLngFromMercator(Point mercatorCoordinate, LatLng::WrapMode wrapMode = LatLng::WrapMode::Unwrapped) { - return {util::rad2deg(2 * std::atan(std::exp(M_PI - mercatorCoordinate.y * util::M2PI)) - M_PI_2), + return {util::rad2deg(2 * std::atan(std::exp(pi - mercatorCoordinate.y * 2 * pi)) - (pi / 2)), mercatorCoordinate.x * 360.0 - 180.0, wrapMode}; } @@ -384,11 +388,11 @@ void TransformState::setNorthOrientation(const NorthOrientation val) { double TransformState::getNorthOrientationAngle() const { double angleOrientation = 0; if (orientation == NorthOrientation::Rightwards) { - angleOrientation += M_PI / 2.0f; + angleOrientation += pi / 2; } else if (orientation == NorthOrientation::Downwards) { - angleOrientation += M_PI; + angleOrientation += pi; } else if (orientation == NorthOrientation::Leftwards) { - angleOrientation -= M_PI / 2.0f; + angleOrientation -= pi / 2; } return angleOrientation; } @@ -442,7 +446,7 @@ void TransformState::setEdgeInsets(const EdgeInsets& val) { // MARK: - Position LatLng TransformState::getLatLng(LatLng::WrapMode wrapMode) const { - return {util::rad2deg(2 * std::atan(std::exp(y / Cc)) - 0.5 * M_PI), -x / Bc, wrapMode}; + return {util::rad2deg(2 * std::atan(std::exp(y / Cc)) - 0.5 * pi), -x / Bc, wrapMode}; } double TransformState::pixel_x() const { diff --git a/src/mbgl/renderer/layers/render_location_indicator_layer.cpp b/src/mbgl/renderer/layers/render_location_indicator_layer.cpp index d01a8918d..b1c7e11cd 100644 --- a/src/mbgl/renderer/layers/render_location_indicator_layer.cpp +++ b/src/mbgl/renderer/layers/render_location_indicator_layer.cpp @@ -35,7 +35,11 @@ #include #include +#include + using namespace mbgl::platform; +using namespace std::numbers; + namespace mbgl { struct LocationIndicatorRenderParameters { @@ -108,8 +112,8 @@ protected: const vec2 norm = normalized(); // From theta to bearing - return util::rad2degf(util::wrap( - static_cast(M_PI_2) - std::atan2(-norm.y, norm.x), 0.0f, static_cast(M_PI * 2.0))); + return util::rad2degf( + util::wrap((pi_v / 2) - std::atan2(-norm.y, norm.x), 0.0f, pi_v * 2)); } Point toPoint() const { return {x, y}; } diff --git a/src/mbgl/style/expression/within.cpp b/src/mbgl/style/expression/within.cpp index f7576c839..29f766075 100644 --- a/src/mbgl/style/expression/within.cpp +++ b/src/mbgl/style/expression/within.cpp @@ -13,6 +13,10 @@ #include #include +#include + +using namespace std::numbers; + namespace mbgl { namespace { @@ -21,7 +25,7 @@ Point latLonToTileCoodinates(const Point& point, const mbgl::Ca const auto x = (point.x + util::LONGITUDE_MAX) * size / util::DEGREES_MAX; const auto y = (util::LONGITUDE_MAX - - util::rad2deg(std::log(std::tan(point.y * M_PI / util::DEGREES_MAX + M_PI / 4.0)))) * + util::rad2deg(std::log(std::tan(point.y * pi / util::DEGREES_MAX + pi / 4)))) * size / util::DEGREES_MAX; Point p; diff --git a/src/mbgl/text/check_max_angle.cpp b/src/mbgl/text/check_max_angle.cpp index 36241394f..8cbc7d1da 100644 --- a/src/mbgl/text/check_max_angle.cpp +++ b/src/mbgl/text/check_max_angle.cpp @@ -2,8 +2,11 @@ #include #include +#include #include +using namespace std::numbers; + namespace mbgl { struct Corner { @@ -55,7 +58,7 @@ bool checkMaxAngle(const GeometryCoordinates& line, double angleDelta = util::angle_to(prev, current) - util::angle_to(current, next); // restrict angle to -pi..pi range - angleDelta = std::fabs(std::fmod(angleDelta + 3 * M_PI, M_PI * 2) - M_PI); + angleDelta = std::fabs(std::fmod(angleDelta + 3 * pi, pi * 2) - pi); recentCorners.emplace(anchorDistance, static_cast(angleDelta)); recentAngleDelta += static_cast(angleDelta); diff --git a/src/mbgl/text/quads.cpp b/src/mbgl/text/quads.cpp index 8c2c6379f..84b5521b0 100644 --- a/src/mbgl/text/quads.cpp +++ b/src/mbgl/text/quads.cpp @@ -10,6 +10,9 @@ #include #include +#include + +using namespace std::numbers; namespace mbgl { @@ -281,7 +284,7 @@ SymbolQuads getGlyphQuads(const Shaping& shapedText, // and translated. const Point center{-halfAdvance, halfAdvance - Shaping::yOffset}; - const float verticalRotation = static_cast(-M_PI_2); + const float verticalRotation = -pi_v / 2; // xHalfWidhtOffsetcorrection is a difference between full-width // and half-width advance, should be 0 for full-width glyphs and diff --git a/src/mbgl/tile/geometry_tile_data.cpp b/src/mbgl/tile/geometry_tile_data.cpp index 4e6245cce..1d8118551 100644 --- a/src/mbgl/tile/geometry_tile_data.cpp +++ b/src/mbgl/tile/geometry_tile_data.cpp @@ -14,6 +14,10 @@ #pragma warning(pop) #endif +#include + +using namespace std::numbers; + namespace mbgl { static double signedArea(const GeometryCoordinates& ring) { @@ -127,7 +131,7 @@ Feature::geometry_type convertGeometry(const GeometryTileFeature& geometryTileFe auto tileCoordinatesToLatLng = [&](const Point& p) { double y2 = 180 - (p.y + y0) * 360 / size; - return Point((p.x + x0) * 360 / size - 180, std::atan(std::exp(y2 * M_PI / 180)) * 360.0 / M_PI - 90.0); + return Point((p.x + x0) * 360 / size - 180, std::atan(std::exp(y2 * pi / 180)) * 360.0 / pi - 90.0); }; const GeometryCollection& geometries = geometryTileFeature.getGeometries(); @@ -205,7 +209,7 @@ GeometryCollection convertGeometry(const Feature::geometry_type& geometryTileFea p.x = int16_t(util::clamp( static_cast(x), std::numeric_limits::min(), std::numeric_limits::max())); - auto y = (180 - (std::log(std::tan((c.y + 90) * M_PI / 360.0)) * 180 / M_PI)) * size / 360 - y0; + auto y = (180 - (std::log(std::tan((c.y + 90) * pi / 360.0)) * 180 / pi)) * size / 360 - y0; p.y = int16_t(util::clamp( static_cast(y), std::numeric_limits::min(), std::numeric_limits::max())); diff --git a/src/mbgl/util/camera.cpp b/src/mbgl/util/camera.cpp index 1a06ecfd0..e25c5004c 100644 --- a/src/mbgl/util/camera.cpp +++ b/src/mbgl/util/camera.cpp @@ -8,6 +8,10 @@ #include #include +#include + +using namespace std::numbers; + namespace mbgl { namespace { @@ -31,11 +35,11 @@ static double mercatorXfromLng(double lng) noexcept { } static double mercatorYfromLat(double lat) noexcept { - return (180.0 - (180.0 / M_PI * std::log(std::tan(M_PI_4 + lat * M_PI / 360.0)))) / 360.0; + return (180.0 - (180.0 / pi * std::log(std::tan((pi / 4) + lat * pi / 360.0)))) / 360.0; } static double latFromMercatorY(double y) noexcept { - return util::rad2deg(2.0 * std::atan(std::exp(M_PI - y * util::M2PI)) - M_PI_2); + return util::rad2deg(2.0 * std::atan(std::exp(pi - y * util::M2PI)) - (pi / 2)); } static double lngFromMercatorX(double x) noexcept { diff --git a/src/mbgl/util/geo.cpp b/src/mbgl/util/geo.cpp index 4cfb65bc7..5d1ab5b47 100644 --- a/src/mbgl/util/geo.cpp +++ b/src/mbgl/util/geo.cpp @@ -6,13 +6,16 @@ #include #include +#include + +using namespace std::numbers; namespace mbgl { namespace { double lat_(const uint8_t z, const int64_t y) noexcept { - const double n = M_PI - 2.0 * M_PI * y / std::pow(2.0, z); + const double n = pi - 2.0 * pi * y / std::pow(2.0, z); return util::rad2deg(std::atan(0.5 * (std::exp(n) - std::exp(-n)))); } diff --git a/src/mbgl/util/math.hpp b/src/mbgl/util/math.hpp index 40f3015e7..8d5efdceb 100644 --- a/src/mbgl/util/math.hpp +++ b/src/mbgl/util/math.hpp @@ -3,6 +3,7 @@ #include #include #include +#include #include @@ -26,7 +27,7 @@ T angle_to(const Point& a, const Point& b) { // Reflect an angle around 0 degrees template std::array flip(const std::array& c) { - return {{static_cast(2 * M_PI - c[0]), static_cast(2 * M_PI - c[1])}}; + return {{static_cast(2 * std::numbers::pi - c[0]), static_cast(2 * std::numbers::pi - c[1])}}; } template diff --git a/src/mbgl/util/tile_cover.cpp b/src/mbgl/util/tile_cover.cpp index 0046a0dba..1a3055788 100644 --- a/src/mbgl/util/tile_cover.cpp +++ b/src/mbgl/util/tile_cover.cpp @@ -9,6 +9,9 @@ #include #include +#include + +using namespace std::numbers; namespace mbgl { @@ -172,7 +175,7 @@ std::vector tileCover(const TransformState& state, const double numTiles = std::pow(2.0, z); const double worldSize = Projection::worldSize(state.getScale()); - const uint8_t minZoom = state.getPitch() <= (60.0 / 180.0) * M_PI ? z : 0; + const uint8_t minZoom = state.getPitch() <= (60.0 / 180.0) * pi ? z : 0; const uint8_t maxZoom = z; const uint8_t overscaledZoom = overscaledZ.value_or(z); const bool flippedY = state.getViewportMode() == ViewportMode::FlippedY; diff --git a/test/api/custom_drawable_layer.test.cpp b/test/api/custom_drawable_layer.test.cpp index 18575d22e..c3e6bd6e5 100644 --- a/test/api/custom_drawable_layer.test.cpp +++ b/test/api/custom_drawable_layer.test.cpp @@ -20,6 +20,9 @@ #include #include +#include + +using namespace std::numbers; class LineTestDrawableLayer : public mbgl::style::CustomDrawableLayerHost { public: @@ -110,7 +113,7 @@ public: for (auto ipoint{0}; ipoint < numPoints; ++ipoint) { polyline.emplace_back( ipoint * util::EXTENT / numPoints, - static_cast(std::sin(ipoint * 2 * M_PI / numPoints) * util::EXTENT / numLines / 2.f)); + static_cast(std::sin(ipoint * 2 * pi / numPoints) * util::EXTENT / numLines / 2.f)); } for (auto index{0}; index < numLines; ++index) { diff --git a/test/map/transform.test.cpp b/test/map/transform.test.cpp index 4a0093a24..54edc8df2 100644 --- a/test/map/transform.test.cpp +++ b/test/map/transform.test.cpp @@ -7,6 +7,9 @@ #include #include +#include + +using namespace std::numbers; using namespace mbgl; TEST(Transform, InvalidZoom) { @@ -263,7 +266,7 @@ TEST(Transform, Anchor) { ASSERT_NE(latLng.longitude(), transform.getLatLng().longitude()); transform.jumpTo(CameraOptions().withCenter(latLng).withZoom(10.0).withBearing(-45.0)); - ASSERT_DOUBLE_EQ(M_PI_4, transform.getBearing()); + ASSERT_DOUBLE_EQ(pi / 4, transform.getBearing()); ASSERT_DOUBLE_EQ(latLng.latitude(), transform.getLatLng().latitude()); ASSERT_DOUBLE_EQ(latLng.longitude(), transform.getLatLng().longitude()); @@ -946,12 +949,12 @@ TEST(Transform, FreeCameraOptionsInvalidOrientation) { EXPECT_EQ(Quaternion::identity.m, transform.getFreeCameraOptions().orientation); // Gimbal lock. Both forward and up vectors are on xy-plane - options.orientation = Quaternion::fromAxisAngle(vec3{{0.0, 1.0, 0.0}}, M_PI_2).m; + options.orientation = Quaternion::fromAxisAngle(vec3{{0.0, 1.0, 0.0}}, pi / 2).m; transform.setFreeCameraOptions(options); EXPECT_EQ(Quaternion::identity.m, transform.getFreeCameraOptions().orientation); // Camera is upside down - options.orientation = Quaternion::fromAxisAngle(vec3{{1.0, 0.0, 0.0}}, M_PI_2 + M_PI_4).m; + options.orientation = Quaternion::fromAxisAngle(vec3{{1.0, 0.0, 0.0}}, pi / 2 + pi / 4).m; transform.setFreeCameraOptions(options); EXPECT_EQ(Quaternion::identity.m, transform.getFreeCameraOptions().orientation); } @@ -1058,8 +1061,8 @@ TEST(Transform, FreeCameraOptionsOrientationRoll) { FreeCameraOptions options; transform.resize({100, 100}); - const auto orientationWithoutRoll = Quaternion::fromEulerAngles(-M_PI_4, 0.0, 0.0); - const auto orientationWithRoll = orientationWithoutRoll.multiply(Quaternion::fromEulerAngles(0.0, 0.0, M_PI_4)); + const auto orientationWithoutRoll = Quaternion::fromEulerAngles(-pi / 4, 0.0, 0.0); + const auto orientationWithRoll = orientationWithoutRoll.multiply(Quaternion::fromEulerAngles(0.0, 0.0, pi / 4)); options.orientation = orientationWithRoll.m; transform.setFreeCameraOptions(options); diff --git a/test/text/get_anchors.test.cpp b/test/text/get_anchors.test.cpp index 2f4874cba..063ec58d9 100644 --- a/test/text/get_anchors.test.cpp +++ b/test/text/get_anchors.test.cpp @@ -2,7 +2,10 @@ #include +#include + using namespace mbgl; +using namespace std::numbers; namespace mbgl { constexpr inline bool operator==(const Anchor& rhs, const Anchor& lhs) { @@ -36,7 +39,7 @@ const float overscaling = 1.0f; TEST(getAnchors, NonContinuedLineShortLabels) { const Anchors anchors = getAnchors(nonContinuedLine, bigSpacing, - static_cast(M_PI), + pi_v, textLeft, textRight, iconLeft, @@ -54,7 +57,7 @@ TEST(getAnchors, NonContinuedLineShortLabels) { TEST(getAnchors, NonContinuedLineLongLabels) { const Anchors anchors = getAnchors(nonContinuedLine, smallSpacing, - static_cast(M_PI), + pi_v, textLeft, textRight, iconLeft, @@ -72,7 +75,7 @@ TEST(getAnchors, NonContinuedLineLongLabels) { TEST(getAnchors, ContinuedLineShortLabels) { const Anchors anchors = getAnchors(continuedLine, bigSpacing, - static_cast(M_PI), + pi_v, textLeft, textRight, iconLeft, @@ -90,7 +93,7 @@ TEST(getAnchors, ContinuedLineShortLabels) { TEST(getAnchors, ContinuedLineLongLabels) { const Anchors anchors = getAnchors(continuedLine, smallSpacing, - static_cast(M_PI), + pi_v, textLeft, textRight, iconLeft, @@ -108,7 +111,7 @@ TEST(getAnchors, ContinuedLineLongLabels) { TEST(getAnchors, OverscaledAnchorsInParent) { const Anchors anchors = getAnchors(nonContinuedLine, bigSpacing, - static_cast(M_PI), + pi_v, textLeft, textRight, iconLeft, @@ -118,7 +121,7 @@ TEST(getAnchors, OverscaledAnchorsInParent) { overscaling); const Anchors childAnchors = getAnchors(nonContinuedLine, bigSpacing / 2, - static_cast(M_PI), + pi_v, textLeft, textRight, iconLeft, @@ -136,7 +139,7 @@ TEST(getAnchors, UseMidpointForShortLine) { const GeometryCoordinates shortLine = {Point{1, 1}, Point{1, 3}}; const Anchors anchors = getAnchors(shortLine, smallSpacing, - static_cast(M_PI), + pi_v, textLeft, textRight, iconLeft, @@ -153,7 +156,7 @@ TEST(getAnchors, GetCenterAnchor) { const GeometryCoordinates line = { Point{1, 1}, Point{1, 3}, Point{3, 6}, Point{4, 7}}; const auto anchor = getCenterAnchor( - line, static_cast(M_PI), textLeft, textRight, iconLeft, iconRight, glyphSize, boxScale); + line, pi_v, textLeft, textRight, iconLeft, iconRight, glyphSize, boxScale); EXPECT_TRUE(anchor); EXPECT_EQ(*anchor, Anchor(2.0f, 4.0f, .982793748f, 1u)); } @@ -161,7 +164,7 @@ TEST(getAnchors, GetCenterAnchor) { TEST(getAnchors, GetCenterAnchorOutsideTileBounds) { const GeometryCoordinates line = {Point{-10, -10}, Point{5, 5}}; const auto anchor = getCenterAnchor( - line, static_cast(M_PI), textLeft, textRight, iconLeft, iconRight, glyphSize, boxScale); + line, pi_v, textLeft, textRight, iconLeft, iconRight, glyphSize, boxScale); EXPECT_TRUE(anchor); EXPECT_EQ(*anchor, Anchor(-3.0f, -3.0f, .785398185f, 0u)); } @@ -169,6 +172,6 @@ TEST(getAnchors, GetCenterAnchorOutsideTileBounds) { TEST(getAnchors, GetCenterAnchorFailMaxAngle) { const GeometryCoordinates line = {Point{1, 1}, Point{1, 3}, Point{3, 3}}; const auto anchor = getCenterAnchor( - line, static_cast(M_PI) / 4, textLeft, textRight, iconLeft, iconRight, glyphSize, boxScale); + line, pi_v / 4, textLeft, textRight, iconLeft, iconRight, glyphSize, boxScale); EXPECT_FALSE(anchor); } diff --git a/test/util/bounding_volumes.test.cpp b/test/util/bounding_volumes.test.cpp index 845709e3f..5cf1c9f72 100644 --- a/test/util/bounding_volumes.test.cpp +++ b/test/util/bounding_volumes.test.cpp @@ -1,9 +1,10 @@ #include #include -#include #include +#include +using namespace std::numbers; using namespace mbgl; TEST(BoundingVolumes, CreateAabb) { @@ -62,7 +63,7 @@ TEST(BoundingVolumes, AabbAabbIntersection) { TEST(BoundingVolumes, CreateFrustumFromProjectionMatrix) { mat4 projMatrix; mat4 invProjMatrix; - matrix::perspective(projMatrix, M_PI_2, 1.0, 0.1, 100.0); + matrix::perspective(projMatrix, pi / 2, 1.0, 0.1, 100.0); matrix::invert(invProjMatrix, projMatrix); const util::Frustum frustum = util::Frustum::fromInvProjMatrix(invProjMatrix, 1.0, 0.0, false); @@ -123,7 +124,7 @@ static util::Frustum createTestFrustum( } TEST(BoundingVolumes, AabbFullyInsideFrustum) { - const util::Frustum frustum = createTestFrustum(M_PI_2, 1.0, 0.1, 100.0, -5.0, 0.0); + const util::Frustum frustum = createTestFrustum(pi / 2, 1.0, 0.1, 100.0, -5.0, 0.0); const std::array aabbArray = { util::AABB({-1, -1, 0}, {1, 1, 0}), util::AABB({-5, -5, 0}, {5, 5, 0}), util::AABB({-5, -5, 0}, {-4, -2, 0})}; @@ -134,7 +135,7 @@ TEST(BoundingVolumes, AabbFullyInsideFrustum) { } TEST(BoundingVolumes, AabbIntersectsFrustum) { - const util::Frustum frustum = createTestFrustum(M_PI_2, 1.0, 0.1, 100.0, -5.0, 0.0); + const util::Frustum frustum = createTestFrustum(pi / 2, 1.0, 0.1, 100.0, -5.0, 0.0); const std::array aabbArray = {util::AABB({-6, -6, 0}, {6, 6, 0}), util::AABB({-6, -6, 0}, {-5, -5, 0})}; @@ -144,10 +145,10 @@ TEST(BoundingVolumes, AabbIntersectsFrustum) { } TEST(BoundingVolumes, AabbIntersectsFrustumEdgeCase) { - const util::Frustum frustum = createTestFrustum(M_PI_2, 1.0, 0.1, 100.0, -5.0, M_PI_4); + const util::Frustum frustum = createTestFrustum(pi / 2, 1.0, 0.1, 100.0, -5.0, pi / 4); const util::AABB aabb({-10, 10, 0}, {10, 12, 0}); // Intersection test should report intersection even though shapes are separate EXPECT_EQ(frustum.intersects(aabb), util::IntersectionResult::Intersects); EXPECT_EQ(frustum.intersectsPrecise(aabb), util::IntersectionResult::Separate); -} \ No newline at end of file +} diff --git a/test/util/camera.test.cpp b/test/util/camera.test.cpp index caabe0d00..de93f297a 100644 --- a/test/util/camera.test.cpp +++ b/test/util/camera.test.cpp @@ -7,7 +7,10 @@ #include +#include + using namespace mbgl; +using namespace std::numbers; static const double abs_double_error = 1e-7; @@ -19,7 +22,7 @@ MATCHER_P(Vec3NearEquals1E7, vec, "") { TEST(FreeCameraOptions, SetLocation) { FreeCameraOptions options; - options.setLocation({{0.0, 0.0}, util::EARTH_RADIUS_M * M_PI}); + options.setLocation({{0.0, 0.0}, util::EARTH_RADIUS_M * pi}); ASSERT_TRUE(options.position); ASSERT_THAT(options.position.value(), Vec3NearEquals1E7(vec3{{0.5, 0.5, 0.5}})); @@ -28,12 +31,12 @@ TEST(FreeCameraOptions, SetLocation) { ASSERT_THAT(options.position.value(), Vec3NearEquals1E7(vec3{{0.0, 0.4282409625, 0.000027532812465}})); options.setLocation( - {{util::LATITUDE_MAX, 0.0}, util::EARTH_RADIUS_M * M_PI * std::cos(util::deg2rad(util::LATITUDE_MAX))}); + {{util::LATITUDE_MAX, 0.0}, util::EARTH_RADIUS_M * pi * std::cos(util::deg2rad(util::LATITUDE_MAX))}); ASSERT_TRUE(options.position); ASSERT_THAT(options.position.value(), Vec3NearEquals1E7(vec3{{0.5, 0.0, 0.5}})); options.setLocation( - {{-util::LATITUDE_MAX, 0.0}, util::EARTH_RADIUS_M * M_PI * std::cos(util::deg2rad(-util::LATITUDE_MAX))}); + {{-util::LATITUDE_MAX, 0.0}, util::EARTH_RADIUS_M * pi * std::cos(util::deg2rad(-util::LATITUDE_MAX))}); ASSERT_TRUE(options.position); ASSERT_THAT(options.position.value(), Vec3NearEquals1E7(vec3{{0.5, 1.0, 0.5}})); } @@ -97,7 +100,7 @@ TEST(FreeCameraOptions, GetLocationNegativeAltitude) { const auto latLngAltitude = options.getLocation(); ASSERT_TRUE(latLngAltitude); - ASSERT_DOUBLE_EQ(latLngAltitude->altitude, -0.5 * util::EARTH_RADIUS_M * M_PI); + ASSERT_DOUBLE_EQ(latLngAltitude->altitude, -0.5 * util::EARTH_RADIUS_M * pi); } TEST(FreeCameraOptions, GetLocationUnwrappedPosition) {