[msvc] Fix warnings, mainly casting to smaller types (#270)

If the checks by GitHub Actions checks are met, then it seems good to go.  Thanks for supporting FOSS4G!
This commit is contained in:
Tadej Novak
2022-04-22 20:40:55 +02:00
committed by GitHub
parent cf41e113f9
commit 32ed70c95d
121 changed files with 645 additions and 459 deletions

View File

@@ -1,6 +1,17 @@
#pragma once
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4244)
#pragma warning(disable: 4267)
#endif
#include <mapbox/cheap_ruler.hpp>
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#include <mbgl/style/expression/expression.hpp>
#include <mbgl/util/geojson.hpp>

View File

@@ -52,8 +52,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;
const float _p = polar * util::DEG2RAD;
const float _a = (azimuthal + 90) * util::DEG2RAD_F;
const float _p = polar * util::DEG2RAD_F;
x = radial * std::cos(_a) * std::sin(_p);
y = radial * std::sin(_a) * std::sin(_p);

View File

@@ -24,7 +24,7 @@ class CustomGeometrySource final : public Source {
public:
struct TileOptions {
double tolerance = 0.375;
uint16_t tileSize = util::tileSize;
uint16_t tileSize = util::tileSize_I;
uint16_t buffer = 128;
bool clip = false;
bool wrap = false;

View File

@@ -21,7 +21,7 @@ struct GeoJSONOptions {
// GeoJSON-VT options
uint8_t minzoom = 0;
uint8_t maxzoom = 18;
uint16_t tileSize = util::tileSize;
uint16_t tileSize = util::tileSize_I;
uint16_t buffer = 128;
double tolerance = 0.375;
bool lineMetrics = false;

View File

@@ -248,7 +248,7 @@ inline OverscaledTileID UnwrappedTileID::overscaleTo(const uint8_t overscaledZ)
}
inline float UnwrappedTileID::pixelsToTileUnits(const float pixelValue, const float zoom) const {
return pixelValue * (static_cast<float>(util::EXTENT) / (static_cast<float>(util::tileSize) * std::pow(2.f, zoom - canonical.z)));
return pixelValue * (static_cast<float>(util::EXTENT) / (static_cast<float>(util::tileSize_D) * std::pow(2.f, zoom - canonical.z)));
}
} // namespace mbgl

View File

@@ -11,7 +11,8 @@ namespace mbgl {
namespace util {
constexpr double tileSize = 512;
constexpr double tileSize_D = 512;
constexpr uint16_t tileSize_I = 512;
/*
* The maximum extent of a feature that can be safely stored in the buffer.
@@ -26,8 +27,10 @@ constexpr double tileSize = 512;
*/
constexpr int32_t EXTENT = 8192;
constexpr double DEG2RAD = M_PI / 180.0;
constexpr double RAD2DEG = 180.0 / M_PI;
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

@@ -32,9 +32,9 @@ public:
template <class T>
optional<T> numericValue(const Value& value) {
return value.match([](uint64_t t) { return optional<T>(t); },
[](int64_t t) { return optional<T>(t); },
[](double t) { return optional<T>(t); },
return value.match([](uint64_t t) { return optional<T>(static_cast<T>(t)); },
[](int64_t t) { return optional<T>(static_cast<T>(t)); },
[](double t) { return optional<T>(static_cast<T>(t)); },
[](const auto&) { return optional<T>(); });
}

View File

@@ -41,7 +41,7 @@ using Geometry = mapbox::geometry::geometry<T>;
template <class S, class T>
Point<S> convertPoint(const Point<T>& p) {
return Point<S>(p.x, p.y);
return Point<S>(static_cast<S>(p.x), static_cast<S>(p.y));
}
struct ToFeatureType {

View File

@@ -25,6 +25,10 @@ T interpolate(const T& a, const T& b, const double t) {
return Interpolator<T>()(a, b, t);
}
template <typename T>
T interpolate(const T& a, const T& b, const float t) {
return Interpolator<T>()(a, b, t);
}
template <class T, class Enabled>
struct Interpolator {
@@ -33,6 +37,17 @@ struct Interpolator {
}
};
template <>
struct Interpolator<float> {
float operator()(const float& a, const float& b, const float t) const {
return a * (1.0f - t) + b * t;
}
float operator()(const float& a, const float& b, const double t) const {
return static_cast<float>(a * (1.0 - t) + b * t);
}
};
template <class T, std::size_t N>
struct Interpolator<std::array<T, N>> {
private:
@@ -49,6 +64,22 @@ public:
}
};
template <std::size_t N>
struct Interpolator<std::array<float, N>> {
private:
using Array = std::array<float, N>;
template <std::size_t... I>
Array operator()(const Array& a, const Array& b, const float t, std::index_sequence<I...>) {
return {{ interpolate(a[I], b[I], t)... }};
}
public:
Array operator()(const Array& a, const Array& b, const float t) {
return operator()(a, b, t, std::make_index_sequence<N>());
}
};
// In order to accept Array<Number, N> as an output value for Curve
// expressions, we need to have an interpolatable std::vector type.
@@ -82,7 +113,7 @@ struct Interpolator<std::vector<style::expression::Value>> {
template <>
struct Interpolator<style::Position> {
public:
style::Position operator()(const style::Position& a, const style::Position& b, const double t) {
style::Position operator()(const style::Position& a, const style::Position& b, const float t) {
auto pos = style::Position();
auto interpolated = interpolate(a.getCartesian(), b.getCartesian(), t);
pos.setCartesian(interpolated);
@@ -93,6 +124,15 @@ public:
template <>
struct Interpolator<Color> {
public:
Color operator()(const Color& a, const Color& b, const float t) {
return {
interpolate(a.r, b.r, t),
interpolate(a.g, b.g, t),
interpolate(a.b, b.b, t),
interpolate(a.a, b.a, t)
};
}
Color operator()(const Color& a, const Color& b, const double t) {
return {
interpolate(a.r, b.r, t),

View File

@@ -41,14 +41,14 @@ class Projection {
public:
// Map pixel width at given scale.
static double worldSize(double scale) {
return scale * util::tileSize;
return scale * util::tileSize_D;
}
static double getMetersPerPixelAtLatitude(double lat, double zoom) {
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) * util::M2PI * util::EARTH_RADIUS_M / worldSize(constrainedScale);
return std::cos(constrainedLatitude * util::DEG2RAD_D) * util::M2PI * util::EARTH_RADIUS_M / worldSize(constrainedScale);
}
static ProjectedMeters projectedMetersForLatLng(const LatLng& latLng) {
@@ -56,17 +56,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 * constrainedLatitude), -m, m);
const double f = util::clamp(std::sin(util::DEG2RAD_D * constrainedLatitude), -m, m);
const double easting = util::EARTH_RADIUS_M * constrainedLongitude * util::DEG2RAD;
const double easting = util::EARTH_RADIUS_M * constrainedLongitude * util::DEG2RAD_D;
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;
double longitude = projectedMeters.easting() * util::RAD2DEG / util::EARTH_RADIUS_M;
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;
latitude = util::clamp(latitude, -util::LATITUDE_MAX, util::LATITUDE_MAX);
longitude = util::clamp(longitude, -util::LONGITUDE_MAX, util::LONGITUDE_MAX);
@@ -86,7 +86,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)) - 90.0,
util::DEGREES_MAX / M_PI * std::atan(std::exp((util::LONGITUDE_MAX - p2.y) * util::DEG2RAD_D)) - 90.0,
p2.x - util::LONGITUDE_MAX,
wrapMode
};
@@ -97,7 +97,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 * std::log(std::tan(M_PI / 4 + latitude * M_PI / util::DEGREES_MAX))
util::LONGITUDE_MAX - util::RAD2DEG_D * std::log(std::tan(M_PI / 4 + latitude * M_PI / util::DEGREES_MAX))
} * (worldSize / util::DEGREES_MAX);
}
};

View File

@@ -1,7 +1,16 @@
#pragma once
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4244)
#endif
#include <mapbox/variant.hpp>
#ifdef _MSC_VER
#pragma warning(pop)
#endif
namespace mbgl {
template <typename... T>