Fix render tests failing on Xcode 14.3 (#1046)

This commit is contained in:
Alex Cristici
2023-04-24 18:45:09 +03:00
committed by GitHub
parent 99167b9116
commit 19b84464a3
24 changed files with 162 additions and 96 deletions

View File

@@ -165,6 +165,7 @@ list(APPEND INCLUDE_FILES
${PROJECT_SOURCE_DIR}/include/mbgl/map/map_projection.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/map/mode.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/map/projection_mode.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/math/angles.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/math/clamp.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/math/log2.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/math/minmax.hpp

View File

@@ -0,0 +1,49 @@
#pragma once
#include <cmath>
namespace mbgl {
namespace util {
/**
* @brief Converts degrees to radians
*
* @param deg Degrees as double.
* @return Radians as double.
*/
constexpr double deg2rad(double deg) noexcept {
return deg * M_PI / 180.0;
}
/**
* @brief Converts degrees to radians
*
* @param deg Degrees as float.
* @return Radians as float.
*/
constexpr float deg2radf(float deg) noexcept {
return deg * static_cast<float>(M_PI) / 180.0F;
}
/**
* @brief Converts radians to degrees
*
* @param rad Radians as double.
* @return Degrees as double.
*/
constexpr double rad2deg(double rad) noexcept {
return rad * 180.0 / M_PI;
}
/**
* @brief Converts radians to degrees
*
* @param rad Radians as float.
* @return Degrees as float.
*/
constexpr float rad2degf(float rad) noexcept {
return rad * 180.0F / static_cast<float>(M_PI);
}
} // namespace util
} // namespace mbgl

View File

@@ -1,5 +1,6 @@
#pragma once
#include <mbgl/math/angles.hpp>
#include <mbgl/util/constants.hpp>
#include <array>
@@ -52,8 +53,8 @@ private:
void calculateCartesian() {
// We abstract "north"/"up" (compass-wise) to be 0° when really this is 90° (π/2): we
// correct for that here
const float _a = (azimuthal + 90) * util::DEG2RAD_F;
const float _p = polar * util::DEG2RAD_F;
const float _a = util::deg2radf(azimuthal + 90);
const float _p = util::deg2radf(polar);
x = radial * std::cos(_a) * std::sin(_p);
y = radial * std::sin(_a) * std::sin(_p);

View File

@@ -26,10 +26,6 @@ constexpr uint16_t tileSize_I = 512;
*/
constexpr int32_t EXTENT = 8192;
constexpr double DEG2RAD_D = M_PI / 180.0;
constexpr double RAD2DEG_D = 180.0 / M_PI;
constexpr float DEG2RAD_F = static_cast<float>(M_PI) / 180.0F;
constexpr float RAD2DEG_F = 180.0F / static_cast<float>(M_PI);
constexpr double M2PI = M_PI * 2;
constexpr double EARTH_RADIUS_M = 6378137;
constexpr double LATITUDE_MAX = 85.051128779806604;

View File

@@ -3,6 +3,7 @@
#include <mbgl/util/constants.hpp>
#include <mbgl/util/geo.hpp>
#include <mbgl/util/geometry.hpp>
#include <mbgl/math/angles.hpp>
#include <mbgl/math/clamp.hpp>
namespace mbgl {
@@ -48,7 +49,7 @@ public:
const double constrainedZoom = util::clamp(zoom, util::MIN_ZOOM, util::MAX_ZOOM);
const double constrainedScale = std::pow(2.0, constrainedZoom);
const double constrainedLatitude = util::clamp(lat, -util::LATITUDE_MAX, util::LATITUDE_MAX);
return std::cos(constrainedLatitude * util::DEG2RAD_D) * util::M2PI * util::EARTH_RADIUS_M / worldSize(constrainedScale);
return std::cos(util::deg2rad(constrainedLatitude)) * util::M2PI * util::EARTH_RADIUS_M / worldSize(constrainedScale);
}
static ProjectedMeters projectedMetersForLatLng(const LatLng& latLng) {
@@ -56,17 +57,17 @@ public:
const double constrainedLongitude = util::clamp(latLng.longitude(), -util::LONGITUDE_MAX, util::LONGITUDE_MAX);
const double m = 1 - 1e-15;
const double f = util::clamp(std::sin(util::DEG2RAD_D * constrainedLatitude), -m, m);
const double f = util::clamp(std::sin(util::deg2rad(constrainedLatitude)), -m, m);
const double easting = util::EARTH_RADIUS_M * constrainedLongitude * util::DEG2RAD_D;
const double easting = util::deg2rad(util::EARTH_RADIUS_M * constrainedLongitude);
const double northing = 0.5 * util::EARTH_RADIUS_M * std::log((1 + f) / (1 - f));
return {northing, easting};
}
static LatLng latLngForProjectedMeters(const ProjectedMeters& projectedMeters) {
double latitude = (2 * std::atan(std::exp(projectedMeters.northing() / util::EARTH_RADIUS_M)) - (M_PI / 2.0)) * util::RAD2DEG_D;
double longitude = projectedMeters.easting() * util::RAD2DEG_D / util::EARTH_RADIUS_M;
double latitude = util::rad2deg(2 * std::atan(std::exp(projectedMeters.northing() / util::EARTH_RADIUS_M)) - (M_PI / 2.0));
double longitude = util::rad2deg(projectedMeters.easting()) / util::EARTH_RADIUS_M;
latitude = util::clamp(latitude, -util::LATITUDE_MAX, util::LATITUDE_MAX);
longitude = util::clamp(longitude, -util::LONGITUDE_MAX, util::LONGITUDE_MAX);
@@ -86,7 +87,7 @@ public:
static LatLng unproject(const Point<double>& p, double scale, LatLng::WrapMode wrapMode = LatLng::Unwrapped) {
auto p2 = p * util::DEGREES_MAX / worldSize(scale);
return LatLng {
util::DEGREES_MAX / M_PI * std::atan(std::exp((util::LONGITUDE_MAX - p2.y) * util::DEG2RAD_D)) - 90.0,
std::atan(std::exp(util::deg2rad(util::LONGITUDE_MAX - p2.y))) * util::DEGREES_MAX / M_PI - 90.0,
p2.x - util::LONGITUDE_MAX,
wrapMode
};
@@ -97,7 +98,7 @@ private:
const double latitude = util::clamp(latLng.latitude(), -util::LATITUDE_MAX, util::LATITUDE_MAX);
return Point<double> {
util::LONGITUDE_MAX + latLng.longitude(),
util::LONGITUDE_MAX - util::RAD2DEG_D * std::log(std::tan(M_PI / 4 + latitude * M_PI / util::DEGREES_MAX))
util::LONGITUDE_MAX - util::rad2deg(std::log(std::tan(M_PI / 4 + latitude * M_PI / util::DEGREES_MAX)))
} * (worldSize / util::DEGREES_MAX);
}
};

View File

@@ -8,6 +8,7 @@
#include <mbgl/gfx/backend.hpp>
#include <mbgl/gfx/backend_scope.hpp>
#include <mbgl/map/camera.hpp>
#include <mbgl/math/angles.hpp>
#include <mbgl/renderer/renderer.hpp>
#include <mbgl/style/expression/dsl.hpp>
#include <mbgl/style/image.hpp>
@@ -467,8 +468,8 @@ void GLFWView::onKey(GLFWwindow *window, int key, int /*scancode*/, int action,
} break;
case GLFW_KEY_U: {
auto bounds = view->map->getBounds();
if (bounds.minPitch == mbgl::util::PITCH_MIN * mbgl::util::RAD2DEG_D &&
bounds.maxPitch == mbgl::util::PITCH_MAX * mbgl::util::RAD2DEG_D) {
if (bounds.minPitch == mbgl::util::rad2deg(mbgl::util::PITCH_MIN) &&
bounds.maxPitch == mbgl::util::rad2deg(mbgl::util::PITCH_MAX)) {
mbgl::Log::Info(mbgl::Event::General, "Limiting pitch bounds to [30, 40] degrees");
view->map->setBounds(mbgl::BoundOptions().withMinPitch(30).withMaxPitch(40));
} else {

View File

@@ -5,6 +5,7 @@
#include <mbgl/gl/render_custom_layer.hpp>
#include <mbgl/gl/renderable_resource.hpp>
#include <mbgl/map/transform_state.hpp>
#include <mbgl/math/angles.hpp>
#include <mbgl/platform/gl_functions.hpp>
#include <mbgl/renderer/bucket.hpp>
#include <mbgl/renderer/paint_parameters.hpp>
@@ -86,7 +87,7 @@ void RenderCustomLayer::render(PaintParameters& paintParameters) {
parameters.latitude = state.getLatLng().latitude();
parameters.longitude = state.getLatLng().longitude();
parameters.zoom = state.getZoom();
parameters.bearing = -state.getBearing() * util::RAD2DEG_D;
parameters.bearing = util::rad2deg(-state.getBearing());
parameters.pitch = state.getPitch();
parameters.fieldOfView = state.getFieldOfView();
mat4 projMatrix;

View File

@@ -1,18 +1,19 @@
#include <mbgl/layout/symbol_layout.hpp>
#include <mbgl/layout/merge_lines.hpp>
#include <mbgl/layout/clip_lines.hpp>
#include <mbgl/math/angles.hpp>
#include <mbgl/renderer/bucket_parameters.hpp>
#include <mbgl/renderer/layers/render_symbol_layer.hpp>
#include <mbgl/renderer/image_atlas.hpp>
#include <mbgl/text/get_anchors.hpp>
#include <mbgl/text/shaping.hpp>
#include <mbgl/tile/geometry_tile_data.hpp>
#include <mbgl/tile/tile.hpp>
#include <mbgl/util/utf.hpp>
#include <mbgl/util/constants.hpp>
#include <mbgl/util/string.hpp>
#include <mbgl/util/i18n.hpp>
#include <mbgl/util/platform.hpp>
#include <mbgl/tile/geometry_tile_data.hpp>
#include <mbgl/tile/tile.hpp>
#include <mapbox/polylabel.hpp>
@@ -540,7 +541,7 @@ void SymbolLayout::addFeature(const std::size_t layoutFeatureIndex,
const float symbolSpacing = tilePixelRatio * layout->get<SymbolSpacing>();
const float textPadding = layout->get<TextPadding>() * tilePixelRatio;
const float iconPadding = layout->get<IconPadding>() * tilePixelRatio;
const float textMaxAngle = layout->get<TextMaxAngle>() * util::DEG2RAD_F;
const float textMaxAngle = util::deg2radf(layout->get<TextMaxAngle>());
const float iconRotation = layout->evaluate<IconRotate>(zoom, feature, canonicalID);
const float textRotation = layout->evaluate<TextRotate>(zoom, feature, canonicalID);
std::array<float, 2> variableTextOffset;

View File

@@ -4,6 +4,7 @@
#include <mbgl/map/map.hpp>
#include <mbgl/map/map_impl.hpp>
#include <mbgl/map/transform.hpp>
#include <mbgl/math/angles.hpp>
#include <mbgl/math/log2.hpp>
#include <mbgl/renderer/renderer_frontend.hpp>
#include <mbgl/renderer/renderer_observer.hpp>
@@ -156,7 +157,7 @@ void Map::moveBy(const ScreenCoordinate& point, const AnimationOptions& animatio
}
void Map::pitchBy(double pitch, const AnimationOptions& animation) {
easeTo(CameraOptions().withPitch((impl->transform.getPitch() * util::RAD2DEG_D) - pitch), animation);
easeTo(CameraOptions().withPitch(util::rad2deg(impl->transform.getPitch()) - pitch), animation);
}
void Map::scaleBy(double scale, const std::optional<ScreenCoordinate>& anchor, const AnimationOptions& animation) {
@@ -246,8 +247,8 @@ CameraOptions Map::cameraForLatLngs(const std::vector<LatLng>& latLngs,
}
return mbgl::cameraForLatLngs(latLngs, transform, padding)
.withBearing(-transform.getBearing() * util::RAD2DEG_D)
.withPitch(transform.getPitch() * util::RAD2DEG_D);
.withBearing(util::rad2deg(-transform.getBearing()))
.withPitch(util::rad2deg(transform.getPitch()));
}
CameraOptions Map::cameraForGeometry(const Geometry<double>& geometry,
@@ -346,8 +347,8 @@ BoundOptions Map::getBounds() const {
.withLatLngBounds(impl->transform.getState().getLatLngBounds())
.withMinZoom(impl->transform.getState().getMinZoom())
.withMaxZoom(impl->transform.getState().getMaxZoom())
.withMinPitch(impl->transform.getState().getMinPitch() * util::RAD2DEG_D)
.withMaxPitch(impl->transform.getState().getMaxPitch() * util::RAD2DEG_D);
.withMinPitch(util::rad2deg(impl->transform.getState().getMinPitch()))
.withMaxPitch(util::rad2deg(impl->transform.getState().getMaxPitch()));
}
// MARK: - Map options

View File

@@ -1,6 +1,7 @@
#include <mbgl/map/map_projection.hpp>
#include <mbgl/map/map_impl.hpp>
#include <mbgl/map/transform.hpp>
#include <mbgl/math/angles.hpp>
namespace mbgl {
@@ -32,8 +33,8 @@ CameraOptions MapProjection::getCamera() const {
void MapProjection::setVisibleCoordinates(const std::vector<LatLng>& latLngs,
const EdgeInsets& padding) {
transform->jumpTo(mbgl::cameraForLatLngs(latLngs, *transform, padding)
.withBearing(-transform->getBearing() * util::RAD2DEG_D)
.withPitch(transform->getPitch() * util::RAD2DEG_D));
.withBearing(util::rad2deg(-transform->getBearing()))
.withPitch(util::rad2deg(transform->getPitch())));
}
} // namespace mbgl

View File

@@ -7,6 +7,7 @@
#include <mbgl/util/interpolate.hpp>
#include <mbgl/util/chrono.hpp>
#include <mbgl/util/projection.hpp>
#include <mbgl/math/angles.hpp>
#include <mbgl/math/clamp.hpp>
#include <mbgl/util/logging.hpp>
#include <mbgl/util/platform.hpp>
@@ -96,8 +97,8 @@ void Transform::easeTo(const CameraOptions& camera, const AnimationOptions& anim
const LatLng& unwrappedLatLng = camera.center.value_or(startLatLng);
const LatLng& latLng = state.getLatLngBounds() != LatLngBounds() ? unwrappedLatLng : unwrappedLatLng.wrapped();
double zoom = camera.zoom.value_or(getZoom());
double bearing = camera.bearing ? -*camera.bearing * util::DEG2RAD_D : getBearing();
double pitch = camera.pitch ? *camera.pitch * util::DEG2RAD_D : getPitch();
double bearing = camera.bearing ? util::deg2rad(-*camera.bearing) : getBearing();
double pitch = camera.pitch ? util::deg2rad(*camera.pitch) : getPitch();
if (std::isnan(zoom) || std::isnan(bearing) || std::isnan(pitch)) {
if (animation.transitionFinishFn) {
@@ -178,8 +179,8 @@ void Transform::flyTo(const CameraOptions& camera, const AnimationOptions& anima
const EdgeInsets& padding = camera.padding.value_or(state.getEdgeInsets());
const LatLng& latLng = camera.center.value_or(getLatLng(LatLng::Unwrapped)).wrapped();
double zoom = camera.zoom.value_or(getZoom());
double bearing = camera.bearing ? -*camera.bearing * util::DEG2RAD_D : getBearing();
double pitch = camera.pitch ? *camera.pitch * util::DEG2RAD_D : getPitch();
double bearing = camera.bearing ? util::deg2rad(-*camera.bearing) : getBearing();
double pitch = camera.pitch ? util::deg2rad(*camera.pitch) : getPitch();
if (std::isnan(zoom) || std::isnan(bearing) || std::isnan(pitch) || state.getSize().isEmpty()) {
if (animation.transitionFinishFn) {
@@ -382,22 +383,22 @@ void Transform::setMaxZoom(const double maxZoom) {
void Transform::setMinPitch(const double minPitch) {
if (std::isnan(minPitch)) return;
if (minPitch * util::DEG2RAD_D < util::PITCH_MIN) {
if (util::deg2rad(minPitch) < util::PITCH_MIN) {
Log::Warning(Event::General,
"Trying to set minimum pitch below the limit (" + std::to_string(util::PITCH_MIN * util::RAD2DEG_D) +
"Trying to set minimum pitch below the limit (" + std::to_string(util::rad2deg(util::PITCH_MIN)) +
" degrees), the value will be clamped.");
}
state.setMinPitch(minPitch * util::DEG2RAD_D);
state.setMinPitch(util::deg2rad(minPitch));
}
void Transform::setMaxPitch(const double maxPitch) {
if (std::isnan(maxPitch)) return;
if (maxPitch * util::DEG2RAD_D > util::PITCH_MAX) {
if (util::deg2rad(maxPitch) > util::PITCH_MAX) {
Log::Warning(Event::General,
"Trying to set maximum pitch above the limit (" + std::to_string(util::PITCH_MAX * util::RAD2DEG_D) +
"Trying to set maximum pitch above the limit (" + std::to_string(util::rad2deg(util::PITCH_MAX)) +
" degrees), the value will be clamped.");
}
state.setMaxPitch(maxPitch * util::DEG2RAD_D);
state.setMaxPitch(util::deg2rad(maxPitch));
}
// MARK: - Bearing
@@ -418,7 +419,7 @@ void Transform::rotateBy(const ScreenCoordinate& first,
center.y = first.y + std::sin(rotateBearing) * heightOffset;
}
const double bearing = -(state.getBearing() + util::angle_between(first - center, second - center)) * util::RAD2DEG_D;
const double bearing = -util::rad2deg(state.getBearing() + util::angle_between(first - center, second - center));
easeTo(CameraOptions().withBearing(bearing), animation);
}

View File

@@ -1,4 +1,5 @@
#include <mbgl/map/transform_state.hpp>
#include <mbgl/math/angles.hpp>
#include <mbgl/math/clamp.hpp>
#include <mbgl/math/log2.hpp>
#include <mbgl/tile/tile_id.hpp>
@@ -12,7 +13,7 @@ namespace mbgl {
namespace {
LatLng latLngFromMercator(Point<double> mercatorCoordinate, LatLng::WrapMode wrapMode = LatLng::WrapMode::Unwrapped) {
return {util::RAD2DEG_D * (2 * std::atan(std::exp(M_PI - mercatorCoordinate.y * util::M2PI)) - M_PI_2),
return {util::rad2deg(2 * std::atan(std::exp(M_PI - mercatorCoordinate.y * util::M2PI)) - M_PI_2),
mercatorCoordinate.x * 360.0 - 180.0,
wrapMode};
}
@@ -420,8 +421,8 @@ CameraOptions TransformState::getCameraOptions(const std::optional<EdgeInsets>&
.withCenter(getLatLng())
.withPadding(padding ? padding : edgeInsets)
.withZoom(getZoom())
.withBearing(-bearing * util::RAD2DEG_D)
.withPitch(pitch * util::RAD2DEG_D);
.withBearing(util::rad2deg(-bearing))
.withPitch(util::rad2deg(pitch));
}
// MARK: - EdgeInsets
@@ -436,7 +437,7 @@ void TransformState::setEdgeInsets(const EdgeInsets& val) {
// MARK: - Position
LatLng TransformState::getLatLng(LatLng::WrapMode wrapMode) const {
return {util::RAD2DEG_D * (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 * M_PI), -x / Bc, wrapMode};
}
double TransformState::pixel_x() const {
@@ -775,7 +776,7 @@ void TransformState::setLatLngZoom(const LatLng& latLng, double zoom) {
Cc = newWorldSize / util::M2PI;
const double m = 1 - 1e-15;
const double f = util::clamp(std::sin(util::DEG2RAD_D * constrained.latitude()), -m, m);
const double f = util::clamp(std::sin(util::deg2rad(constrained.latitude())), -m, m);
ScreenCoordinate point = {
-constrained.longitude() * Bc,

View File

@@ -12,6 +12,7 @@
#include <mbgl/gfx/cull_face_mode.hpp>
#include <mbgl/gfx/offscreen_texture.hpp>
#include <mbgl/gfx/render_pass.hpp>
#include <mbgl/math/angles.hpp>
#include <mbgl/util/geo.hpp>
namespace mbgl {
@@ -41,7 +42,7 @@ std::array<float, 2> RenderHillshadeLayer::getLatRange(const UnwrappedTileID& id
std::array<float, 2> RenderHillshadeLayer::getLight(const PaintParameters& parameters) {
const auto& evaluated = static_cast<const HillshadeLayerProperties&>(*evaluatedProperties).evaluated;
float azimuthal = evaluated.get<HillshadeIlluminationDirection>() * util::DEG2RAD_F;
float azimuthal = util::deg2radf(evaluated.get<HillshadeIlluminationDirection>());
if (evaluated.get<HillshadeIlluminationAnchor>() == HillshadeIlluminationAnchorType::Viewport) azimuthal = azimuthal - static_cast<float>(parameters.state.getBearing());
return {{evaluated.get<HillshadeExaggeration>(), azimuthal}};
}

View File

@@ -18,6 +18,7 @@
#include <mbgl/gl/context.hpp>
#include <mbgl/gl/renderable_resource.hpp>
#include <mbgl/map/transform_state.hpp>
#include <mbgl/math/angles.hpp>
#include <mbgl/platform/gl_functions.hpp>
#include <mbgl/renderer/bucket.hpp>
#include <mbgl/renderer/layers/render_location_indicator_layer.hpp>
@@ -94,15 +95,15 @@ protected:
}
float dot(const vec2& v2) const { return x * v2.x + y * v2.y; }
vec2 rotated(float degrees) const {
const float cs = std::cos(degrees * util::DEG2RAD_F);
const float sn = std::sin(degrees * util::DEG2RAD_F);
const float cs = std::cos(util::deg2radf(degrees));
const float sn = std::sin(util::deg2radf(degrees));
return vec2{x * cs + y * sn, x * sn + y * cs}.normalized();
}
float bearing() const {
const vec2 norm = normalized();
// From theta to bearing
return util::wrap<float>(static_cast<float>(M_PI_2) - std::atan2(-norm.y, norm.x), 0.0f, static_cast<float>(M_PI * 2.0)) * util::RAD2DEG_F;
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)));
}
Point<double> toPoint() const { return {x, y}; }
@@ -488,7 +489,7 @@ protected:
Point<double> center = project(params.puckPosition, s);
circle[0] = {0, 0};
const auto mapBearing = static_cast<float>(util::wrap(util::RAD2DEG_D * params.bearing, 0.0, util::DEGREES_MAX));
const auto mapBearing = static_cast<float>(util::wrap(util::rad2deg(params.bearing), 0.0, util::DEGREES_MAX));
for (unsigned long i = 1; i <= numVtxCircumference; ++i) {
const float bearing_ = static_cast<float>(i - 1) * bearingStep - mapBearing;
Point<double> poc = ruler.destination(centerPoint, params.errorRadiusMeters, bearing_);
@@ -596,8 +597,8 @@ protected:
for (unsigned long i = 0; i < 4; ++i) {
const auto b = util::wrap<float>(static_cast<float>(params.puckBearing) + bearings[i], 0.0f, 360.0f);
const Point<double> cornerDirection{std::sin(util::DEG2RAD_D * b),
-std::cos(util::DEG2RAD_D * b)};
const Point<double> cornerDirection{std::sin(util::deg2rad(b)),
-std::cos(util::deg2rad(b))};
Point<double> shadowOffset = cornerDirection * shadowRadius;
Point<double> puckOffset = cornerDirection * puckRadius;
@@ -816,7 +817,7 @@ void RenderLocationIndicatorLayer::prepare(const LayerPrepareParameters& p) {
renderImpl->parameters.latitude = state.getLatLng().latitude();
renderImpl->parameters.longitude = state.getLatLng().longitude();
renderImpl->parameters.zoom = state.getZoom();
renderImpl->parameters.bearing = -state.getBearing() * util::RAD2DEG_D;
renderImpl->parameters.bearing = util::rad2deg(-state.getBearing());
renderImpl->parameters.pitch = state.getPitch();
mat4 projMatrix;
state.getProjMatrix(projMatrix);

View File

@@ -8,6 +8,7 @@
#include <mbgl/programs/raster_program.hpp>
#include <mbgl/tile/tile.hpp>
#include <mbgl/gfx/cull_face_mode.hpp>
#include <mbgl/math/angles.hpp>
#include <mbgl/style/layers/raster_layer_impl.hpp>
namespace mbgl {
@@ -67,7 +68,7 @@ static float contrastFactor(float contrast) {
}
static std::array<float, 3> spinWeights(float spin) {
spin *= util::DEG2RAD_F;
spin = util::deg2radf(spin);
float s = std::sin(spin);
float c = std::cos(spin);
std::array<float, 3> spin_weights = {{

View File

@@ -10,6 +10,7 @@
#include <mbgl/util/string.hpp>
#include <rapidjson/document.h>
#include <mbgl/math/angles.hpp>
#include <mbgl/math/clamp.hpp>
namespace mbgl {
@@ -20,7 +21,7 @@ Point<int64_t> latLonToTileCoodinates(const Point<double>& point, const mbgl::Ca
auto x = (point.x + util::LONGITUDE_MAX) * size / util::DEGREES_MAX;
auto y =
(util::LONGITUDE_MAX - (std::log(std::tan(point.y * M_PI / util::DEGREES_MAX + M_PI / 4.0)) * util::RAD2DEG_D)) *
(util::LONGITUDE_MAX - util::rad2deg(std::log(std::tan(point.y * M_PI / util::DEGREES_MAX + M_PI / 4.0)))) *
size / util::DEGREES_MAX;
Point<int64_t> p;

View File

@@ -1,5 +1,6 @@
#include <mbgl/text/collision_feature.hpp>
#include <mbgl/util/math.hpp>
#include <mbgl/math/angles.hpp>
#include <mbgl/math/log2.hpp>
namespace mbgl {
@@ -46,7 +47,7 @@ CollisionFeature::CollisionFeature(const GeometryCoordinates& line,
if (rotate) {
// Account for *-rotate in point collision boxes
// Doesn't account for icon-text-fit
const float rotateRadians = rotate * util::DEG2RAD_F;
const float rotateRadians = util::deg2radf(rotate);
const Point<float> tl = util::rotate(Point<float>(x1, y1), rotateRadians);
const Point<float> tr = util::rotate(Point<float>(x2, y1), rotateRadians);

View File

@@ -1,5 +1,6 @@
#include <mbgl/geometry/anchor.hpp>
#include <mbgl/layout/symbol_instance.hpp>
#include <mbgl/math/angles.hpp>
#include <mbgl/math/minmax.hpp>
#include <mbgl/style/layers/symbol_layer_properties.hpp>
#include <mbgl/text/quads.hpp>
@@ -108,7 +109,7 @@ SymbolQuads getIconQuads(const PositionedIcon& shapedIcon,
std::optional<std::array<float, 4>> matrix{std::nullopt};
if (iconRotate) {
const float angle = iconRotate * util::DEG2RAD_F;
const float angle = util::deg2radf(iconRotate);
const float angle_sin = std::sin(angle);
const float angle_cos = std::cos(angle);
matrix = std::array<float, 4>{{angle_cos, -angle_sin, angle_sin, angle_cos}};
@@ -200,7 +201,7 @@ SymbolQuads getGlyphQuads(const Shaping& shapedText,
const style::SymbolPlacementType placement,
const ImageMap& imageMap,
bool allowVerticalPlacement) {
const float textRotate = layout.get<TextRotate>() * util::DEG2RAD_F;
const float textRotate = util::deg2radf(layout.get<TextRotate>());
const bool alongLine = layout.get<TextRotationAlignment>() == AlignmentType::Map && placement != SymbolPlacementType::Point;
SymbolQuads quads;

View File

@@ -118,7 +118,7 @@ Feature::geometry_type convertGeometry(const GeometryTileFeature& geometryTileFe
double y2 = 180 - (p.y + y0) * 360 / size;
return Point<double>(
(p.x + x0) * 360 / size - 180,
360.0 / M_PI * std::atan(std::exp(y2 * M_PI / 180)) - 90.0
std::atan(std::exp(y2 * M_PI / 180)) * 360.0 / M_PI - 90.0
);
};

View File

@@ -2,6 +2,7 @@
#include <cassert>
#include <cmath>
#include <mbgl/map/camera.hpp>
#include <mbgl/math/angles.hpp>
#include <mbgl/math/log2.hpp>
#include <mbgl/util/constants.hpp>
#include <mbgl/util/geo.hpp>
@@ -34,7 +35,7 @@ static double mercatorYfromLat(double lat) {
}
static double latFromMercatorY(double y) {
return util::RAD2DEG_D * (2.0 * std::atan(std::exp(M_PI - y * util::M2PI)) - M_PI_2);
return util::rad2deg(2.0 * std::atan(std::exp(M_PI - y * util::M2PI)) - M_PI_2);
}
static double lngFromMercatorX(double x) {
@@ -113,7 +114,7 @@ mat4 Camera::getWorldToCamera(double scale, bool flippedY) const {
// cameraToWorld: (flip * cam^-1 * zScale)^-1 => (zScale^-1 * cam * flip^-1)
const double worldSize = Projection::worldSize(scale);
const double latitude = latFromMercatorY(getColumn(transform, 3)[1]);
const double pixelsPerMeter = worldSize / (std::cos(latitude * util::DEG2RAD_D) * util::M2PI * util::EARTH_RADIUS_M);
const double pixelsPerMeter = worldSize / (std::cos(util::deg2rad(latitude)) * util::M2PI * util::EARTH_RADIUS_M);
// Compute inverse of the camera matrix
mat4 result = orientation.conjugate().toRotationMatrix();
@@ -256,7 +257,7 @@ void FreeCameraOptions::lookAtPoint(const LatLng& location, const std::optional<
}
void FreeCameraOptions::setPitchBearing(double pitch, double bearing) {
orientation = util::orientationFromPitchBearing(pitch * util::DEG2RAD_D, bearing * util::DEG2RAD_D).m;
orientation = util::orientationFromPitchBearing(util::deg2rad(pitch), util::deg2rad(bearing)).m;
}
} // namespace mbgl

View File

@@ -1,6 +1,7 @@
#include <mbgl/util/geo.hpp>
#include <mbgl/util/constants.hpp>
#include <mbgl/tile/tile_id.hpp>
#include <mbgl/math/angles.hpp>
#include <mbgl/math/clamp.hpp>
#include <mbgl/util/tile_range.hpp>
@@ -12,7 +13,7 @@ namespace {
double lat_(const uint8_t z, const int64_t y) {
const double n = M_PI - 2.0 * M_PI * y / std::pow(2.0, z);
return util::RAD2DEG_D * std::atan(0.5 * (std::exp(n) - std::exp(-n)));
return util::rad2deg(std::atan(0.5 * (std::exp(n) - std::exp(-n))));
}
double lon_(const uint8_t z, const int64_t x) {

View File

@@ -3,6 +3,7 @@
#include <gmock/gmock.h>
#include <cmath>
#include <mbgl/map/transform.hpp>
#include <mbgl/math/angles.hpp>
#include <mbgl/util/geo.hpp>
#include <mbgl/util/quaternion.hpp>
@@ -68,7 +69,7 @@ TEST(Transform, InvalidBearing) {
ASSERT_DOUBLE_EQ(0, transform.getLatLng().latitude());
ASSERT_DOUBLE_EQ(0, transform.getLatLng().longitude());
ASSERT_DOUBLE_EQ(1, transform.getZoom());
ASSERT_DOUBLE_EQ(-2.0 * util::DEG2RAD_D, transform.getBearing());
ASSERT_DOUBLE_EQ(util::deg2rad(-2.0), transform.getBearing());
const double invalid = NAN;
@@ -76,7 +77,7 @@ TEST(Transform, InvalidBearing) {
ASSERT_DOUBLE_EQ(0, transform.getLatLng().latitude());
ASSERT_DOUBLE_EQ(0, transform.getLatLng().longitude());
ASSERT_DOUBLE_EQ(1, transform.getZoom());
ASSERT_DOUBLE_EQ(-2.0 * util::DEG2RAD_D, transform.getBearing());
ASSERT_DOUBLE_EQ(util::deg2rad(-2.0), transform.getBearing());
}
TEST(Transform, IntegerZoom) {
@@ -272,24 +273,24 @@ TEST(Transform, Anchor) {
ASSERT_DOUBLE_EQ(latLng.longitude(), transform.getLatLng().longitude());
transform.jumpTo(CameraOptions().withBearing(45.0).withAnchor(anchorPoint));
ASSERT_DOUBLE_EQ(-45.0 * util::DEG2RAD_D, transform.getBearing());
ASSERT_DOUBLE_EQ(util::deg2rad(-45.0), transform.getBearing());
// Anchor coordinates are imprecise because we are converting from an integer pixel.
ASSERT_NEAR(anchorLatLng.latitude(), transform.getLatLng().latitude(), 0.5);
ASSERT_NEAR(anchorLatLng.longitude(), transform.getLatLng().longitude(), 0.5);
transform.jumpTo(CameraOptions().withCenter(latLng).withZoom(10.0).withPitch(10.0));
ASSERT_DOUBLE_EQ(10.0 * util::DEG2RAD_D, transform.getPitch());
ASSERT_DOUBLE_EQ(util::deg2rad(10.0), transform.getPitch());
ASSERT_DOUBLE_EQ(latLng.latitude(), transform.getLatLng().latitude());
ASSERT_DOUBLE_EQ(latLng.longitude(), transform.getLatLng().longitude());
transform.jumpTo(CameraOptions().withPitch(15.0));
ASSERT_DOUBLE_EQ(15.0 * util::DEG2RAD_D, transform.getPitch());
ASSERT_DOUBLE_EQ(util::deg2rad(15.0), transform.getPitch());
ASSERT_DOUBLE_EQ(latLng.latitude(), transform.getLatLng().latitude());
ASSERT_DOUBLE_EQ(latLng.longitude(), transform.getLatLng().longitude());
transform.jumpTo(CameraOptions().withPitch(20.0).withAnchor(anchorPoint));
ASSERT_DOUBLE_EQ(20.0 * util::DEG2RAD_D, transform.getPitch());
ASSERT_DOUBLE_EQ(util::deg2rad(20.0), transform.getPitch());
// Anchor coordinates are imprecise because we are converting from an integer pixel.
ASSERT_NEAR(anchorLatLng.latitude(), transform.getLatLng().latitude(), 0.5);
@@ -811,15 +812,15 @@ TEST(Transform, InvalidPitch) {
transform.jumpTo(CameraOptions().withZoom(1.0).withPitch(45));
ASSERT_DOUBLE_EQ(1, transform.getZoom());
ASSERT_DOUBLE_EQ(45 * util::DEG2RAD_D, transform.getPitch());
ASSERT_DOUBLE_EQ(util::deg2rad(45), transform.getPitch());
const double invalid = NAN;
transform.jumpTo(CameraOptions().withPitch(invalid));
ASSERT_DOUBLE_EQ(45 * util::DEG2RAD_D, transform.getPitch());
ASSERT_DOUBLE_EQ(util::deg2rad(45), transform.getPitch());
transform.jumpTo(CameraOptions().withPitch(60));
ASSERT_DOUBLE_EQ(60 * util::DEG2RAD_D, transform.getPitch());
ASSERT_DOUBLE_EQ(util::deg2rad(60), transform.getPitch());
}
TEST(Transform, MinMaxPitch) {
@@ -834,17 +835,17 @@ TEST(Transform, MinMaxPitch) {
transform.jumpTo(CameraOptions().withZoom(1.0).withPitch(60));
ASSERT_DOUBLE_EQ(1, transform.getZoom());
ASSERT_DOUBLE_EQ(transform.getState().getMaxPitch(), transform.getPitch());
ASSERT_DOUBLE_EQ(60 * util::DEG2RAD_D, transform.getPitch());
ASSERT_DOUBLE_EQ(util::deg2rad(60), transform.getPitch());
transform.setMaxPitch(70);
transform.jumpTo(CameraOptions().withPitch(70));
ASSERT_DOUBLE_EQ(transform.getState().getMaxPitch(), transform.getPitch());
ASSERT_DOUBLE_EQ(60 * util::DEG2RAD_D, transform.getPitch());
ASSERT_DOUBLE_EQ(util::deg2rad(60), transform.getPitch());
transform.setMaxPitch(45);
transform.jumpTo(CameraOptions().withPitch(60));
ASSERT_DOUBLE_EQ(transform.getState().getMaxPitch(), transform.getPitch());
ASSERT_DOUBLE_EQ(45 * util::DEG2RAD_D, transform.getPitch());
ASSERT_DOUBLE_EQ(util::deg2rad(45), transform.getPitch());
transform.jumpTo(CameraOptions().withPitch(0));
ASSERT_DOUBLE_EQ(transform.getState().getMinPitch(), transform.getPitch());
@@ -858,18 +859,18 @@ TEST(Transform, MinMaxPitch) {
transform.setMinPitch(15);
transform.jumpTo(CameraOptions().withPitch(0));
ASSERT_DOUBLE_EQ(transform.getState().getMinPitch(), transform.getPitch());
ASSERT_DOUBLE_EQ(15 * util::DEG2RAD_D, transform.getPitch());
ASSERT_DOUBLE_EQ(util::deg2rad(15), transform.getPitch());
transform.setMinPitch(45);
ASSERT_DOUBLE_EQ(45 * util::DEG2RAD_D, transform.getState().getMinPitch());
ASSERT_DOUBLE_EQ(util::deg2rad(45), transform.getState().getMinPitch());
transform.setMaxPitch(45);
ASSERT_DOUBLE_EQ(45 * util::DEG2RAD_D, transform.getState().getMaxPitch());
ASSERT_DOUBLE_EQ(util::deg2rad(45), transform.getState().getMaxPitch());
transform.setMaxPitch(10);
ASSERT_DOUBLE_EQ(45 * util::DEG2RAD_D, transform.getState().getMaxPitch());
ASSERT_DOUBLE_EQ(util::deg2rad(45), transform.getState().getMaxPitch());
transform.setMinPitch(60);
ASSERT_DOUBLE_EQ(45 * util::DEG2RAD_D, transform.getState().getMinPitch());
ASSERT_DOUBLE_EQ(util::deg2rad(45), transform.getState().getMinPitch());
}
static const double abs_double_error = 1e-5;
@@ -968,26 +969,26 @@ TEST(Transform, FreeCameraOptionsSetOrientation) {
EXPECT_DOUBLE_EQ(0.0, transform.getState().getX());
EXPECT_DOUBLE_EQ(0.0, transform.getState().getY());
options.orientation = Quaternion::fromAxisAngle(vec3{{1.0, 0.0, 0.0}}, -60.0 * util::DEG2RAD_D).m;
options.orientation = Quaternion::fromAxisAngle(vec3{{1.0, 0.0, 0.0}}, util::deg2rad(-60.0)).m;
transform.setFreeCameraOptions(options);
EXPECT_DOUBLE_EQ(0.0, transform.getState().getBearing());
EXPECT_DOUBLE_EQ(60.0 * util::DEG2RAD_D, transform.getState().getPitch());
EXPECT_DOUBLE_EQ(util::deg2rad(60.0), transform.getState().getPitch());
EXPECT_DOUBLE_EQ(0.0, transform.getState().getX());
EXPECT_DOUBLE_EQ(206.0, transform.getState().getY());
options.orientation = Quaternion::fromAxisAngle(vec3{{0.0, 0.0, 1.0}}, 56.0 * util::DEG2RAD_D).m;
options.orientation = Quaternion::fromAxisAngle(vec3{{0.0, 0.0, 1.0}}, util::deg2rad(56.0)).m;
transform.setFreeCameraOptions(options);
EXPECT_DOUBLE_EQ(-56.0 * util::DEG2RAD_D, transform.getState().getBearing());
EXPECT_DOUBLE_EQ(util::deg2rad(-56.0), transform.getState().getBearing());
EXPECT_DOUBLE_EQ(0.0, transform.getState().getPitch());
EXPECT_DOUBLE_EQ(0.0, transform.getState().getX());
EXPECT_NEAR(152.192378, transform.getState().getY(), 1e-6);
options.orientation = Quaternion::fromEulerAngles(0.0, 0.0, -179.0 * util::DEG2RAD_D)
.multiply(Quaternion::fromEulerAngles(-30.0 * util::DEG2RAD_D, 0.0, 0.0))
options.orientation = Quaternion::fromEulerAngles(0.0, 0.0, util::deg2rad(-179.0))
.multiply(Quaternion::fromEulerAngles(util::deg2rad(-30.0), 0.0, 0.0))
.m;
transform.setFreeCameraOptions(options);
EXPECT_DOUBLE_EQ(179.0 * util::DEG2RAD_D, transform.getState().getBearing());
EXPECT_DOUBLE_EQ(30.0 * util::DEG2RAD_D, transform.getState().getPitch());
EXPECT_DOUBLE_EQ(util::deg2rad(179.0), transform.getState().getBearing());
EXPECT_DOUBLE_EQ(util::deg2rad(30.0), transform.getState().getPitch());
EXPECT_NEAR(1.308930, transform.getState().getX(), 1e-6);
EXPECT_NEAR(56.813889, transform.getState().getY(), 1e-6);
}
@@ -1004,7 +1005,7 @@ TEST(Transform, FreeCameraOptionsClampPitch) {
FreeCameraOptions options;
vec3 right, up, forward;
options.orientation = Quaternion::fromAxisAngle(vec3{{1.0, 0.0, 0.0}}, -85.0 * util::DEG2RAD_D).m;
options.orientation = Quaternion::fromAxisAngle(vec3{{1.0, 0.0, 0.0}}, util::deg2rad(-85.0)).m;
transform.setFreeCameraOptions(options);
EXPECT_DOUBLE_EQ(util::PITCH_MAX, transform.getState().getPitch());
std::tie(right, up, forward) = rotatedFrame(transform.getFreeCameraOptions().orientation.value());
@@ -1022,14 +1023,14 @@ TEST(Transform, FreeCameraOptionsClampToBounds) {
// Place camera to an arbitrary position looking away from the map
options.position = vec3{{-100.0, -10000.0, 1000.0}};
options.orientation = Quaternion::fromEulerAngles(-45.0 * util::DEG2RAD_D, 0.0, 0.0).m;
options.orientation = Quaternion::fromEulerAngles(util::deg2rad(-45.0), 0.0, 0.0).m;
transform.setFreeCameraOptions(options);
// Map center should be clamped to width/2 pixels away from map borders
EXPECT_DOUBLE_EQ(206.0, transform.getState().getX());
EXPECT_DOUBLE_EQ(206.0, transform.getState().getY());
EXPECT_DOUBLE_EQ(0.0, transform.getState().getBearing());
EXPECT_DOUBLE_EQ(45.0 * util::DEG2RAD_D, transform.getState().getPitch());
EXPECT_DOUBLE_EQ(util::deg2rad(45.0), transform.getState().getPitch());
vec3 right, up, forward;
std::tie(right, up, forward) = rotatedFrame(transform.getFreeCameraOptions().orientation.value());
@@ -1070,7 +1071,7 @@ TEST(Transform, FreeCameraOptionsOrientationRoll) {
EXPECT_NEAR(options.orientation.value()[2], orientationWithoutRoll.z, 1e-9);
EXPECT_NEAR(options.orientation.value()[3], orientationWithoutRoll.w, 1e-9);
EXPECT_NEAR(45.0 * util::DEG2RAD_D, transform.getState().getPitch(), 1e-9);
EXPECT_NEAR(util::deg2rad(45.0), transform.getState().getPitch(), 1e-9);
EXPECT_NEAR(0.0, transform.getState().getBearing(), 1e-9);
EXPECT_NEAR(0.0, transform.getState().getX(), 1e-9);
EXPECT_NEAR(150.0, transform.getState().getY(), 1e-9);

View File

@@ -1,6 +1,7 @@
#include <mbgl/test/util.hpp>
#include <mbgl/map/camera.hpp>
#include <mbgl/math/angles.hpp>
#include <mbgl/util/mat3.hpp>
#include <mbgl/util/quaternion.hpp>
@@ -27,12 +28,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::LATITUDE_MAX * util::DEG2RAD_D)});
{{util::LATITUDE_MAX, 0.0}, util::EARTH_RADIUS_M * 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::LATITUDE_MAX * util::DEG2RAD_D)});
{{-util::LATITUDE_MAX, 0.0}, util::EARTH_RADIUS_M * 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}}));
}
@@ -240,8 +241,8 @@ TEST(FreeCameraOptions, SetPitchBearing) {
ASSERT_THAT(up, Vec3NearEquals1E7(vec3{{0.0, 1.0, 0.0}}));
ASSERT_THAT(forward, Vec3NearEquals1E7(vec3{{0.0, 0.0, -1.0}}));
const double cos60 = std::cos(60.0 * util::DEG2RAD_D);
const double sin60 = std::sin(60.0 * util::DEG2RAD_D);
const double cos60 = std::cos(util::deg2rad(60.0));
const double sin60 = std::sin(util::deg2rad(60.0));
options.setPitchBearing(60.0, 0.0);
ASSERT_TRUE(options.orientation);

View File

@@ -1,6 +1,7 @@
#include <mbgl/util/tile_cover.hpp>
#include <mbgl/util/geo.hpp>
#include <mbgl/map/transform.hpp>
#include <mbgl/math/angles.hpp>
#include <algorithm>
#include <cstdlib> /* srand, rand */
@@ -46,8 +47,8 @@ TEST(TileCover, PitchIssue15442) {
transform.resize({ 412, 691 });
transform.jumpTo(CameraOptions().withCenter(LatLng { 59.116898740996106, 91.565660781803615, })
.withZoom(2.0551126748417214).withBearing(0.74963938256567264 * util::RAD2DEG_D)
.withPitch(1.0471975511965976 * util::RAD2DEG_D));
.withZoom(2.0551126748417214).withBearing(util::rad2deg(0.74963938256567264))
.withPitch(util::rad2deg(1.0471975511965976)));
EXPECT_EQ((std::vector<OverscaledTileID>{
{2, 3, 1}, {2, 2, 1}, {2, 3, 0}, {2, 2, 0}, {2, 1, {2, 0, 0}}, {2, 1, {2, 1, 0}}}),
@@ -61,7 +62,7 @@ TEST(TileCover, PitchOverAllowedByContentInsets) {
transform.jumpTo(CameraOptions().withCenter(LatLng { 0.1, -0.1 }).withPadding(EdgeInsets { 376, 0, 0, 0 })
.withZoom(8.0).withBearing(45.0).withPitch(60.0));
// Top padding of 376 leads to capped pitch. See Transform::getMaxPitchForEdgeInsets.
EXPECT_LE(transform.getPitch() + 0.001, util::DEG2RAD_D * 60);
EXPECT_LE(transform.getPitch() + 0.001, util::deg2rad(60));
EXPECT_EQ(
(std::vector<OverscaledTileID>{{3, 4, 3}, {3, 3, 3}, {3, 4, 4}, {3, 3, 4}, {3, 4, 2}, {3, 5, 3}, {3, 5, 2}}),