summaryrefslogtreecommitdiff
path: root/test/tile/geometry_tile.cpp
blob: 998a7183a7398f992ed62b4e127f9ceee7c4559a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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(), 1u);
    // output: polygon 1 has 1 exterior
    ASSERT_EQ(polygons[0].size(), 1u);
}

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(), 1u);
    // output: polygon 1 has 1 exterior, 1 interior
    ASSERT_EQ(polygons[0].size(), 2u);
}

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(), 2u);

    // 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(), 2u);

    // 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);
}