File: GEOSPreparedDistanceWithinTest.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 (284 lines) | stat: -rw-r--r-- 4,996 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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
//
// Test Suite for C-API GEOSPreparedDistanceWithin

#include <tut/tut.hpp>
// geos
#include <geos_c.h>
#include <geos/constants.h>

#include "capi_test_utils.h"

namespace tut {
//
// Test Group
//

// Common data used in test cases.
struct test_capigeosprepareddistancewithin_data : public capitest::utility {
    const GEOSPreparedGeometry* pgeom1_;

    test_capigeosprepareddistancewithin_data()
        : pgeom1_(nullptr)
    {}

    ~test_capigeosprepareddistancewithin_data()
    {
        GEOSPreparedGeom_destroy(pgeom1_);
    }

    void checkDistanceWithin(const char* wkt1, const char* wkt2,
                       double dist, char expectedResult)
    {
        geom1_ = GEOSGeomFromWKT(wkt1);
        ensure(nullptr != geom1_);
        pgeom1_ = GEOSPrepare(geom1_);
        ensure(nullptr != pgeom1_);
        geom2_ = GEOSGeomFromWKT(wkt2);
        ensure(nullptr != geom2_);


        int ret = GEOSPreparedDistanceWithin(pgeom1_, geom2_, dist);
        ensure_equals("return code", (int)ret, (int)expectedResult);

    }


};

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

group test_capigeosprepareddistancewithin_group("capi::GEOSPreparedDistanceWithin");

//
// Test Cases
//

// Empty inputs
template<>
template<>
void object::test<1>
()
{
    checkDistanceWithin(
        "POLYGON EMPTY",
        "POLYGON EMPTY",
        geos::DoubleInfinity,
        0
    );
}

// Disjoint polygons
template<>
template<>
void object::test<2>
()
{
    checkDistanceWithin(
        "POLYGON((1 1,1 5,5 5,5 1,1 1))",
        "POLYGON((8 8, 9 9, 9 10, 8 8))",
        4.25,
        1
    );

}

// Point contained in polygon
template<>
template<>
void object::test<3>
()
{
    checkDistanceWithin(
        "POLYGON((1 1,1 5,5 5,5 1,1 1))",
        "POINT(2 2)",
        0,
        1
    );
}

// Disjoint line and point
template<>
template<>
void object::test<4>
()
{
    checkDistanceWithin(
        "LINESTRING(1 5,5 5,5 1,1 1)",
        "POINT(2 2)",
        1,
        1
    );
}

// Intersecting lines
template<>
template<>
void object::test<5>
()
{
    checkDistanceWithin(
        "LINESTRING(0 0,10 10)",
        "LINESTRING(0 10,10 0)",
        0,
        1
    );
}

// Intersecting polygon and line
template<>
template<>
void object::test<6>
()
{
    checkDistanceWithin(
        "POLYGON((0 0,10 0,10 10,0 10,0 0))",
        "LINESTRING(8 5,12 5)",
        0,
        1
    );
}

// Empty geometries
template<>
template<>
void object::test<7>
()
{
    checkDistanceWithin(
        "LINESTRING EMPTY",
        "POINT EMPTY",
        geos::DoubleInfinity,
        0
    );
}

// Empty geometries
template<>
template<>
void object::test<8>
()
{
    checkDistanceWithin(
        "POINT EMPTY",
        "LINESTRING EMPTY",
        geos::DoubleInfinity,
        0
    );
}

// Mixed empty and non-empty
template<>
template<>
void object::test<9>
()
{
    checkDistanceWithin(
        "POINT EMPTY",
        "POINT(0 0)",
        geos::DoubleInfinity,
        0
    );
}

// Mixed empty and non-empty
template<>
template<>
void object::test<10>
()
{
    checkDistanceWithin(
        "LINESTRING(0 0, 10 0)",
        "POLYGON EMPTY",
        geos::DoubleInfinity,
        0
    );
}

// Prepared geometry contained in test geometry
template<>
template<>
void object::test<11>
()
{
    checkDistanceWithin(
        "POLYGON((1 1,1 5,5 5,5 1,1 1))",
        "POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))",
        0,
        1
    );
}

// Prepared line within envelope of test line
// see https://github.com/libgeos/geos/issues/958
template<>
template<>
void object::test<12>
()
{
    checkDistanceWithin(
        "LINESTRING (2 2, 3 3, 4 4, 5 5, 6 6, 7 7)",
        "LINESTRING (0 0, 1 1, 2 2, 3 3, 4 4, 5 5, 6 6, 7 7, 8 8, 9 9)",
        1,
        1
    );
}

// Prepared line within test geometry
// see https://github.com/libgeos/geos/issues/960
template<>
template<>
void object::test<13>
()
{
    checkDistanceWithin(
        "LINESTRING (30 30, 70 70)",
        "POLYGON ((0 100, 100 100, 100 0, 0 0, 0 100))",
        1,
        1
    );
}

// Prepared multiline with one element within Polygon
template<>
template<>
void object::test<14>
()
{
    checkDistanceWithin(
        "MULTILINESTRING ((30 30, 70 70), (170 200, 200 170))",
        "POLYGON ((0 100, 100 100, 100 0, 0 0, 0 100))",
        1,
        1
    );
}

// Prepared multiline with one element within MultiPolygon.
template<>
template<>
void object::test<15>
()
{
    checkDistanceWithin(
        "MULTILINESTRING ((1 6, 1 1), (15 16, 15 14))",
        "MULTIPOLYGON (((10 20, 20 20, 20 10, 10 10, 10 20)), ((30 20, 40 20, 40 10, 30 10, 30 20)))",
        1,
        1
    );
}

// Indexed multiline with one element within line envelope.
template<>
template<>
void object::test<16>()
{
    checkDistanceWithin(
        "MULTILINESTRING ((1 6, 1 1), (11 14, 11 11))",
        "LINESTRING (10 10, 10 20, 30 20)",
        2,
        1
    );
}

} // namespace tut