Add clang-format (#1086)

Co-authored-by: mwilsnd <mwilsnd@gmail.com>
This commit is contained in:
Bart Louwers
2023-05-01 16:57:37 +02:00
committed by GitHub
parent 403a12bd1b
commit 71f6da2722
1018 changed files with 27876 additions and 25862 deletions

View File

@@ -8,11 +8,9 @@
#include <mbgl/util/geometry.hpp>
#include <mbgl/util/tile_coordinate.hpp>
using namespace mbgl;
TEST(TileCoordinate, FromLatLng) {
size_t changeCount = 0;
struct TransformObserver : public mbgl::MapObserver {
void onCameraWillChange(MapObserver::CameraChangeMode mode) final {
@@ -43,15 +41,15 @@ TEST(TileCoordinate, FromLatLng) {
Transform transform(observer);
const double max = util::tileSize_D;
transform.resize({ static_cast<uint32_t>(max), static_cast<uint32_t>(max) });
transform.resize({static_cast<uint32_t>(max), static_cast<uint32_t>(max)});
// Center, top-left, bottom-left, bottom-right, top-right edges.
std::vector<std::pair<LatLng, ScreenCoordinate>> edges {
{ {}, { max / 2.0, max / 2.0 } },
{ { util::LATITUDE_MAX, -util::LONGITUDE_MAX }, { 0, max } },
{ { -util::LATITUDE_MAX, -util::LONGITUDE_MAX }, { 0, 0 } },
{ { -util::LATITUDE_MAX, util::LONGITUDE_MAX }, { max, 0 } },
{ { util::LATITUDE_MAX, util::LONGITUDE_MAX }, { max, max } },
std::vector<std::pair<LatLng, ScreenCoordinate>> edges{
{{}, {max / 2.0, max / 2.0}},
{{util::LATITUDE_MAX, -util::LONGITUDE_MAX}, {0, max}},
{{-util::LATITUDE_MAX, -util::LONGITUDE_MAX}, {0, 0}},
{{-util::LATITUDE_MAX, util::LONGITUDE_MAX}, {max, 0}},
{{util::LATITUDE_MAX, util::LONGITUDE_MAX}, {max, max}},
};
for (const auto& pair : edges) {
@@ -64,8 +62,12 @@ TEST(TileCoordinate, FromLatLng) {
const double zoom = integerZoom;
const double maxTilesPerAxis = std::pow(2.0, zoom);
const Point<double> tilePoint = {
latLng.longitude() == 0 ? 0.5 : latLng.longitude() == -util::LONGITUDE_MAX ? 0 : 1.0,
latLng.latitude() == 0 ? 0.5 : latLng.latitude() == -util::LATITUDE_MAX ? 1.0 : 0,
latLng.longitude() == 0 ? 0.5
: latLng.longitude() == -util::LONGITUDE_MAX ? 0
: 1.0,
latLng.latitude() == 0 ? 0.5
: latLng.latitude() == -util::LATITUDE_MAX ? 1.0
: 0,
};
const auto fromLatLng = TileCoordinate::fromLatLng(zoom, latLng);
@@ -73,7 +75,8 @@ TEST(TileCoordinate, FromLatLng) {
ASSERT_DOUBLE_EQ(fromLatLng.p.x, tilePoint.x * maxTilesPerAxis);
ASSERT_NEAR(fromLatLng.p.y, tilePoint.y * maxTilesPerAxis, 1.0e-7);
const auto fromScreenCoordinate = TileCoordinate::fromScreenCoordinate(transform.getState(), static_cast<uint8_t>(zoom), screenCoordinate);
const auto fromScreenCoordinate = TileCoordinate::fromScreenCoordinate(
transform.getState(), static_cast<uint8_t>(zoom), screenCoordinate);
ASSERT_DOUBLE_EQ(fromScreenCoordinate.z, fromLatLng.z);
ASSERT_NEAR(fromScreenCoordinate.p.x, fromLatLng.p.x, 0.99);
ASSERT_NEAR(fromScreenCoordinate.p.y, fromLatLng.p.y, 0.99);
@@ -87,16 +90,18 @@ TEST(TileCoordinate, FromLatLng) {
}
TEST(TileCoordinate, ToGeometryCoordinate) {
std::vector<Point<double>> edges {
{ 0.5, 0.5 }, { 0, 0 }, { 1, 0 }, { 1, 1 }, { 0, 1 }
};
std::vector<Point<double>> edges{{0.5, 0.5}, {0, 0}, {1, 0}, {1, 1}, {0, 1}};
for (uint8_t zoom = 0; zoom <= 16; ++zoom) {
auto maxTilesPerAxis = static_cast<uint32_t>(std::pow(2, zoom));
for (const auto& edge : edges) {
uint32_t tileX = edge.x == 0 ? 0 : edge.x == 1 ? maxTilesPerAxis - 1 : static_cast<uint32_t>((maxTilesPerAxis / 2.0) - 1);
uint32_t tileY = edge.y == 0 ? 0 : edge.y == 1 ? maxTilesPerAxis - 1 : static_cast<uint32_t>((maxTilesPerAxis / 2.0) - 1);
UnwrappedTileID unwrapped(0, CanonicalTileID { zoom, tileX, tileY });
uint32_t tileX = edge.x == 0 ? 0
: edge.x == 1 ? maxTilesPerAxis - 1
: static_cast<uint32_t>((maxTilesPerAxis / 2.0) - 1);
uint32_t tileY = edge.y == 0 ? 0
: edge.y == 1 ? maxTilesPerAxis - 1
: static_cast<uint32_t>((maxTilesPerAxis / 2.0) - 1);
UnwrappedTileID unwrapped(0, CanonicalTileID{zoom, tileX, tileY});
auto tilePointX = ((edge.x * maxTilesPerAxis) - tileX) * util::EXTENT;
auto tilePointY = ((edge.y * maxTilesPerAxis) - tileY) * util::EXTENT;