Debian Codegraph @

unittest/gunit/gis_relops-t.cc

raw symbols SCIP
1 /*
2 Copyright (c) 2017, 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 "my_config.h"
27
28 #include <gtest/gtest.h>
29 #include <memory> // unique_ptr
30
31 #include "sql/dd/dd.h"
32 #include "sql/dd/impl/types/spatial_reference_system_impl.h"
33 #include "sql/dd/properties.h"
34 #include "sql/dd/types/spatial_reference_system.h"
35 #include "sql/gis/geometries.h"
36 #include "sql/gis/geometries_cs.h"
37 #include "sql/gis/relops.h"
38
39 namespace gis_relops_unittest {
40
41 struct Cartesian_types {
42 typedef gis::Cartesian_point Point;
43 typedef gis::Cartesian_linestring Linestring;
44 typedef gis::Cartesian_linearring Linearring;
45 typedef gis::Cartesian_polygon Polygon;
46 typedef gis::Cartesian_geometrycollection Geometrycollection;
47 typedef gis::Cartesian_multipoint Multipoint;
48 typedef gis::Cartesian_multilinestring Multilinestring;
49 typedef gis::Cartesian_multipolygon Multipolygon;
50
51 static gis::Coordinate_system coordinate_system() {
52 return gis::Coordinate_system::kCartesian;
53 }
54 };
55
56 struct Geographic_types {
57 typedef gis::Geographic_point Point;
58 typedef gis::Geographic_linestring Linestring;
59 typedef gis::Geographic_linearring Linearring;
60 typedef gis::Geographic_polygon Polygon;
61 typedef gis::Geographic_geometrycollection Geometrycollection;
62 typedef gis::Geographic_multipoint Multipoint;
63 typedef gis::Geographic_multilinestring Multilinestring;
64 typedef gis::Geographic_multipolygon Multipolygon;
65
66 static gis::Coordinate_system coordinate_system() {
67 return gis::Coordinate_system::kGeographic;
68 }
69 };
70
71 template <typename Types>
72 class RelopsTest : public ::testing::Test {
73 protected:
74 dd::Spatial_reference_system_impl *m_srs;
75
76 public:
77 RelopsTest() {
78 switch (Types::coordinate_system()) {
79 case gis::Coordinate_system::kCartesian:
80 // Use SRID 0.
81 m_srs = nullptr;
82 break;
83 case gis::Coordinate_system::kGeographic:
84 // EPSG 4326, but with long-lat axes (E-N).
85 m_srs = dynamic_cast<dd::Spatial_reference_system_impl *>(
86 dd::create_object<dd::Spatial_reference_system>());
87 m_srs->set_id(4326);
88 m_srs->set_name("WGS 84");
89 m_srs->set_created(0UL);
90 m_srs->set_last_altered(0UL);
91 m_srs->set_organization("EPSG");
92 m_srs->set_organization_coordsys_id(4326);
93 m_srs->set_definition(
94 "GEOGCS[\"WGS 84\",DATUM[\"World Geodetic System "
95 "1984\",SPHEROID[\"WGS "
96 "84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],"
97 "AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY["
98 "\"EPSG\",\"8901\"]],UNIT[\"degree\",0.017453292519943278,"
99 "AUTHORITY[\"EPSG\",\"9122\"]],AXIS[\"Lon\",EAST],AXIS[\"Lat\","
100 "NORTH],AUTHORITY[\"EPSG\",\"4326\"]]");
101 m_srs->set_description("");
102 m_srs->parse_definition();
103 break;
104 }
105 }
106
107 ~RelopsTest() override { delete m_srs; }
108 };
109
110 typedef ::testing::Types<Cartesian_types, Geographic_types> Types;
111 TYPED_TEST_SUITE(RelopsTest, Types);
112
113 // The purpose of this test is to cover all type combinations, not to check if
114 // the results are correct.
115 TYPED_TEST(RelopsTest, CodeCoverage) {
116 typename TypeParam::Geometrycollection gc;
117 gc.push_back(typename TypeParam::Point(0.0, 0.0));
118
119 typename TypeParam::Linestring ls;
120 ls.push_back(typename TypeParam::Point(0.0, 0.0));
121 ls.push_back(typename TypeParam::Point(1.0, 1.0));
122 gc.push_back(ls);
123
124 typename TypeParam::Polygon py;
125 typename TypeParam::Linearring lr;
126 lr.push_back(typename TypeParam::Point(0.0, 0.0));
127 lr.push_back(typename TypeParam::Point(1.0, 0.0));
128 lr.push_back(typename TypeParam::Point(1.0, 1.0));
129 lr.push_back(typename TypeParam::Point(0.0, 1.0));
130 lr.push_back(typename TypeParam::Point(0.0, 0.0));
131 py.push_back(lr);
132 gc.push_back(py);
133
134 typename TypeParam::Geometrycollection gc_empty;
135 gc.push_back(gc_empty);
136
137 typename TypeParam::Geometrycollection gc_inner;
138 gc_inner.push_back(typename TypeParam::Point(0.0, 0.0));
139 gc.push_back(gc_inner);
140
141 typename TypeParam::Multipoint mpt;
142 mpt.push_back(typename TypeParam::Point(0.0, 0.0));
143 gc.push_back(mpt);
144
145 typename TypeParam::Multilinestring mls;
146 mls.push_back(ls);
147 gc.push_back(mls);
148
149 typename TypeParam::Multipolygon mpy;
150 mpy.push_back(py);
151 gc.push_back(mpy);
152
153 for (auto g1 : gc) {
154 for (auto g2 : gc) {
155 bool result = false;
156 bool is_null = false;
157 gis::crosses(this->m_srs, g1, g2, "unittest", &result, &is_null);
158 gis::disjoint(this->m_srs, g1, g2, "unittest", &result, &is_null);
159 gis::equals(this->m_srs, g1, g2, "unittest", &result, &is_null);
160 gis::intersects(this->m_srs, g1, g2, "unittest", &result, &is_null);
161 gis::mbr_covered_by(this->m_srs, g1, g2, "unittest", &result, &is_null);
162 gis::mbr_disjoint(this->m_srs, g1, g2, "unittest", &result, &is_null);
163 gis::mbr_equals(this->m_srs, g1, g2, "unittest", &result, &is_null);
164 gis::mbr_intersects(this->m_srs, g1, g2, "unittest", &result, &is_null);
165 gis::mbr_overlaps(this->m_srs, g1, g2, "unittest", &result, &is_null);
166 gis::mbr_touches(this->m_srs, g1, g2, "unittest", &result, &is_null);
167 gis::mbr_within(this->m_srs, g1, g2, "unittest", &result, &is_null);
168 gis::overlaps(this->m_srs, g1, g2, "unittest", &result, &is_null);
169 gis::touches(this->m_srs, g1, g2, "unittest", &result, &is_null);
170 gis::within(this->m_srs, g1, g2, "unittest", &result, &is_null);
171 }
172 }
173 }
174
175 } // namespace gis_relops_unittest