File: gis_testshapes.h

package info (click to toggle)
mysql-8.0 8.0.43-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,273,924 kB
  • sloc: cpp: 4,684,605; ansic: 412,450; pascal: 108,398; java: 83,641; perl: 30,221; cs: 27,067; sql: 26,594; sh: 24,181; python: 21,816; yacc: 17,169; php: 11,522; xml: 7,388; javascript: 7,076; makefile: 2,194; lex: 1,075; awk: 670; asm: 520; objc: 183; ruby: 97; lisp: 86
file content (328 lines) | stat: -rw-r--r-- 11,251 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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
#ifndef UNITTEST_GUNIT_GIS_TESTSHAPES_H_INCLUDED
#define UNITTEST_GUNIT_GIS_TESTSHAPES_H_INCLUDED

// Copyright (c) 2017, 2025, Oracle and/or its affiliates.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License, version 2.0,
// as published by the Free Software Foundation.
//
// This program is designed to work with certain software (including
// but not limited to OpenSSL) that is licensed under separate terms,
// as designated in a particular file or component or in included license
// documentation.  The authors of MySQL hereby grant you an additional
// permission to link the program and your derivative works with the
// separately licensed software that they have either included with
// the program or referenced in the documentation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License, version 2.0, for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA.

#include <exception>
#include <vector>
#include "sql/gis/geometries.h"
#include "sql/gis/geometries_cs.h"

struct Cartesian_types {
  typedef gis::Cartesian_point Point;
  typedef gis::Cartesian_linestring Linestring;
  typedef gis::Cartesian_linearring Linearring;
  typedef gis::Cartesian_polygon Polygon;
  typedef gis::Cartesian_geometrycollection Geometrycollection;
  typedef gis::Cartesian_multipoint Multipoint;
  typedef gis::Cartesian_multilinestring Multilinestring;
  typedef gis::Cartesian_multipolygon Multipolygon;

  static gis::Coordinate_system coordinate_system() {
    return gis::Coordinate_system::kCartesian;
  }
};

struct Geographic_types {
  typedef gis::Geographic_point Point;
  typedef gis::Geographic_linestring Linestring;
  typedef gis::Geographic_linearring Linearring;
  typedef gis::Geographic_polygon Polygon;
  typedef gis::Geographic_geometrycollection Geometrycollection;
  typedef gis::Geographic_multipoint Multipoint;
  typedef gis::Geographic_multilinestring Multilinestring;
  typedef gis::Geographic_multipolygon Multipolygon;

  static gis::Coordinate_system coordinate_system() {
    return gis::Coordinate_system::kGeographic;
  }
};
template <typename T>
typename T::Linearring linearringFromVector(std::vector<double> data) {
  if (data.size() % 2 != 0) {
    throw std::exception(); /* purecov: dead code */
  }
  typename T::Linearring lr;
  for (size_t i = 0; i + 1 < data.size(); i += 2) {
    lr.push_back(typename T::Point(data[i], data[i + 1]));
  }
  return lr;
}

template <typename T, typename U>
T polygonFromVector(std::vector<double> data) {
  T py;
  py.push_back(linearringFromVector<U>(data));
  return py;
}

template <typename T>
typename T::Polygon selfTouchingPolygon() {
  typename T::Polygon py;
  py.push_back(linearringFromVector<T>(
      {0, 0, 1, 0, 0, 0.5, 0.5, 0.25, 0.25, 0.5, 0.5, 0.5, 0, 1, 0, 0}));
  return py;
}

template <typename U>
typename U::Polygon polygonWithTouchingHole() {
  typename U::Polygon py;
  py.push_back(linearringFromVector<U>({0, 0, 1, 0, 0, 1, 0, 0}));
  py.push_back(
      linearringFromVector<U>({0.5, 0.5, 0.5, 0.25, 0.25, 0.5, 0.5, 0.5}));
  return py;
}
template <typename U>
typename U::Polygon polygon_reverse() {
  typename U::Polygon py;
  py.push_back(linearringFromVector<U>({0, 0, 0, 1, 1, 0, 0, 0}));
  py.push_back(
      linearringFromVector<U>({0.5, 0.5, 0.25, 0.5, 0.5, 0.25, 0.5, 0.5}));
  return py;
}
template <typename U>
typename U::Polygon polygon_reverse_touching_hole() {
  typename U::Polygon py;
  py.push_back(linearringFromVector<U>({0, 0, 1, 0, 0, 1, 0, 0}));
  py.push_back(
      linearringFromVector<U>({0.5, 0.5, 0.25, 0.5, 0.5, 0.25, 0.5, 0.5}));
  return py;
}
template <typename T>
typename T::Linearring linearring_2xsquare_around_origin() {
  return linearringFromVector<T>({-1, -1, 1, -1, 1, 1, -1, 1, -1, -1});
}
template <typename U>
typename U::Polygon polygon_with_touching_hole_vertice_vertice() {
  typename U::Polygon py;
  py.push_back(linearring_2xsquare_around_origin<U>());
  py.push_back(
      linearringFromVector<U>({-1., 0.0, 0.5, 0.25, 0.5, -0.25, -1, 0.0}));
  return py;
}

template <typename T>
typename T::Polygon polygon_hourglass();

template <>
gis::Geographic_polygon polygon_hourglass<Geographic_types>() {
  gis::Geographic_polygon py;
  py.push_back(linearringFromVector<Geographic_types>(
      {-0.5, 1, 0.5, 1, -0.5 + M_PI, 1, 0.5 - M_PI, 1}));
  return py;
}
template <>
gis::Cartesian_polygon polygon_hourglass<Cartesian_types>() {
  gis::Cartesian_polygon py;
  py.push_back(linearringFromVector<Cartesian_types>(
      {-1, -1, 1, -1, -1, 1, 1, 1, -1, -1}));
  return py;
}

template <typename T>
typename T::Polygon polygonSelfTouchEdgeVertice() {
  typename T::Polygon py;
  py.push_back(linearringFromVector<T>(
      {0, 0, 0.2, -0.2, 0, -0.4, 0, 0.2, -0.4, -0.6, 0.6, 0, 0, 0}));
  return py;
}

template <typename T>
typename T::Polygon polygonDisconnectedLimit() {
  typename T::Polygon py;
  py.push_back(linearringFromVector<T>({0, 0, 0.2, 0, 0.2, 0.3, 0, 0.3, 0, 0}));
  py.push_back(linearringFromVector<T>({0, 0.4, 0.4, 0.4, 0.2, 0.2, 0, 0.4}));
  return py;
}
template <typename T>
typename T::Polygon polygon_empty_hole() {
  typename T::Polygon py;
  py.push_back(linearringFromVector<T>({0, 0, 1, 0, 0, 1, 0, 0}));
  py.push_back(linearringFromVector<T>(std::vector<double>()));
  return py;
}

template <typename T>
typename T::Polygon polygon_open() {
  typename T::Polygon py;
  py.push_back(linearringFromVector<T>({0, 0, 1, 0, 1, 0}));
  return py;
}
template <typename T>
typename T::Polygon polygon_inner_partially_outside() {
  typename T::Polygon py;
  py.push_back(linearringFromVector<T>({0, 0, 1, 0, 1, 0, 0, 0}));
  py.push_back(
      linearringFromVector<T>({0.25, 0.25, 1, .25, .25, 1, 0.25, 0.25}));
  return py;
}
template <typename T>
typename T::Polygon polygon_inner_wholly_outside() {
  typename T::Polygon py;
  py.push_back(linearringFromVector<T>({0, 0, 1, 0, 1, 0, 0, 0}));
  py.push_back(linearringFromVector<T>({1, 0.5, 0.5, 1, 1, 1, 1, 0.5}));
  return py;
}
template <typename T>
typename T::Polygon polygon_inner_intersecting() {
  typename T::Polygon py;
  py.push_back(linearringFromVector<T>({0, 0, 1, 0, 1, 1, 1, 0, 0, 0}));
  py.push_back(linearringFromVector<T>({.2, 0.2, 0.2, .8, .8, .2, .2, .2}));
  py.push_back(linearringFromVector<T>({.4, 0.4, 0.4, .8, .8, .4, .4, .4}));
  return py;
}
template <typename T>
typename T::Linearring linearring_unit_square() {
  return linearringFromVector<T>({0, 0, 1, 0, 1, 1, 0, 1, 0, 0});
}
template <typename T>
typename T::Polygon polygon_2_inner() {
  typename T::Polygon py;
  py.push_back(linearring_unit_square<T>());
  py.push_back(
      linearringFromVector<T>({0.2, 0.2, 0.2, 0.8, 0.8, 0.2, 0.2, 0.2}));
  py.push_back(
      linearringFromVector<T>({0.8, 0.4, 0.4, 0.8, 0.8, 0.8, 0.8, 0.4}));
  return py;
}
template <typename T>
typename T::Polygon polygon_2_inner_edge_to_edge0() {
  typename T::Polygon py;
  py.push_back(linearring_unit_square<T>());
  py.push_back(
      linearringFromVector<T>({0.2, 0.2, 0.2, 0.8, 0.8, 0.2, 0.2, 0.2}));
  py.push_back(
      linearringFromVector<T>({0.8, 0.2, 0.2, 0.8, 0.8, 0.8, 0.8, 0.2}));
  return py;
}
template <typename T>
typename T::Polygon polygon_2_inner_edge_to_edge1() {
  typename T::Polygon py;
  py.push_back(linearring_unit_square<T>());
  py.push_back(
      linearringFromVector<T>({0.2, 0.2, 0.2, 0.8, 0.8, 0.2, 0.2, 0.2}));
  py.push_back(
      linearringFromVector<T>({0.8, 0.2, 0.4, 0.6, 0.8, 0.6, 0.8, 0.2}));
  return py;
}
template <typename T>
typename T::Polygon polygon_2_inner_edge_to_vertice() {
  typename T::Polygon py;
  py.push_back(linearringFromVector<T>({-1, -1, 1, -1, 1, 1, -1, 1, -1, -1}));
  py.push_back(
      linearringFromVector<T>({-0.5, 0.0, 0.0, 0.5, 0.0, -0.5, -0.5, 0.0}));
  py.push_back(
      linearringFromVector<T>({0.0, 0.0, 0.5, 0.5, 0.5, -0.5, 0.0, 0.0}));
  return py;
}
template <typename T>
typename T::Polygon polygon_2_inner_vertice_to_vertice() {
  typename T::Polygon py;
  py.push_back(linearring_2xsquare_around_origin<T>());
  py.push_back(
      linearringFromVector<T>({-0.5, -0.5, -0.5, 0.5, 0.0, 0.0, -0.5, -0.5}));
  py.push_back(
      linearringFromVector<T>({0.0, 0.0, 0.5, 0.5, 0.5, -0.5, 0.0, 0.0}));
  return py;
}
template <typename T>
typename T::Polygon polygon_1_1_bug26476445() {
  typename T::Polygon py;
  py.push_back(linearringFromVector<T>(
      {0.15707963267948966, 0.19198621771937624, 2.4958208303518914,
       0.9250245035569946, 0.24434609527920614, 0.6632251157578452,
       0.15707963267948966, 0.19198621771937624}));
  return py;
}
template <typename T>
typename T::Polygon polygon_1_2_bug26476445() {
  typename T::Polygon py;
  py.push_back(linearringFromVector<T>(
      {-2.5132741228718345, -1.0122909661567112, -0.06981317007977318,
       -1.2217304763960306, -2.478367537831948, -0.10471975511965977,
       -2.5132741228718345, -1.0122909661567112}));
  return py;
}
template <typename T>
typename T::Multipolygon multipolygon_1_bug26476445() {
  typename T::Multipolygon mpy;
  mpy.push_back(polygon_1_1_bug26476445<T>());
  mpy.push_back(polygon_1_2_bug26476445<T>());
  return mpy;
}

template <typename T>
typename T::Polygon polygon_2_1_bug26476445() {
  typename T::Polygon py;
  py.push_back(linearringFromVector<T>(
      {0.15707963267948966, 0.19198621771937624, 0.7504915783575616,
       0.9424777960769379, 0.24434609527920614, 1.4660765716752369,
       0.15707963267948966, 0.19198621771937624}));
  return py;
}
template <typename T>
typename T::Polygon polygon_2_2_bug26476445() {
  typename T::Polygon py;
  py.push_back(linearringFromVector<T>(
      {-2.5132741228718345, -1.0122909661567112, -0.06981317007977318,
       -1.2217304763960306, -2.478367537831948, -0.10471975511965977,
       -2.5132741228718345, -1.0122909661567112}));
  return py;
}
template <typename T>
typename T::Multipolygon multipolygon_2_bug26476445() {
  typename T::Multipolygon mpy;
  mpy.push_back(polygon_2_1_bug26476445<T>());
  mpy.push_back(polygon_2_2_bug26476445<T>());
  return mpy;
}

template <typename T>
typename T::Linestring linestringFromVector(std::vector<double> data) {
  if (data.size() % 2 != 0) {
    throw std::exception();
  }
  typename T::Linearring ls;
  for (size_t i = 0; i + 1 < data.size(); i += 2) {
    ls.push_back(typename T::Point(data[i], data[i + 1]));
  }
  return ls;
}

template <typename T>
typename T::Linestring linestring_3pt_normal() {
  return linestringFromVector<T>({0.0, 0.0, 0.56, 0.99, -.66, 2.0});
}

template <typename T>
typename T::Linestring linestring_ring() {
  return linestringFromVector<T>({0.0, 0.0, 0.56, 0.99, 0.0, 2.0, 0.0, 0.0});
}

template <typename T>
typename T::Linestring linestring_selfcrossing() {
  return linestringFromVector<T>({0.0, 0.0, 1.0, 0.0, 0.1, 1.0, 0.0, -2.0});
}

#endif  // UNITTEST_GUNIT_GIS_TESTSHAPES_H_INCLUDED