File: CoverageRingEdgesTest.cpp

package info (click to toggle)
geos 3.14.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 31,212 kB
  • sloc: cpp: 199,103; xml: 56,065; ansic: 6,162; sh: 287; makefile: 26
file content (150 lines) | stat: -rw-r--r-- 4,929 bytes parent folder | download | duplicates (2)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
//
// Test Suite for geos::coverage::CoverageRingEdges class.

#include <tut/tut.hpp>
#include <utility.h>

// geos
#include <geos/coverage/CoverageRingEdges.h>
#include <geos/coverage/CoverageEdge.h>

using geos::coverage::CoverageRingEdges;
using geos::coverage::CoverageEdge;
using geos::geom::MultiLineString;

namespace tut {
//
// Test Group
//

// Common data used by all tests
struct test_coverageringedges_data
 {

    WKTReader r;
    WKTWriter w;

    test_coverageringedges_data() {
    }

    void
    checkEdges(const std::string& wkt, const std::string& wktExpected)
    {
        std::unique_ptr<Geometry> geom = r.read(wkt);
        std::vector<const Geometry*> polygons = toArray(*geom);
        CoverageRingEdges cov(polygons);
        std::vector<CoverageEdge*>& edges = cov.getEdges();
        std::unique_ptr<Geometry> edgeLines = toArray(edges, geom->getFactory());
        std::unique_ptr<Geometry> expected = r.read(wktExpected);
        ensure_equals_geometry(edgeLines.get(), expected.get());
    }

    void
    checkEdgesSelected(const std::string& wkt, std::size_t ringCount, const std::string& wktExpected)
    {
        std::unique_ptr<Geometry> geom = r.read(wkt);
        auto polygons = toArray(*geom);
        CoverageRingEdges covEdges(polygons);
        auto edges = covEdges.selectEdges(ringCount);
        auto edgeLines = toArray(edges, geom->getFactory());
        std::unique_ptr<Geometry> expected = r.read(wktExpected);
        ensure_equals_geometry(edgeLines.get(), expected.get());
    }

    std::unique_ptr<Geometry>
    toArray(std::vector<CoverageEdge*>& edges, const GeometryFactory* geomFactory)
    {
        std::vector<std::unique_ptr<LineString>> lines;
        for (auto* edge : edges) {
            lines.push_back(edge->toLineString(geomFactory));
        }
        return geomFactory->createMultiLineString(std::move(lines));
    }

    std::vector<const Geometry*>
    toArray(const Geometry& geom)
    {
        std::vector<const Geometry*> geoms;
        for (std::size_t i = 0; i < geom.getNumGeometries(); i++) {
            geoms.push_back(geom.getGeometryN(i));
        }
        return geoms;
    }
};


typedef test_group<test_coverageringedges_data> group;
typedef group::object object;

group test_coverageringedges_data("geos::coverage::CoverageRingEdges");


// testTwoAdjacent
template<>
template<>
void object::test<1> ()
{
    checkEdges(
        "GEOMETRYCOLLECTION (POLYGON ((1 1, 1 6, 6 5, 9 6, 9 1, 1 1)), POLYGON ((1 9, 6 9, 6 5, 1 6, 1 9)))",
        "MULTILINESTRING ((1 6, 1 1, 9 1, 9 6, 6 5), (1 6, 1 9, 6 9, 6 5), (1 6, 6 5))"
    );
}

// testTwoAdjacentWithFilledHole
template<>
template<>
void object::test<2> ()
{
    checkEdges(
        "GEOMETRYCOLLECTION (POLYGON ((1 1, 1 6, 6 5, 9 6, 9 1, 1 1), (2 4, 4 4, 4 2, 2 2, 2 4)), POLYGON ((1 9, 6 9, 6 5, 1 6, 1 9)), POLYGON ((4 2, 2 2, 2 4, 4 4, 4 2)))",
        "MULTILINESTRING ((1 6, 1 1, 9 1, 9 6, 6 5), (1 6, 1 9, 6 9, 6 5), (1 6, 6 5), (2 4, 2 2, 4 2, 4 4, 2 4))"
    );
}

// testHolesAndFillWithDifferentEndpoints
template<>
template<>
void object::test<3> ()
{
    checkEdges(
        "GEOMETRYCOLLECTION (POLYGON ((0 10, 10 10, 10 0, 0 0, 0 10), (1 9, 4 8, 9 9, 9 1, 1 1, 1 9)), POLYGON ((9 9, 1 1, 1 9, 4 8, 9 9)), POLYGON ((1 1, 9 9, 9 1, 1 1)))",
        "MULTILINESTRING ((0 10, 0 0, 10 0, 10 10, 0 10), (1 1, 1 9, 4 8, 9 9), (1 1, 9 1, 9 9), (1 1, 9 9))"
    );
}

// testTouchingSquares
template<>
template<>
void object::test<4> ()
{
    std::string wkt = "MULTIPOLYGON (((2 7, 2 8, 3 8, 3 7, 2 7)), ((1 6, 1 7, 2 7, 2 6, 1 6)), ((0 7, 0 8, 1 8, 1 7, 0 7)), ((0 5, 0 6, 1 6, 1 5, 0 5)), ((2 5, 2 6, 3 6, 3 5, 2 5)))";
    checkEdgesSelected(wkt, 1,
        "MULTILINESTRING ((1 6, 0 6, 0 5, 1 5, 1 6), (1 6, 1 7), (1 6, 2 6), (1 7, 0 7, 0 8, 1 8, 1 7), (1 7, 2 7), (2 6, 2 5, 3 5, 3 6, 2 6), (2 6, 2 7), (2 7, 2 8, 3 8, 3 7, 2 7))");
    checkEdgesSelected(wkt, 2,
        "MULTILINESTRING EMPTY");
}

// testAdjacentSquares
template<>
template<>
void object::test<5> ()
{
    std::string wkt = "GEOMETRYCOLLECTION (POLYGON ((1 3, 2 3, 2 2, 1 2, 1 3)), POLYGON ((3 3, 3 2, 2 2, 2 3, 3 3)), POLYGON ((3 1, 2 1, 2 2, 3 2, 3 1)), POLYGON ((1 1, 1 2, 2 2, 2 1, 1 1)))";
    checkEdgesSelected(wkt, 1,
        "MULTILINESTRING ((1 2, 1 1, 2 1), (1 2, 1 3, 2 3), (2 1, 3 1, 3 2), (2 3, 3 3, 3 2))");
    checkEdgesSelected(wkt, 2,
        "MULTILINESTRING ((1 2, 2 2), (2 1, 2 2), (2 2, 2 3), (2 2, 3 2))");
}

// testMultiPolygons
template<>
template<>
void object::test<6> ()
{
    checkEdges(
        "GEOMETRYCOLLECTION (MULTIPOLYGON (((5 9, 2.5 7.5, 1 5, 5 5, 5 9)), ((5 5, 9 5, 7.5 2.5, 5 1, 5 5))), MULTIPOLYGON (((5 9, 6.5 6.5, 9 5, 5 5, 5 9)), ((1 5, 5 5, 5 1, 3.5 3.5, 1 5))))",
        "MULTILINESTRING ((1 5, 2.5 7.5, 5 9), (1 5, 3.5 3.5, 5 1), (1 5, 5 5), (5 1, 5 5), (5 1, 7.5 2.5, 9 5), (5 5, 5 9), (5 5, 9 5), (5 9, 6.5 6.5, 9 5))"
    );
}

} // namespace tut