summaryrefslogtreecommitdiff
path: root/test/tile
diff options
context:
space:
mode:
authorYoung Hahn <young@mapbox.com>2016-05-25 02:45:54 -0400
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-05-31 10:15:18 -0700
commita800d33dd8b88b1be8db64a4ee83835758a9718e (patch)
tree767f778866b7d6de502ba3de25b818c5f0ea1373 /test/tile
parent517218204fb3639413161662824164c463c7e407 (diff)
downloadqtlocation-mapboxgl-a800d33dd8b88b1be8db64a4ee83835758a9718e.tar.gz
[core] Don't earcut more than 500 inner rings
Diffstat (limited to 'test/tile')
-rw-r--r--test/tile/geometry_tile.cpp61
1 files changed, 61 insertions, 0 deletions
diff --git a/test/tile/geometry_tile.cpp b/test/tile/geometry_tile.cpp
new file mode 100644
index 0000000000..c94b20cee6
--- /dev/null
+++ b/test/tile/geometry_tile.cpp
@@ -0,0 +1,61 @@
+#include <mbgl/test/util.hpp>
+#include <mbgl/tile/geometry_tile.hpp>
+
+using namespace mbgl;
+
+TEST(GeometryTile, classifyRings1) {
+ std::vector<GeometryCollection> polygons = classifyRings({
+ { {0, 0}, {0, 40}, {40, 40}, {40, 0}, {0, 0} }
+ });
+
+ // output: 1 polygon
+ ASSERT_EQ(polygons.size(), 1);
+ // output: polygon 1 has 1 exterior
+ ASSERT_EQ(polygons[0].size(), 1);
+}
+
+TEST(GeometryTile, classifyRings2) {
+ std::vector<GeometryCollection> polygons = classifyRings({
+ { {0, 0}, {0, 40}, {40, 40}, {40, 0}, {0, 0} },
+ { {10, 10}, {20, 10}, {20, 20}, {10, 10} }
+ });
+
+ // output: 1 polygon
+ ASSERT_EQ(polygons.size(), 1);
+ // output: polygon 1 has 1 exterior, 1 interior
+ ASSERT_EQ(polygons[0].size(), 2);
+}
+
+TEST(GeometryTile, limitHoles1) {
+ GeometryCollection polygon = {
+ { {0, 0}, {0, 40}, {40, 40}, {40, 0}, {0, 0} },
+ { {30, 30}, {32, 30}, {32, 32}, {30, 30} },
+ { {10, 10}, {20, 10}, {20, 20}, {10, 10} }
+ };
+
+ limitHoles(polygon, 1);
+
+ // output: polygon 1 has 1 exterior, 1 interior
+ ASSERT_EQ(polygon.size(), 2);
+
+ // ensure we've kept the right rings (ones with largest areas)
+ ASSERT_EQ(polygon[0][0].x, 0);
+ ASSERT_EQ(polygon[1][0].x, 10);
+}
+
+TEST(GeometryTile, limitHoles2) {
+ GeometryCollection polygon = {
+ { {0, 0}, {0, 40}, {40, 40}, {40, 0}, {0, 0} },
+ { {10, 10}, {20, 10}, {20, 20}, {10, 10} },
+ { {30, 30}, {32, 30}, {32, 32}, {30, 30} }
+ };
+
+ limitHoles(polygon, 1);
+
+ // output: polygon 1 has 1 exterior, 1 interior
+ ASSERT_EQ(polygon.size(), 2);
+
+ // ensure we've kept the right rings (ones with largest areas)
+ ASSERT_EQ(polygon[0][0].x, 0);
+ ASSERT_EQ(polygon[1][0].x, 10);
+}