File: BoundaryOpTest.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 (191 lines) | stat: -rw-r--r-- 5,689 bytes parent folder | download
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#include <tut/tut.hpp>
// geos
#include <geos/geom/Geometry.h>
#include <geos/io/WKTReader.h>
#include <geos/algorithm/BoundaryNodeRule.h>
#include <geos/operation/BoundaryOp.h>
// std
#include <string>
#include <memory>

using namespace geos::algorithm;
using namespace geos::geom;
using geos::operation::BoundaryOp;

namespace tut {
//----------------------------------------------
// Test Group
//----------------------------------------------

struct test_boundaryop_data {
    geos::io::WKTReader wktreader;

    void runBoundaryTest(const std::string& wkt, const BoundaryNodeRule& bnRule, const std::string& wktExpected)
    {
        auto g = wktreader.read(wkt);
        auto expected = wktreader.read(wktExpected);

        BoundaryOp op(*g, bnRule);
        auto boundary = op.getBoundary();

        ensure(boundary->equals(expected.get()));
    }

    void checkHasBoundary(const std::string& wkt)
    {
        checkHasBoundary(wkt, BoundaryNodeRule::getBoundaryRuleMod2(), true);
    }

    void checkHasBoundary(const std::string& wkt, bool expected)
    {
        checkHasBoundary(wkt, BoundaryNodeRule::getBoundaryRuleMod2(), expected);
    }

    void checkHasBoundary(const std::string& wkt, const BoundaryNodeRule& bnRule, bool expected)
    {
        auto g = wktreader.read(wkt);
        ensure_equals(expected, BoundaryOp::hasBoundary(*g, bnRule));
    }

};

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

group test_boundaryop_group("geos::operation::BoundaryOp");

// test1
template<>
template<>
void object::test<1>()
{
    std::string a = "MULTILINESTRING ((0 0, 10 10), (10 10, 20 20))";
    // under MultiValent, the common point is the only point on the boundary
    runBoundaryTest(a, BoundaryNodeRule::getBoundaryMultivalentEndPoint(),
            "POINT (10 10)"  );
}

// test2LinesTouchAtEndpoint2
template<>
template<>
void object::test<2>()
{
    std::string a = "MULTILINESTRING ((0 0, 10 10), (10 10, 20 20))";
    // under Mod-2, the common point is not on the boundary
    runBoundaryTest(a, BoundaryNodeRule::getBoundaryRuleMod2(),
            "MULTIPOINT ((0 0), (20 20))" );
    // under Endpoint, the common point is on the boundary
    runBoundaryTest(a, BoundaryNodeRule::getBoundaryEndPoint(),
            "MULTIPOINT ((0 0), (10 10), (20 20))"  );
    // under MonoValent, the common point is not on the boundary
    runBoundaryTest(a, BoundaryNodeRule::getBoundaryMonovalentEndPoint(),
            "MULTIPOINT ((0 0), (20 20))"  );
    // under MultiValent, the common point is the only point on the boundary
    runBoundaryTest(a, BoundaryNodeRule::getBoundaryMultivalentEndPoint(),
            "POINT (10 10)"  );
}

// test3LinesTouchAtEndpoint2
template<>
template<>
void object::test<3>()
{
    std::string a = "MULTILINESTRING ((0 0, 10 10), (10 10, 20 20), (10 10, 10 20))";
    // under Mod-2, the common point is on the boundary (3 mod 2 = 1)
    runBoundaryTest(a, BoundaryNodeRule::getBoundaryRuleMod2(),
            "MULTIPOINT ((0 0), (10 10), (10 20), (20 20))" );
    // under Endpoint, the common point is on the boundary (it is an endpoint)
    runBoundaryTest(a, BoundaryNodeRule::getBoundaryEndPoint(),
            "MULTIPOINT ((0 0), (10 10), (10 20), (20 20))"  );
    // under MonoValent, the common point is not on the boundary (it has valence > 1)
    runBoundaryTest(a, BoundaryNodeRule::getBoundaryMonovalentEndPoint(),
            "MULTIPOINT ((0 0), (10 20), (20 20))"  );
    // under MultiValent, the common point is the only point on the boundary
    runBoundaryTest(a, BoundaryNodeRule::getBoundaryMultivalentEndPoint(),
            "POINT (10 10)"  );
}

// testMultiLinestd::stringWithRingTouchAtEndpoint
template<>
template<>
void object::test<4>()
{
    std::string a = "MULTILINESTRING ((100 100, 20 20, 200 20, 100 100), (100 200, 100 100))";
    // under Mod-2, the ring has no boundary, so the line intersects the interior ==> not simple
    runBoundaryTest(a, BoundaryNodeRule::getBoundaryRuleMod2(),
            "MULTIPOINT ((100 100), (100 200))" );
    // under Endpoint, the ring has a boundary point, so the line does NOT intersect the interior ==> simple
    runBoundaryTest(a, BoundaryNodeRule::getBoundaryEndPoint(),
            "MULTIPOINT ((100 100), (100 200))"  );
}

// testRing
template<>
template<>
void object::test<5>()
{
    std::string a = "LINESTRING (100 100, 20 20, 200 20, 100 100)";
    // rings are simple under all rules
    runBoundaryTest(a, BoundaryNodeRule::getBoundaryRuleMod2(),
            "MULTIPOINT EMPTY");
    runBoundaryTest(a, BoundaryNodeRule::getBoundaryEndPoint(),
            "POINT (100 100)"  );
}

// testHasBoundaryPoint
template<>
template<>
void object::test<6>()
{
    checkHasBoundary( "POINT (0 0)", false);
}

// testHasBoundaryPointEmpty
template<>
template<>
void object::test<7>()
{
    checkHasBoundary( "POINT EMPTY", false);
}

// testHasBoundaryRingClosed
template<>
template<>
void object::test<8>()
{
    checkHasBoundary( "LINESTRING (100 100, 20 20, 200 20, 100 100)", false);
}

// testHasBoundaryMultiLinestd::stringClosed
template<>
template<>
void object::test<9>()
{
    checkHasBoundary( "MULTILINESTRING ((0 0, 0 1), (0 1, 1 1, 1 0, 0 0))", false);
}

// testHasBoundaryMultiLinestd::stringOpen
template<>
template<>
void object::test<10>()
{
    checkHasBoundary( "MULTILINESTRING ((0 0, 0 2), (0 1, 1 1, 1 0, 0 0))");
}

// testHasBoundaryPolygon
template<>
template<>
void object::test<11>()
{
    checkHasBoundary( "POLYGON ((1 9, 9 9, 9 1, 1 1, 1 9))");
}

// testHasBoundaryPolygonEmpty
template<>
template<>
void object::test<12>()
{
    checkHasBoundary( "POLYGON EMPTY", false);
}

}