summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-01-29 15:21:32 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-02-10 15:40:20 -0800
commit7d6c6c00cac53a3864f0dfd399e64fd862d017e1 (patch)
tree0cbd724297db689cf07c79123b9a19e17c856e62 /test
parentf52b6105db22aeafab0737ba2202d79ca60896f7 (diff)
downloadqtlocation-mapboxgl-7d6c6c00cac53a3864f0dfd399e64fd862d017e1.tar.gz
[core] Refactor tileCover
Diffstat (limited to 'test')
-rw-r--r--test/test.gypi1
-rw-r--r--test/util/tile_cover.cpp118
2 files changed, 119 insertions, 0 deletions
diff --git a/test/test.gypi b/test/test.gypi
index 34c9d8dd56..22e3d0184e 100644
--- a/test/test.gypi
+++ b/test/test.gypi
@@ -47,6 +47,7 @@
'util/text_conversions.cpp',
'util/thread.cpp',
'util/thread_local.cpp',
+ 'util/tile_cover.cpp',
'util/timer.cpp',
'util/token.cpp',
'util/work_queue.cpp',
diff --git a/test/util/tile_cover.cpp b/test/util/tile_cover.cpp
new file mode 100644
index 0000000000..d003653fd8
--- /dev/null
+++ b/test/util/tile_cover.cpp
@@ -0,0 +1,118 @@
+#include <mbgl/util/tile_cover.hpp>
+#include <mbgl/util/geo.hpp>
+#include <mbgl/map/tile_id.hpp>
+
+#include <gtest/gtest.h>
+
+#include <unordered_set>
+
+using namespace mbgl;
+using set = std::unordered_set<TileID>;
+
+TEST(TileCover, Empty) {
+ auto result = tileCover(LatLngBounds::empty(), 0, 0);
+ ASSERT_TRUE(result.empty());
+}
+
+TEST(TileCover, Arctic) {
+ auto result = tileCover(LatLngBounds::hull({ 86, -180 }, { 90, 180 }), 0, 0);
+ ASSERT_TRUE(result.empty());
+}
+
+TEST(TileCover, Antarctic) {
+ auto result = tileCover(LatLngBounds::hull({ -86, -180 }, { -90, 180 }), 0, 0);
+ ASSERT_TRUE(result.empty());
+}
+
+TEST(TileCover, WorldZ0) {
+ auto result = tileCover(LatLngBounds::world(), 0, 0);
+ ASSERT_EQ(1, result.size());
+ ASSERT_EQ(0, result[0].z);
+ ASSERT_EQ(0, result[0].x);
+ ASSERT_EQ(0, result[0].y);
+}
+
+TEST(TileCover, WorldZ1) {
+ auto result = tileCover(LatLngBounds::world(), 1, 1);
+ ASSERT_EQ(4, result.size());
+ ASSERT_EQ(
+ (set {{
+ TileID(1, 1, 1, 1),
+ TileID(1, 0, 1, 1),
+ TileID(1, 1, 0, 1),
+ TileID(1, 0, 0, 1)
+ }}),
+ (set {
+ result.begin(),
+ result.end()
+ }));
+}
+
+//TEST(TileCover, SingletonZ0) {
+// auto result = tileCover(LatLngBounds::singleton({0, 0}), 0, 0);
+// ASSERT_EQ(1, result.size());
+// ASSERT_EQ(0, result[0].z);
+// ASSERT_EQ(0, result[0].x);
+// ASSERT_EQ(0, result[0].y);
+//}
+//
+//TEST(TileCover, SingletonZ1) {
+// auto result = tileCover(LatLngBounds::singleton({0, 0}), 1, 1);
+// ASSERT_EQ(1, result.size());
+// ASSERT_EQ(0, result[0].z);
+// ASSERT_EQ(0, result[0].x);
+// ASSERT_EQ(0, result[0].y);
+//}
+
+static const LatLngBounds sanFrancisco = LatLngBounds::hull(
+ { 37.6609, -122.5744 },
+ { 37.8271, -122.3204 });
+
+TEST(TileCover, SanFranciscoZ0) {
+ auto result = tileCover(sanFrancisco, 0, 0);
+ ASSERT_EQ(1, result.size());
+ ASSERT_EQ(0, result[0].w);
+ ASSERT_EQ(0, result[0].z);
+ ASSERT_EQ(0, result[0].x);
+ ASSERT_EQ(0, result[0].y);
+}
+
+TEST(TileCover, SanFranciscoZ10) {
+ auto result = tileCover(sanFrancisco, 10, 10);
+ ASSERT_EQ(4, result.size());
+ ASSERT_EQ(
+ (set {{
+ TileID(10, 163, 395, 10),
+ TileID(10, 164, 395, 10),
+ TileID(10, 163, 396, 10),
+ TileID(10, 164, 396, 10)
+ }}),
+ (set {
+ result.begin(),
+ result.end()
+ }));
+}
+
+//TEST(TileCover, OrderedByDistanceToCenter) {
+// auto result = tileCover(sanFrancisco, 12, 12);
+// ASSERT_EQ(12, result.size());
+// ASSERT_EQ( 12, result[0].z);
+// ASSERT_EQ( 654, result[0].x);
+// ASSERT_EQ(1583, result[0].y);
+// ASSERT_EQ( 12, result[1].z);
+// ASSERT_EQ( 655, result[1].x);
+// ASSERT_EQ(1583, result[1].y);
+//}
+//
+//static const LatLngBounds sanFranciscoWrapped = LatLngBounds::hull(
+// { 37.6609, 238.5744 },
+// { 37.8271, 238.3204 });
+//
+//TEST(TileCover, SanFranciscoZ0Wrapped) {
+// auto result = tileCover(sanFranciscoWrapped, 0, 0);
+// ASSERT_EQ(1, result.size());
+// ASSERT_EQ(1, result[0].w);
+// ASSERT_EQ(0, result[0].z);
+// ASSERT_EQ(0, result[0].x);
+// ASSERT_EQ(0, result[0].y);
+//}