Replace M_PI with std::numbers:pi (#2713)

This commit is contained in:
Bart Louwers
2024-08-13 01:26:49 +02:00
committed by GitHub
parent b42fa344b3
commit d19ab42d0a
22 changed files with 126 additions and 64 deletions

View File

@@ -1,6 +1,6 @@
#pragma once
#include <cmath>
#include <numbers>
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<float>(M_PI) / 180.0F;
return deg * std::numbers::pi_v<float> / 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<float>(M_PI);
return rad * 180.0F / std::numbers::pi_v<float>;
}
} // namespace util

View File

@@ -6,6 +6,8 @@
#include <mbgl/math/angles.hpp>
#include <mbgl/math/clamp.hpp>
#include <numbers>
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);

View File

@@ -59,6 +59,9 @@
#include <iostream>
#include <utility>
#include <sstream>
#include <numbers>
using namespace std::numbers;
#if defined(MLN_RENDER_BACKEND_OPENGL) && !defined(MBGL_LAYER_LOCATION_INDICATOR_DISABLE_ALL)
#include <mbgl/style/layers/location_indicator_layer.hpp>
@@ -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"});
}
}

View File

@@ -11,6 +11,9 @@
#endif
#include <memory>
#include <numbers>
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<float>(M_PI) / 180.0f));
const float COS_HALF_SHARP_CORNER = std::cos(75.0f / 2.0f * (pi_v<float> / 180.0f));
constexpr float SHARP_CORNER_OFFSET = 15.0f;
// Angle per triangle for approximating round line joins.
@@ -360,7 +363,7 @@ void PolylineGenerator<PLV, PS>::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<unsigned>(::round((approxAngle * 180 / M_PI) / DEG_PER_TRIANGLE));
const auto n = static_cast<unsigned>(::round((approxAngle * 180 / pi) / DEG_PER_TRIANGLE));
for (unsigned m = 1; m < n; ++m) {
double t = static_cast<double>(m) / n;

View File

@@ -18,6 +18,10 @@
#include <mapbox/polylabel.hpp>
#include <numbers>
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<float>(M_PI_2)
? pi_v<float> / 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<float>(M_PI_2)
: 0.0f;
placedSymbol.angle = (allowVerticalPlacement && writingMode == WritingModeType::Vertical) ? pi_v<float> / 2 : 0.0f;
bool firstSymbol = true;
for (const auto& symbolQuad : glyphQuads) {

View File

@@ -5,6 +5,10 @@
#include <mbgl/renderer/layers/render_symbol_layer.hpp>
#include <mbgl/util/math.hpp>
#include <numbers>
using namespace std::numbers;
namespace mbgl {
/*
@@ -198,10 +202,10 @@ std::optional<PlacedGlyph> placeGlyphAlongLine(const float offsetX,
// The label needs to be flipped to keep text upright.
// Iterate in the reverse direction.
dir *= -1;
angle = static_cast<float>(M_PI);
angle = pi_v<float>;
}
if (dir < 0) angle += static_cast<float>(M_PI);
if (dir < 0) angle += pi_v<float>;
int32_t currentIndex = dir > 0 ? anchorSegment : anchorSegment + 1;

View File

@@ -12,9 +12,11 @@
#include <mbgl/util/logging.hpp>
#include <mbgl/util/platform.hpp>
#include <cmath>
#include <cstdio>
#include <utility>
#include <numbers>
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.
}

View File

@@ -9,11 +9,15 @@
#include <mbgl/util/projection.hpp>
#include <mbgl/util/tile_coordinate.hpp>
#include <numbers>
using namespace std::numbers;
namespace mbgl {
namespace {
LatLng latLngFromMercator(Point<double> 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 {

View File

@@ -35,7 +35,11 @@
#include <mbgl/gl/types.hpp>
#include <mbgl/renderer/image_manager.hpp>
#include <numbers>
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<float>(
static_cast<float>(M_PI_2) - std::atan2(-norm.y, norm.x), 0.0f, static_cast<float>(M_PI * 2.0)));
return util::rad2degf(
util::wrap<float>((pi_v<float> / 2) - std::atan2(-norm.y, norm.x), 0.0f, pi_v<float> * 2));
}
Point<double> toPoint() const { return {x, y}; }

View File

@@ -13,6 +13,10 @@
#include <mbgl/math/angles.hpp>
#include <mbgl/math/clamp.hpp>
#include <numbers>
using namespace std::numbers;
namespace mbgl {
namespace {
@@ -21,7 +25,7 @@ Point<int64_t> latLonToTileCoodinates(const Point<double>& 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<int64_t> p;

View File

@@ -2,8 +2,11 @@
#include <mbgl/geometry/anchor.hpp>
#include <mbgl/util/math.hpp>
#include <numbers>
#include <queue>
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<float>(angleDelta));
recentAngleDelta += static_cast<float>(angleDelta);

View File

@@ -10,6 +10,9 @@
#include <mbgl/util/math.hpp>
#include <cassert>
#include <numbers>
using namespace std::numbers;
namespace mbgl {
@@ -281,7 +284,7 @@ SymbolQuads getGlyphQuads(const Shaping& shapedText,
// and translated.
const Point<float> center{-halfAdvance, halfAdvance - Shaping::yOffset};
const float verticalRotation = static_cast<float>(-M_PI_2);
const float verticalRotation = -pi_v<float> / 2;
// xHalfWidhtOffsetcorrection is a difference between full-width
// and half-width advance, should be 0 for full-width glyphs and

View File

@@ -14,6 +14,10 @@
#pragma warning(pop)
#endif
#include <numbers>
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<int16_t>& p) {
double y2 = 180 - (p.y + y0) * 360 / size;
return Point<double>((p.x + x0) * 360 / size - 180, std::atan(std::exp(y2 * M_PI / 180)) * 360.0 / M_PI - 90.0);
return Point<double>((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<int64_t>(
static_cast<int16_t>(x), std::numeric_limits<int16_t>::min(), std::numeric_limits<int16_t>::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<int64_t>(
static_cast<int16_t>(y), std::numeric_limits<int16_t>::min(), std::numeric_limits<int16_t>::max()));

View File

@@ -8,6 +8,10 @@
#include <mbgl/util/geo.hpp>
#include <mbgl/util/projection.hpp>
#include <numbers>
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 {

View File

@@ -6,13 +6,16 @@
#include <mbgl/util/tile_range.hpp>
#include <cmath>
#include <numbers>
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))));
}

View File

@@ -3,6 +3,7 @@
#include <cmath>
#include <array>
#include <limits>
#include <numbers>
#include <mbgl/util/geometry.hpp>
@@ -26,7 +27,7 @@ T angle_to(const Point<S>& a, const Point<S>& b) {
// Reflect an angle around 0 degrees
template <typename T>
std::array<T, 2> flip(const std::array<T, 2>& c) {
return {{static_cast<T>(2 * M_PI - c[0]), static_cast<T>(2 * M_PI - c[1])}};
return {{static_cast<T>(2 * std::numbers::pi - c[0]), static_cast<T>(2 * std::numbers::pi - c[1])}};
}
template <typename T, typename S1, typename S2>

View File

@@ -9,6 +9,9 @@
#include <functional>
#include <list>
#include <numbers>
using namespace std::numbers;
namespace mbgl {
@@ -172,7 +175,7 @@ std::vector<OverscaledTileID> 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;

View File

@@ -20,6 +20,9 @@
#include <memory>
#include <cmath>
#include <numbers>
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<int16_t>(std::sin(ipoint * 2 * M_PI / numPoints) * util::EXTENT / numLines / 2.f));
static_cast<int16_t>(std::sin(ipoint * 2 * pi / numPoints) * util::EXTENT / numLines / 2.f));
}
for (auto index{0}; index < numLines; ++index) {

View File

@@ -7,6 +7,9 @@
#include <mbgl/util/geo.hpp>
#include <mbgl/util/quaternion.hpp>
#include <numbers>
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);

View File

@@ -2,7 +2,10 @@
#include <mbgl/text/get_anchors.hpp>
#include <numbers>
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<float>(M_PI),
pi_v<float>,
textLeft,
textRight,
iconLeft,
@@ -54,7 +57,7 @@ TEST(getAnchors, NonContinuedLineShortLabels) {
TEST(getAnchors, NonContinuedLineLongLabels) {
const Anchors anchors = getAnchors(nonContinuedLine,
smallSpacing,
static_cast<float>(M_PI),
pi_v<float>,
textLeft,
textRight,
iconLeft,
@@ -72,7 +75,7 @@ TEST(getAnchors, NonContinuedLineLongLabels) {
TEST(getAnchors, ContinuedLineShortLabels) {
const Anchors anchors = getAnchors(continuedLine,
bigSpacing,
static_cast<float>(M_PI),
pi_v<float>,
textLeft,
textRight,
iconLeft,
@@ -90,7 +93,7 @@ TEST(getAnchors, ContinuedLineShortLabels) {
TEST(getAnchors, ContinuedLineLongLabels) {
const Anchors anchors = getAnchors(continuedLine,
smallSpacing,
static_cast<float>(M_PI),
pi_v<float>,
textLeft,
textRight,
iconLeft,
@@ -108,7 +111,7 @@ TEST(getAnchors, ContinuedLineLongLabels) {
TEST(getAnchors, OverscaledAnchorsInParent) {
const Anchors anchors = getAnchors(nonContinuedLine,
bigSpacing,
static_cast<float>(M_PI),
pi_v<float>,
textLeft,
textRight,
iconLeft,
@@ -118,7 +121,7 @@ TEST(getAnchors, OverscaledAnchorsInParent) {
overscaling);
const Anchors childAnchors = getAnchors(nonContinuedLine,
bigSpacing / 2,
static_cast<float>(M_PI),
pi_v<float>,
textLeft,
textRight,
iconLeft,
@@ -136,7 +139,7 @@ TEST(getAnchors, UseMidpointForShortLine) {
const GeometryCoordinates shortLine = {Point<int16_t>{1, 1}, Point<int16_t>{1, 3}};
const Anchors anchors = getAnchors(shortLine,
smallSpacing,
static_cast<float>(M_PI),
pi_v<float>,
textLeft,
textRight,
iconLeft,
@@ -153,7 +156,7 @@ TEST(getAnchors, GetCenterAnchor) {
const GeometryCoordinates line = {
Point<int16_t>{1, 1}, Point<int16_t>{1, 3}, Point<int16_t>{3, 6}, Point<int16_t>{4, 7}};
const auto anchor = getCenterAnchor(
line, static_cast<float>(M_PI), textLeft, textRight, iconLeft, iconRight, glyphSize, boxScale);
line, pi_v<float>, 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<int16_t>{-10, -10}, Point<int16_t>{5, 5}};
const auto anchor = getCenterAnchor(
line, static_cast<float>(M_PI), textLeft, textRight, iconLeft, iconRight, glyphSize, boxScale);
line, pi_v<float>, 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<int16_t>{1, 1}, Point<int16_t>{1, 3}, Point<int16_t>{3, 3}};
const auto anchor = getCenterAnchor(
line, static_cast<float>(M_PI) / 4, textLeft, textRight, iconLeft, iconRight, glyphSize, boxScale);
line, pi_v<float> / 4, textLeft, textRight, iconLeft, iconRight, glyphSize, boxScale);
EXPECT_FALSE(anchor);
}

View File

@@ -1,9 +1,10 @@
#include <mbgl/util/bounding_volumes.hpp>
#include <gtest/gtest.h>
#include <cmath>
#include <algorithm>
#include <numbers>
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<util::AABB, 3> 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<util::AABB, 2> aabbArray = {util::AABB({-6, -6, 0}, {6, 6, 0}),
util::AABB({-6, -6, 0}, {-5, -5, 0})};
@@ -144,7 +145,7 @@ 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

View File

@@ -7,7 +7,10 @@
#include <gmock/gmock.h>
#include <numbers>
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) {