Debian Codegraph @

unittest/gunit/gis_symdifference-t.cc

raw symbols SCIP
1 /*
2 Copyright (c) 2021, 2026, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is designed to work with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License, version 2.0, for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25
26 #include <gtest/gtest.h>
27 #include <memory> // unique_ptr
28 #include <ostream> // <<
29
30 #include "sql/dd/dd.h"
31 #include "sql/dd/impl/types/spatial_reference_system_impl.h"
32 #include "sql/dd/properties.h"
33 #include "sql/dd/types/spatial_reference_system.h"
34 #include "sql/gis/geometries.h"
35 #include "sql/gis/geometries_cs.h"
36 #include "sql/gis/relops.h"
37 #include "sql/gis/setops.h"
38 #include "template_utils.h" // down_cast
39 #include "unittest/gunit/gis_setops_testshapes.h"
40 #include "unittest/gunit/gis_test.h"
41 #include "unittest/gunit/gis_typeset.h"
42
43 #include <boost/geometry.hpp>
44
45 #ifdef GIS_SYMDIFFERENCE_TEST_DEBUG
46 namespace gis {
47 std::ostream &operator<<(std::ostream &os, const Geometry &geometry) {
48 if (geometry.coordinate_system() == Coordinate_system::kGeographic) {
49 switch (geometry.type()) {
50 case Geometry_type::kPoint: {
51 Geographic_point pt = *down_cast<const Geographic_point *>(&geometry);
52 return os << "POINT(" << pt.x() << "," << pt.y() << ")";
53 }
54 case Geometry_type::kLinestring: {
55 Geographic_linestring ls =
56 *down_cast<const Geographic_linestring *>(&geometry);
57 os << "LINESTRING: ";
58 for (auto pt : ls) {
59 os << pt;
60 }
61 return os;
62 }
63 case Geometry_type::kPolygon: {
64 Geographic_polygon py =
65 *down_cast<const Geographic_polygon *>(&geometry);
66 Geographic_linearring lr = py.geographic_exterior_ring();
67 os << "POLYGON: ";
68 for (auto pt : lr) {
69 os << pt;
70 }
71 return os;
72 }
73 case Geometry_type::kMultipoint: {
74 Geographic_multipoint g =
75 *down_cast<const Geographic_multipoint *>(&geometry);
76 os << "MULTIPOINT: ";
77 for (size_t i = 0; i < g.size(); i++) {
78 os << g[i] << " ";
79 }
80 return os;
81 }
82 case Geometry_type::kMultilinestring: {
83 Geographic_multilinestring g =
84 *down_cast<const Geographic_multilinestring *>(&geometry);
85 os << "MULTILINESTRING: ";
86 for (size_t i = 0; i < g.size(); i++) {
87 os << g[i] << " ";
88 }
89 return os;
90 }
91 case Geometry_type::kMultipolygon: {
92 Geographic_multipolygon g =
93 *down_cast<const Geographic_multipolygon *>(&geometry);
94 os << "MULTIPOLYGON: ";
95 for (size_t i = 0; i < g.size(); i++) {
96 os << g[i] << " ";
97 }
98 return os;
99 }
100 case Geometry_type::kGeometrycollection: {
101 Geographic_geometrycollection g =
102 *down_cast<const Geographic_geometrycollection *>(&geometry);
103 os << "GEOMCOL: ";
104 for (size_t i = 0; i < g.size(); i++) {
105 os << g[i] << " ";
106 }
107 return os;
108 }
109 case Geometry_type::kGeometry:
110 break;
111 }
112 } else if (geometry.coordinate_system() == Coordinate_system::kCartesian) {
113 switch (geometry.type()) {
114 case Geometry_type::kPoint: {
115 Cartesian_point pt = *down_cast<const Cartesian_point *>(&geometry);
116 return os << "POINT(" << pt.x() << "," << pt.y() << ")";
117 }
118 case Geometry_type::kLinestring: {
119 Cartesian_linestring ls =
120 *down_cast<const Cartesian_linestring *>(&geometry);
121 os << "LINESTRING: ";
122 for (auto pt : ls) {
123 os << pt;
124 }
125 return os;
126 }
127 case Geometry_type::kPolygon: {
128 Cartesian_polygon py = *down_cast<const Cartesian_polygon *>(&geometry);
129 Cartesian_linearring lr = py.cartesian_exterior_ring();
130 os << "POLYGON: ";
131 for (auto pt : lr) {
132 os << pt;
133 }
134 return os;
135 }
136 case Geometry_type::kMultipoint: {
137 Cartesian_multipoint g =
138 *down_cast<const Cartesian_multipoint *>(&geometry);
139 os << "MULTIPOINT: ";
140 for (size_t i = 0; i < g.size(); i++) {
141 os << g[i] << " ";
142 }
143 return os;
144 }
145 case Geometry_type::kMultilinestring: {
146 Cartesian_multilinestring g =
147 *down_cast<const Cartesian_multilinestring *>(&geometry);
148 os << "MULTILINESTRING: ";
149 for (size_t i = 0; i < g.size(); i++) {
150 os << g[i] << " ";
151 }
152 return os;
153 }
154 case Geometry_type::kMultipolygon: {
155 Cartesian_multipolygon g =
156 *down_cast<const Cartesian_multipolygon *>(&geometry);
157 os << "MULTIPOLYGON: ";
158 for (size_t i = 0; i < g.size(); i++) {
159 os << g[i] << " ";
160 }
161 return os;
162 }
163 case Geometry_type::kGeometrycollection: {
164 Cartesian_geometrycollection g =
165 *down_cast<const Cartesian_geometrycollection *>(&geometry);
166 os << "GEOMCOL: ";
167 for (size_t i = 0; i < g.size(); i++) {
168 os << g[i] << " ";
169 }
170 return os;
171 }
172 case Geometry_type::kGeometry:
173 break;
174 }
175 }
176 return os << "Hello " << type_to_name(geometry.type());
177 }
178 } // namespace gis
179 #endif
180
181 namespace gis_symdifference_unittest {
182
183 template <typename Types>
184 struct SymDifferenceTest : Gis_test<Types> {
185 void test_valid_input_both_orders(
186 const gis::Geometry &g1, const gis::Geometry &g2,
187 const gis::Geometry &expected_result) const {
188 std::unique_ptr<gis::Geometry> result;
189 bool is_null = false;
190 bool error =
191 gis::symdifference(this->m_srs.get(), &g1, &g2, "unittest", &result);
192 EXPECT_FALSE(error);
193
194 #ifdef GIS_SYMDIFFERENCE_TEST_DEBUG
195 std::cout << "g1 :" << g1 << std::endl;
196 std::cout << "g2 :" << g2 << std::endl;
197 std::cout << "Exp:" << expected_result << std::endl;
198 std::cout << "Res:" << *result << std::endl;
199 #endif
200
201 // Verify geometry return type.
202 const std::string type_res(gis::type_to_name(result->type()));
203 const std::string type_exp(gis::type_to_name(expected_result.type()));
204 EXPECT_EQ(type_exp, type_res);
205
206 // Verify result is correct.
207 bool is_equals = false;
208 bool equals_error =
209 gis::equals(this->m_srs.get(), &expected_result, result.get(),
210 "unittest", &is_equals, &is_null);
211 EXPECT_FALSE(equals_error);
212 EXPECT_FALSE(is_null);
213 EXPECT_TRUE(is_equals);
214 }
215
216 void test_valid_input(const gis::Geometry &g1, const gis::Geometry &g2,
217 const gis::Geometry &expected_result) const {
218 test_valid_input_both_orders(g1, g2, expected_result);
219 test_valid_input_both_orders(g2, g1, expected_result);
220 }
221 };
222
223 // The purpose of these tests is to check that the result returned from
224 // gis::symdifference is correct. The tests test all combinations of geometries.
225 // TYPED_TEST_SUITE(SymDifferenceTest, gis_typeset::Cartesian);
226 TYPED_TEST_SUITE(SymDifferenceTest, gis_typeset::Test_both);
227
228 // symdifference(... ,point, *, ...)
229
230 TYPED_TEST(SymDifferenceTest, PointPoint) {
231 typename TypeParam::Point pt1{0, 0};
232 typename TypeParam::Point pt2{0, 0.1};
233 typename TypeParam::Multipoint expected_result{};
234 typename TypeParam::Geometrycollection empty_result{};
235
236 expected_result.push_back(pt1);
237 expected_result.push_back(pt2);
238
239 this->test_valid_input(pt1, pt1, empty_result);
240 this->test_valid_input(pt1, pt2, expected_result);
241 }
242
243 TYPED_TEST(SymDifferenceTest, PointLinestring) {
244 typename TypeParam::Point pt1{0, 0};
245 typename TypeParam::Point pt2{0.1, 0.1};
246 typename TypeParam::Linestring ls = simple_ls<TypeParam>();
247 typename TypeParam::Geometrycollection result{};
248
249 this->test_valid_input(pt1, ls, ls);
250
251 result.push_back(pt2);
252 result.push_back(ls);
253 this->test_valid_input(pt2, ls, result);
254 }
255
256 TYPED_TEST(SymDifferenceTest, PointPolygon) {
257 typename TypeParam::Point pt1{0.05, 0.05};
258 typename TypeParam::Point pt2{0.1, 0.2};
259 typename TypeParam::Polygon py = base_py<TypeParam>();
260 typename TypeParam::Geometrycollection result{};
261
262 this->test_valid_input(pt1, py, py);
263
264 result.push_back(pt2);
265 result.push_back(py);
266 this->test_valid_input(pt2, py, result);
267 }
268
269 TYPED_TEST(SymDifferenceTest, PointMultiPoint) {
270 typename TypeParam::Point pt1{0, 0};
271 typename TypeParam::Point pt2{0, 0.1};
272 typename TypeParam::Point pt3{0.1, 0.1};
273 typename TypeParam::Multipoint mpt{};
274 typename TypeParam::Multipoint expected_result{};
275 typename TypeParam::Geometrycollection empty_result{};
276
277 // intersect
278 mpt.push_back(pt1);
279 mpt.push_back(pt2);
280 mpt.push_back(pt3);
281 expected_result.push_back(pt2);
282 expected_result.push_back(pt3);
283
284 this->test_valid_input(pt1, mpt, expected_result);
285
286 mpt.clear();
287 expected_result.clear();
288
289 // disjoint
290 mpt.push_back(pt2);
291 mpt.push_back(pt3);
292 expected_result.push_back(pt1);
293 expected_result.push_back(pt2);
294 expected_result.push_back(pt3);
295
296 this->test_valid_input(pt1, mpt, expected_result);
297
298 mpt.clear();
299 expected_result.clear();
300
301 // equals
302 mpt.push_back(pt1);
303
304 this->test_valid_input(pt1, mpt, empty_result);
305 }
306
307 TYPED_TEST(SymDifferenceTest, PointMultiLinestring) {
308 typename TypeParam::Point pt1{0, 0};
309 typename TypeParam::Point pt2{0.1, 0.1};
310 typename TypeParam::Point pt3{0.05, 0.05};
311 typename TypeParam::Linestring ls1 = simple_ls<TypeParam>();
312 typename TypeParam::Linestring ls2 = simple_ls_2<TypeParam>();
313 typename TypeParam::Multilinestring mls;
314 mls.push_back(ls1);
315 mls.push_back(ls2);
316
317 this->test_valid_input(pt1, mls, mls);
318 this->test_valid_input(pt2, mls, mls);
319
320 typename TypeParam::Geometrycollection result{};
321 result.push_back(mls);
322 result.push_back(pt3);
323 this->test_valid_input(pt3, mls, result);
324 }
325
326 TYPED_TEST(SymDifferenceTest, PointMultiPolygon) {
327 typename TypeParam::Point pt1{0.05, 0.05};
328 typename TypeParam::Point pt2{0.1, 0.2};
329 typename TypeParam::Polygon py = base_py<TypeParam>();
330 typename TypeParam::Multipolygon mpy = simple_mpy<TypeParam>();
331 typename TypeParam::Geometrycollection result{};
332
333 this->test_valid_input(pt1, mpy, py);
334
335 result.push_back(pt2);
336 result.push_back(mpy);
337 this->test_valid_input(pt2, mpy, result);
338 }
339
340 TYPED_TEST(SymDifferenceTest, PointGeometryCollection) {
341 typename TypeParam::Point pt1{0.05, 0.05};
342 typename TypeParam::Point pt2{0.1, 0.2};
343 typename TypeParam::Point pt3{0.2, 0.0};
344 typename TypeParam::Point pt4{0.2, 0.1};
345 typename TypeParam::Linestring ls1;
346 ls1.push_back(pt3);
347 ls1.push_back(pt4);
348 typename TypeParam::Multipolygon mpy = simple_mpy<TypeParam>();
349 typename TypeParam::Geometrycollection gc{};
350
351 this->test_valid_input(pt1, gc, pt1);
352
353 gc.push_back(pt1);
354 gc.push_back(ls1);
355 gc.push_back(mpy);
356
357 typename TypeParam::Geometrycollection result{};
358
359 this->test_valid_input(pt1, gc, gc);
360
361 result.push_back(pt2);
362 result.push_back(gc);
363 this->test_valid_input(pt2, gc, result);
364
365 typename TypeParam::Geometrycollection gc2{};
366 gc2.push_back(mpy);
367 gc2.push_back(ls1);
368 this->test_valid_input(pt1, gc2, gc);
369 }
370
371 // symdifference(... , linestring, *, ...)
372
373 TYPED_TEST(SymDifferenceTest, LinestringLinestring) {
374 typename TypeParam::Linestring ls1 = simple_ls<TypeParam>();
375 typename TypeParam::Linestring ls2 = offset_simple_ls<TypeParam>();
376 typename TypeParam::Point pt1{0.0, 0.0};
377 typename TypeParam::Point pt2{0.05, 0.0};
378 typename TypeParam::Point pt3{0.1, 0.0};
379 typename TypeParam::Point pt4{0.15, 0.0};
380 typename TypeParam::Linestring ls1_result;
381 ls1_result.push_back(pt1);
382 ls1_result.push_back(pt2);
383 typename TypeParam::Linestring ls2_result;
384 ls2_result.push_back(pt3);
385 ls2_result.push_back(pt4);
386 typename TypeParam::Multilinestring mls_result;
387 mls_result.push_back(ls1_result);
388 mls_result.push_back(ls2_result);
389
390 typename TypeParam::Geometrycollection empty_result{};
391
392 this->test_valid_input(ls1, ls1, empty_result);
393 this->test_valid_input(ls1, ls2, mls_result);
394 }
395
396 TYPED_TEST(SymDifferenceTest, LinestringPolygon) {
397 // TODO: needs intersection point for geographic CS
398 // for a robust test
399 // typename TypeParam::Point pt1{0.05, 0.05};
400 typename TypeParam::Point pt1{0.1, 0.05};
401 typename TypeParam::Point pt2{0.1, 0.05};
402 ;
403 typename TypeParam::Point pt3{0.15, 0.05};
404
405 typename TypeParam::Linestring ls;
406 ls.push_back(pt1);
407 ls.push_back(pt3);
408 typename TypeParam::Linestring ls_result;
409 ls_result.push_back(pt2);
410 ls_result.push_back(pt3);
411 typename TypeParam::Polygon py = base_py<TypeParam>();
412
413 typename TypeParam::Geometrycollection result{};
414 result.push_back(py);
415 result.push_back(ls_result);
416
417 this->test_valid_input(ls, py, result);
418 }
419
420 TYPED_TEST(SymDifferenceTest, LinestringMultiPoint) {
421 typename TypeParam::Linestring ls = simple_ls<TypeParam>();
422 typename TypeParam::Point pt1{0.0, 0.0};
423 typename TypeParam::Point pt2{0.05, 0.0};
424 typename TypeParam::Point pt3{0.15, 0.05};
425 typename TypeParam::Multipoint mp;
426 mp.push_back(pt1);
427 mp.push_back(pt2);
428 mp.push_back(pt3);
429
430 typename TypeParam::Geometrycollection result{};
431 result.push_back(ls);
432 result.push_back(pt3);
433
434 this->test_valid_input(ls, mp, result);
435 }
436
437 TYPED_TEST(SymDifferenceTest, LinestringMultiLinestring) {
438 typename TypeParam::Linestring ls1 = simple_ls<TypeParam>();
439 typename TypeParam::Linestring ls2 = offset_simple_ls<TypeParam>();
440 typename TypeParam::Point pt1{0.0, 0.0};
441 typename TypeParam::Point pt2{0.05, 0.0};
442 typename TypeParam::Point pt3{0.1, 0.0};
443 typename TypeParam::Point pt4{0.15, 0.0};
444 typename TypeParam::Linestring ls1_result;
445 ls1_result.push_back(pt1);
446 ls1_result.push_back(pt2);
447 typename TypeParam::Linestring ls2_result;
448 ls2_result.push_back(pt3);
449 ls2_result.push_back(pt4);
450 typename TypeParam::Multilinestring mls_result;
451 mls_result.push_back(ls1_result);
452 mls_result.push_back(ls2_result);
453
454 typename TypeParam::Multilinestring mls{};
455 this->test_valid_input(ls1, mls, ls1);
456 mls.push_back(ls2);
457 this->test_valid_input(ls1, mls, mls_result);
458 }
459
460 TYPED_TEST(SymDifferenceTest, LinestringMultiPolygon) {
461 // TODO: needs intersection point for geographic CS
462 // for a robust test
463 // typename TypeParam::Point pt1{0.05, 0.05};
464 typename TypeParam::Point pt1{0.1, 0.05};
465 typename TypeParam::Point pt2{0.1, 0.05};
466 typename TypeParam::Point pt3{0.15, 0.05};
467 typename TypeParam::Linestring ls;
468 ls.push_back(pt1);
469 ls.push_back(pt3);
470 typename TypeParam::Linestring ls_result;
471 ls_result.push_back(pt2);
472 ls_result.push_back(pt3);
473 typename TypeParam::Multipolygon mpy = simple_mpy<TypeParam>();
474
475 typename TypeParam::Geometrycollection result{};
476 result.push_back(mpy);
477 result.push_back(ls_result);
478
479 this->test_valid_input(ls, mpy, result);
480 }
481
482 TYPED_TEST(SymDifferenceTest, LinestringGeometryCollection) {
483 typename TypeParam::Point pt1{0.05, 0.05};
484 typename TypeParam::Point pt2{0.1, 0.2};
485 typename TypeParam::Point pt3{0.2, 0.0};
486 typename TypeParam::Point pt4{0.2, 0.1};
487 typename TypeParam::Linestring ls1;
488 ls1.push_back(pt3);
489 ls1.push_back(pt4);
490 typename TypeParam::Multipolygon mpy = simple_mpy<TypeParam>();
491 typename TypeParam::Geometrycollection gc{};
492 this->test_valid_input(ls1, gc, ls1);
493 gc.push_back(pt1);
494 gc.push_back(ls1);
495 gc.push_back(mpy);
496
497 this->test_valid_input(ls1, gc, base_py<TypeParam>());
498
499 typename TypeParam::Linestring ls_intersect_py;
500 ls_intersect_py.push_back(pt2);
501 typename TypeParam::Point pt5{0.1, 0.0};
502 ls_intersect_py.push_back(pt5);
503 typename TypeParam::Geometrycollection result{};
504 result.push_back(mpy);
505 result.push_back(ls1);
506 typename TypeParam::Linestring ls_result;
507 ls_result.push_back(pt2);
508 typename TypeParam::Point pt6{0.1, 0.1};
509 ls_result.push_back(pt6);
510 result.push_back(ls_result);
511 this->test_valid_input(ls_intersect_py, gc, result);
512
513 typename TypeParam::Linestring ls2;
514 ls2.push_back(pt3);
515 ls2.push_back(pt4);
516 ls2.push_back(pt2);
517 typename TypeParam::Linestring ls_result2;
518 ls_result2.push_back(pt2);
519 ls_result2.push_back(pt4);
520
521 // using clear() here create memory leaks
522 // e.g.
523 // result.clear();
524 // result.push_back(ls_result2);
525 // result.push_back(mpy);
526 // this->test_valid_input(ls2, gc, result);
527
528 typename TypeParam::Geometrycollection result2;
529 result2.push_back(ls_result2);
530 result2.push_back(mpy);
531 this->test_valid_input(ls2, gc, result2);
532 }
533
534 // symdifference(... , polygon, *, ...)
535
536 TYPED_TEST(SymDifferenceTest, PolygonPolygon) {
537 typename TypeParam::Point pt1{0.0, 0.0};
538 typename TypeParam::Point pt2{0.1, 0.0};
539 typename TypeParam::Point pt3{0.0, 0.1};
540 typename TypeParam::Point pt4{0.1, 0.1};
541 typename TypeParam::Point pt5{0.1, 0.2};
542 typename TypeParam::Polygon py1 = base_py<TypeParam>();
543 typename TypeParam::Polygon py2;
544 typename TypeParam::Linearring exterior2;
545 exterior2.push_back(pt2);
546 exterior2.push_back(pt5);
547 exterior2.push_back(pt3);
548 exterior2.push_back(pt2);
549 py2.push_back(exterior2);
550
551 typename TypeParam::Multipolygon mpy_result;
552 typename TypeParam::Polygon py1_result;
553 typename TypeParam::Linearring exterior1r;
554 typename TypeParam::Polygon py2_result;
555 typename TypeParam::Linearring exterior2r;
556 exterior1r.push_back(pt1);
557 exterior1r.push_back(pt2);
558 exterior1r.push_back(pt3);
559 exterior1r.push_back(pt1);
560 py1_result.push_back(exterior1r);
561 mpy_result.push_back(py1_result);
562 exterior2r.push_back(pt3);
563 exterior2r.push_back(pt4);
564 exterior2r.push_back(pt5);
565 exterior2r.push_back(pt3);
566 py2_result.push_back(exterior2r);
567 mpy_result.push_back(py2_result);
568 typename TypeParam::Geometrycollection empty_result{};
569
570 this->test_valid_input(py1, py1, empty_result);
571 this->test_valid_input(py1, py2, mpy_result);
572 }
573
574 TYPED_TEST(SymDifferenceTest, PolygonMultiPoint) {
575 typename TypeParam::Point pt1{0.05, 0.05};
576 typename TypeParam::Point pt2{0.1, 0.2};
577 typename TypeParam::Multipoint mp;
578 mp.push_back(pt1);
579 mp.push_back(pt2);
580 typename TypeParam::Polygon py = base_py<TypeParam>();
581 typename TypeParam::Geometrycollection result{};
582 result.push_back(pt2);
583 result.push_back(py);
584
585 this->test_valid_input(py, mp, result);
586 }
587
588 TYPED_TEST(SymDifferenceTest, PolygonMultiLinestring) {
589 // TODO: needs intersection point for geographic CS
590 // for a robust test
591 // typename TypeParam::Point pt1{0.05, 0.05};
592 typename TypeParam::Point pt1{0.1, 0.05};
593 typename TypeParam::Point pt2{0.1, 0.05};
594 typename TypeParam::Point pt3{0.15, 0.05};
595 typename TypeParam::Linestring ls;
596 ls.push_back(pt1);
597 ls.push_back(pt3);
598 typename TypeParam::Multilinestring mls;
599 mls.push_back(ls);
600 typename TypeParam::Polygon py = base_py<TypeParam>();
601
602 typename TypeParam::Linestring ls_result;
603 ls_result.push_back(pt2);
604 ls_result.push_back(pt3);
605 typename TypeParam::Geometrycollection result{};
606 result.push_back(py);
607 result.push_back(ls_result);
608
609 this->test_valid_input(py, mls, result);
610 }
611
612 TYPED_TEST(SymDifferenceTest, PolygonMultiPolygon) {
613 typename TypeParam::Point pt1{0.0, 0.0};
614 typename TypeParam::Point pt2{0.1, 0.0};
615 typename TypeParam::Point pt3{0.0, 0.1};
616 typename TypeParam::Point pt4{0.1, 0.1};
617 typename TypeParam::Point pt5{0.1, 0.2};
618 typename TypeParam::Polygon py1 = base_py<TypeParam>();
619 typename TypeParam::Polygon py2;
620 typename TypeParam::Linearring exterior2;
621 exterior2.push_back(pt2);
622 exterior2.push_back(pt5);
623 exterior2.push_back(pt3);
624 exterior2.push_back(pt2);
625 py2.push_back(exterior2);
626 typename TypeParam::Multipolygon mpy;
627 mpy.push_back(py2);
628
629 typename TypeParam::Multipolygon mpy_result;
630 typename TypeParam::Polygon py1_result;
631 typename TypeParam::Linearring exterior1r;
632 typename TypeParam::Polygon py2_result;
633 typename TypeParam::Linearring exterior2r;
634 exterior1r.push_back(pt1);
635 exterior1r.push_back(pt2);
636 exterior1r.push_back(pt3);
637 exterior1r.push_back(pt1);
638 py1_result.push_back(exterior1r);
639 mpy_result.push_back(py1_result);
640 exterior2r.push_back(pt3);
641 exterior2r.push_back(pt4);
642 exterior2r.push_back(pt5);
643 exterior2r.push_back(pt3);
644 py2_result.push_back(exterior2r);
645 mpy_result.push_back(py2_result);
646
647 this->test_valid_input(py1, mpy, mpy_result);
648
649 typename TypeParam::Multipolygon mpy2 = simple_mpy<TypeParam>();
650 typename TypeParam::Geometrycollection empty_result{};
651 this->test_valid_input(py1, mpy2, empty_result);
652 }
653
654 TYPED_TEST(SymDifferenceTest, PolygonGeometryCollection) {
655 typename TypeParam::Point pt1{0.05, 0.05};
656 typename TypeParam::Point pt2{0.1, 0.2};
657 typename TypeParam::Point pt3{0.2, 0.0};
658 typename TypeParam::Point pt4{0.2, 0.1};
659 typename TypeParam::Linestring ls1;
660 ls1.push_back(pt3);
661 ls1.push_back(pt4);
662 // typename TypeParam::Multipolygon mpy = simple_mpy<TypeParam>();
663 typename TypeParam::Polygon py = base_py<TypeParam>();
664 typename TypeParam::Geometrycollection gc{};
665 this->test_valid_input(py, gc, py);
666 gc.push_back(pt3);
667 gc.push_back(ls1);
668 gc.push_back(py);
669 this->test_valid_input(py, gc, ls1);
670
671 typename TypeParam::Linestring ls2;
672 ls2.push_back(pt3);
673 ls2.push_back(pt4);
674 ls2.push_back(pt2);
675 typename TypeParam::Linestring ls3;
676 ls3.push_back(pt1);
677 ls3.push_back(pt2);
678 gc.push_back(ls2);
679 gc.push_back(ls3);
680 typename TypeParam::Multilinestring result{};
681 typename TypeParam::Linestring ls_result;
682 ls_result.push_back(pt2);
683 ls_result.push_back(typename TypeParam::Point(0.0666667, 0.1));
684 result.push_back(ls_result);
685 result.push_back(ls1);
686 result.push_back(ls2);
687 this->test_valid_input(py, gc, result);
688 }
689
690 // symdifference(... , multipoint, *, ...)
691
692 TYPED_TEST(SymDifferenceTest, MultiPointMultiPoint) {
693 typename TypeParam::Point pt1{0, 0};
694 typename TypeParam::Point pt2{0, 0.1};
695 typename TypeParam::Point pt3{0.1, 0.1};
696 typename TypeParam::Multipoint mpt1{};
697 mpt1.push_back(pt1);
698 typename TypeParam::Multipoint mpt2{};
699 typename TypeParam::Multipoint expected_result{};
700 typename TypeParam::Geometrycollection empty_result{};
701
702 // intersect
703 mpt2.push_back(pt1);
704 mpt2.push_back(pt2);
705 mpt2.push_back(pt3);
706 expected_result.push_back(pt2);
707 expected_result.push_back(pt3);
708
709 this->test_valid_input(mpt1, mpt2, expected_result);
710
711 mpt2.clear();
712 expected_result.clear();
713
714 // disjoint
715 mpt2.push_back(pt2);
716 mpt2.push_back(pt3);
717 expected_result.push_back(pt1);
718 expected_result.push_back(pt2);
719 expected_result.push_back(pt3);
720
721 this->test_valid_input(mpt1, mpt2, expected_result);
722
723 mpt2.clear();
724 expected_result.clear();
725
726 // equals
727 mpt2.push_back(pt1);
728
729 this->test_valid_input(mpt1, mpt2, empty_result);
730 }
731
732 TYPED_TEST(SymDifferenceTest, MultiPointMultiLinestring) {
733 typename TypeParam::Point pt1{0, 0};
734 typename TypeParam::Point pt2{0.1, 0.1};
735 typename TypeParam::Point pt3{0.05, 0.05};
736 typename TypeParam::Multipoint mpt1;
737 mpt1.push_back(pt1);
738 typename TypeParam::Multipoint mpt2;
739 mpt2.push_back(pt1);
740 mpt2.push_back(pt2);
741 typename TypeParam::Multipoint mpt3;
742 mpt3.push_back(pt1);
743 mpt3.push_back(pt2);
744 mpt3.push_back(pt3);
745 typename TypeParam::Linestring ls1 = simple_ls<TypeParam>();
746 typename TypeParam::Linestring ls2 = simple_ls_2<TypeParam>();
747 typename TypeParam::Multilinestring mls;
748 mls.push_back(ls1);
749 mls.push_back(ls2);
750
751 this->test_valid_input(mpt1, mls, mls);
752 this->test_valid_input(mpt2, mls, mls);
753
754 typename TypeParam::Geometrycollection result{};
755 result.push_back(mls);
756 result.push_back(pt3);
757 this->test_valid_input(mpt3, mls, result);
758 }
759
760 TYPED_TEST(SymDifferenceTest, MultiPointMultiPolygon) {
761 typename TypeParam::Point pt1{0.05, 0.05};
762 typename TypeParam::Point pt2{0.1, 0.2};
763 typename TypeParam::Multipoint mpt1;
764 mpt1.push_back(pt1);
765 typename TypeParam::Multipoint mpt2;
766 mpt2.push_back(pt1);
767 mpt2.push_back(pt2);
768 typename TypeParam::Polygon py = base_py<TypeParam>();
769 typename TypeParam::Multipolygon mpy = simple_mpy<TypeParam>();
770 typename TypeParam::Geometrycollection result{};
771
772 this->test_valid_input(mpt1, mpy, py);
773
774 result.push_back(pt2);
775 result.push_back(mpy);
776 this->test_valid_input(mpt2, mpy, result);
777 }
778
779 TYPED_TEST(SymDifferenceTest, MultiPointGeometryCollection) {
780 typename TypeParam::Point pt1{0.05, 0.05};
781 typename TypeParam::Point pt2{0.1, 0.2};
782 typename TypeParam::Point pt3{0.2, 0.0};
783 typename TypeParam::Point pt4{0.2, 0.1};
784 typename TypeParam::Point pt5{0.3, 0.0};
785 typename TypeParam::Point pt6{0.3, 0.1};
786 typename TypeParam::Linestring ls1;
787 ls1.push_back(pt3);
788 ls1.push_back(pt4);
789 typename TypeParam::Multipolygon mpy = simple_mpy<TypeParam>();
790 typename TypeParam::Geometrycollection gc{};
791 gc.push_back(pt2);
792 gc.push_back(pt3);
793 gc.push_back(pt4);
794 gc.push_back(pt5);
795 gc.push_back(ls1);
796 gc.push_back(mpy);
797
798 typename TypeParam::Multipoint mp;
799 mp.push_back(pt1);
800 mp.push_back(pt2);
801 mp.push_back(pt3);
802 mp.push_back(pt6);
803 this->test_valid_input(mp, typename TypeParam::Geometrycollection(), mp);
804
805 typename TypeParam::Geometrycollection result{};
806 result.push_back(mpy);
807 result.push_back(ls1);
808 result.push_back(pt5);
809 result.push_back(pt6);
810
811 this->test_valid_input(mp, gc, result);
812 }
813
814 // symdifference(... , multilinestring, *, ...)
815
816 TYPED_TEST(SymDifferenceTest, MultiLinestringMultiLinestring) {
817 typename TypeParam::Linestring ls1 = simple_ls<TypeParam>();
818 typename TypeParam::Linestring ls2 = offset_simple_ls<TypeParam>();
819 typename TypeParam::Point pt1{0.0, 0.0};
820 typename TypeParam::Point pt2{0.05, 0.0};
821 typename TypeParam::Point pt3{0.1, 0.0};
822 typename TypeParam::Point pt4{0.15, 0.0};
823 typename TypeParam::Multilinestring mls1;
824 mls1.push_back(ls1);
825 typename TypeParam::Linestring ls1_result;
826 ls1_result.push_back(pt1);
827 ls1_result.push_back(pt2);
828 typename TypeParam::Linestring ls2_result;
829 ls2_result.push_back(pt3);
830 ls2_result.push_back(pt4);
831 typename TypeParam::Multilinestring mls_result;
832 mls_result.push_back(ls1_result);
833 mls_result.push_back(ls2_result);
834
835 typename TypeParam::Multilinestring mls{};
836 this->test_valid_input(mls1, mls, ls1);
837 mls.push_back(ls2);
838 this->test_valid_input(mls1, mls, mls_result);
839 }
840
841 TYPED_TEST(SymDifferenceTest, MultiLinestringMultiPolygon) {
842 // TODO: needs intersection point for geographic CS
843 // for a robust test
844 // typename TypeParam::Point pt1{0.05, 0.05};
845 typename TypeParam::Point pt1{0.1, 0.05};
846 typename TypeParam::Point pt2{0.1, 0.05};
847 typename TypeParam::Point pt3{0.15, 0.05};
848 typename TypeParam::Linestring ls;
849 ls.push_back(pt1);
850 ls.push_back(pt3);
851 typename TypeParam::Multilinestring mls;
852 mls.push_back(ls);
853 typename TypeParam::Linestring ls_result;
854 ls_result.push_back(pt2);
855 ls_result.push_back(pt3);
856 typename TypeParam::Multipolygon mpy = simple_mpy<TypeParam>();
857
858 typename TypeParam::Geometrycollection result{};
859 result.push_back(mpy);
860 result.push_back(ls_result);
861
862 this->test_valid_input(mls, mpy, result);
863 }
864
865 TYPED_TEST(SymDifferenceTest, MultiLinestringGeometryCollection) {
866 typename TypeParam::Point pt1{0.05, 0.05};
867 typename TypeParam::Point pt2{0.1, 0.2};
868 typename TypeParam::Point pt3{0.2, 0.0};
869 typename TypeParam::Point pt4{0.2, 0.1};
870 typename TypeParam::Linestring ls1;
871 ls1.push_back(pt3);
872 ls1.push_back(pt4);
873 typename TypeParam::Multipolygon mpy = simple_mpy<TypeParam>();
874 typename TypeParam::Geometrycollection gc{};
875 this->test_valid_input(ls1, gc, ls1);
876 gc.push_back(pt1);
877 gc.push_back(ls1);
878 gc.push_back(mpy);
879
880 typename TypeParam::Multilinestring mls;
881 mls.push_back(ls1);
882 this->test_valid_input(mls, gc, base_py<TypeParam>());
883
884 typename TypeParam::Linestring ls_intersect_py;
885 ls_intersect_py.push_back(pt2);
886 typename TypeParam::Point pt5{0.1, 0.0};
887 ls_intersect_py.push_back(pt5);
888 typename TypeParam::Geometrycollection result{};
889 result.push_back(mpy);
890 result.push_back(ls1);
891 typename TypeParam::Linestring ls_result;
892 ls_result.push_back(pt2);
893 typename TypeParam::Point pt6{0.1, 0.1};
894 ls_result.push_back(pt6);
895 result.push_back(ls_result);
896 mls.clear();
897 mls.push_back(ls_intersect_py);
898 this->test_valid_input(mls, gc, result);
899
900 typename TypeParam::Linestring ls2;
901 ls2.push_back(pt3);
902 ls2.push_back(pt4);
903 ls2.push_back(pt2);
904 typename TypeParam::Linestring ls_result2;
905 ls_result2.push_back(pt2);
906 ls_result2.push_back(pt4);
907
908 typename TypeParam::Geometrycollection result2;
909 result2.push_back(ls_result2);
910 result2.push_back(mpy);
911 mls.clear();
912 mls.push_back(ls2);
913 this->test_valid_input(mls, gc, result2);
914 }
915
916 // symdifference(... , multipolygon, *, ...)
917
918 TYPED_TEST(SymDifferenceTest, MultiPolygonMultiPolygon) {
919 typename TypeParam::Point pt1{0.0, 0.0};
920 typename TypeParam::Point pt2{0.1, 0.0};
921 typename TypeParam::Point pt3{0.0, 0.1};
922 typename TypeParam::Point pt4{0.1, 0.1};
923 typename TypeParam::Point pt5{0.1, 0.2};
924 typename TypeParam::Multipolygon mpy1 = simple_mpy<TypeParam>();
925 typename TypeParam::Polygon py2;
926 typename TypeParam::Linearring exterior2;
927 exterior2.push_back(pt2);
928 exterior2.push_back(pt5);
929 exterior2.push_back(pt3);
930 exterior2.push_back(pt2);
931 py2.push_back(exterior2);
932 typename TypeParam::Multipolygon mpy2;
933 mpy2.push_back(py2);
934
935 typename TypeParam::Multipolygon mpy_result;
936 typename TypeParam::Polygon py1_result;
937 typename TypeParam::Linearring exterior1r;
938 typename TypeParam::Polygon py2_result;
939 typename TypeParam::Linearring exterior2r;
940 exterior1r.push_back(pt1);
941 exterior1r.push_back(pt2);
942 exterior1r.push_back(pt3);
943 exterior1r.push_back(pt1);
944 py1_result.push_back(exterior1r);
945 mpy_result.push_back(py1_result);
946 exterior2r.push_back(pt3);
947 exterior2r.push_back(pt4);
948 exterior2r.push_back(pt5);
949 exterior2r.push_back(pt3);
950 py2_result.push_back(exterior2r);
951 mpy_result.push_back(py2_result);
952
953 this->test_valid_input(mpy1, mpy2, mpy_result);
954 }
955
956 TYPED_TEST(SymDifferenceTest, MultiPolygonGeometryCollection) {
957 typename TypeParam::Point pt1{0.05, 0.05};
958 typename TypeParam::Point pt2{0.1, 0.2};
959 typename TypeParam::Point pt3{0.2, 0.0};
960 typename TypeParam::Point pt4{0.2, 0.1};
961 typename TypeParam::Linestring ls1;
962 ls1.push_back(pt3);
963 ls1.push_back(pt4);
964 typename TypeParam::Multipolygon mpy = simple_mpy<TypeParam>();
965 typename TypeParam::Polygon py = base_py<TypeParam>();
966 typename TypeParam::Geometrycollection gc{};
967
968 this->test_valid_input(mpy, gc, py);
969 gc.push_back(pt3);
970 gc.push_back(ls1);
971 gc.push_back(mpy);
972
973 this->test_valid_input(mpy, gc, ls1);
974
975 typename TypeParam::Linestring ls2;
976 ls2.push_back(pt3);
977 ls2.push_back(pt4);
978 ls2.push_back(pt2);
979 typename TypeParam::Linestring ls3;
980 ls3.push_back(pt1);
981 ls3.push_back(pt2);
982 gc.push_back(ls2);
983 gc.push_back(ls3);
984 typename TypeParam::Multilinestring result{};
985 typename TypeParam::Linestring ls_result;
986 ls_result.push_back(pt2);
987 ls_result.push_back(typename TypeParam::Point(0.0666667, 0.1));
988 result.push_back(ls_result);
989 result.push_back(ls1);
990 result.push_back(ls2);
991 this->test_valid_input(mpy, gc, result);
992 }
993
994 // symdifference(... , geometrycollection, geometrycollection, ...)
995
996 TYPED_TEST(SymDifferenceTest, GeometryCollectionGeometryCollection) {
997 typename TypeParam::Point pt1{0.05, 0.05};
998 typename TypeParam::Point pt2{0.1, 0.2};
999 typename TypeParam::Point pt3{0.2, 0.0};
1000 typename TypeParam::Point pt4{0.2, 0.1};
1001 typename TypeParam::Linestring ls1;
1002 ls1.push_back(pt3);
1003 ls1.push_back(pt4);
1004 typename TypeParam::Multipolygon mpy = simple_mpy<TypeParam>();
1005 typename TypeParam::Polygon py = base_py<TypeParam>();
1006 typename TypeParam::Geometrycollection emptygc{};
1007 typename TypeParam::Geometrycollection gc{};
1008 typename TypeParam::Geometrycollection gc_py{};
1009 gc_py.push_back(mpy);
1010 this->test_valid_input(gc_py, gc_py, emptygc);
1011 this->test_valid_input(gc_py, gc, py);
1012 gc.push_back(ls1);
1013 this->test_valid_input(gc, gc, emptygc);
1014 gc.push_back(pt3);
1015 gc.push_back(mpy);
1016 this->test_valid_input(gc_py, gc, ls1);
1017
1018 typename TypeParam::Linestring ls2;
1019 ls2.push_back(pt3);
1020 ls2.push_back(pt4);
1021 ls2.push_back(pt2);
1022 typename TypeParam::Linestring ls3;
1023 ls3.push_back(pt1);
1024 ls3.push_back(pt2);
1025 gc.push_back(ls2);
1026 gc.push_back(ls3);
1027 typename TypeParam::Multilinestring result{};
1028 typename TypeParam::Linestring ls_result;
1029 ls_result.push_back(pt2);
1030 ls_result.push_back(typename TypeParam::Point(0.0666667, 0.1));
1031 result.push_back(ls_result);
1032 result.push_back(ls1);
1033 result.push_back(ls2);
1034 this->test_valid_input(gc_py, gc, result);
1035 }
1036
1037 } // namespace gis_symdifference_unittest