| 1 |
#ifndef UNITTEST_GUNIT_GIS_TESTSHAPES_H_INCLUDED |
| 2 |
#define UNITTEST_GUNIT_GIS_TESTSHAPES_H_INCLUDED |
| 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 |
#include <exception> |
| 28 |
#include <vector> |
| 29 |
#include "sql/gis/geometries.h" |
| 30 |
#include "sql/gis/geometries_cs.h" |
| 31 |
|
| 32 |
struct Cartesian_types { |
| 33 |
typedef gis::Cartesian_point Point; |
| 34 |
typedef gis::Cartesian_linestring Linestring; |
| 35 |
typedef gis::Cartesian_linearring Linearring; |
| 36 |
typedef gis::Cartesian_polygon Polygon; |
| 37 |
typedef gis::Cartesian_geometrycollection Geometrycollection; |
| 38 |
typedef gis::Cartesian_multipoint Multipoint; |
| 39 |
typedef gis::Cartesian_multilinestring Multilinestring; |
| 40 |
typedef gis::Cartesian_multipolygon Multipolygon; |
| 41 |
|
| 42 |
static gis::Coordinate_system coordinate_system() { |
| 43 |
return gis::Coordinate_system::kCartesian; |
| 44 |
} |
| 45 |
}; |
| 46 |
|
| 47 |
struct Geographic_types { |
| 48 |
typedef gis::Geographic_point Point; |
| 49 |
typedef gis::Geographic_linestring Linestring; |
| 50 |
typedef gis::Geographic_linearring Linearring; |
| 51 |
typedef gis::Geographic_polygon Polygon; |
| 52 |
typedef gis::Geographic_geometrycollection Geometrycollection; |
| 53 |
typedef gis::Geographic_multipoint Multipoint; |
| 54 |
typedef gis::Geographic_multilinestring Multilinestring; |
| 55 |
typedef gis::Geographic_multipolygon Multipolygon; |
| 56 |
|
| 57 |
static gis::Coordinate_system coordinate_system() { |
| 58 |
return gis::Coordinate_system::kGeographic; |
| 59 |
} |
| 60 |
}; |
| 61 |
template <typename T> |
| 62 |
typename T::Linearring linearringFromVector(std::vector<double> data) { |
| 63 |
if (data.size() % 2 != 0) { |
| 64 |
throw std::exception(); |
| 65 |
} |
| 66 |
typename T::Linearring lr; |
| 67 |
for (size_t i = 0; i + 1 < data.size(); i += 2) { |
| 68 |
lr.push_back(typename T::Point(data[i], data[i + 1])); |
| 69 |
} |
| 70 |
return lr; |
| 71 |
} |
| 72 |
|
| 73 |
template <typename T, typename U> |
| 74 |
T polygonFromVector(std::vector<double> data) { |
| 75 |
T py; |
| 76 |
py.push_back(linearringFromVector<U>(data)); |
| 77 |
return py; |
| 78 |
} |
| 79 |
|
| 80 |
template <typename T> |
| 81 |
typename T::Polygon selfTouchingPolygon() { |
| 82 |
typename T::Polygon py; |
| 83 |
py.push_back(linearringFromVector<T>( |
| 84 |
{0, 0, 1, 0, 0, 0.5, 0.5, 0.25, 0.25, 0.5, 0.5, 0.5, 0, 1, 0, 0})); |
| 85 |
return py; |
| 86 |
} |
| 87 |
|
| 88 |
template <typename U> |
| 89 |
typename U::Polygon polygonWithTouchingHole() { |
| 90 |
typename U::Polygon py; |
| 91 |
py.push_back(linearringFromVector<U>({0, 0, 1, 0, 0, 1, 0, 0})); |
| 92 |
py.push_back( |
| 93 |
linearringFromVector<U>({0.5, 0.5, 0.5, 0.25, 0.25, 0.5, 0.5, 0.5})); |
| 94 |
return py; |
| 95 |
} |
| 96 |
template <typename U> |
| 97 |
typename U::Polygon polygon_reverse() { |
| 98 |
typename U::Polygon py; |
| 99 |
py.push_back(linearringFromVector<U>({0, 0, 0, 1, 1, 0, 0, 0})); |
| 100 |
py.push_back( |
| 101 |
linearringFromVector<U>({0.5, 0.5, 0.25, 0.5, 0.5, 0.25, 0.5, 0.5})); |
| 102 |
return py; |
| 103 |
} |
| 104 |
template <typename U> |
| 105 |
typename U::Polygon polygon_reverse_touching_hole() { |
| 106 |
typename U::Polygon py; |
| 107 |
py.push_back(linearringFromVector<U>({0, 0, 1, 0, 0, 1, 0, 0})); |
| 108 |
py.push_back( |
| 109 |
linearringFromVector<U>({0.5, 0.5, 0.25, 0.5, 0.5, 0.25, 0.5, 0.5})); |
| 110 |
return py; |
| 111 |
} |
| 112 |
template <typename T> |
| 113 |
typename T::Linearring linearring_2xsquare_around_origin() { |
| 114 |
return linearringFromVector<T>({-1, -1, 1, -1, 1, 1, -1, 1, -1, -1}); |
| 115 |
} |
| 116 |
template <typename U> |
| 117 |
typename U::Polygon polygon_with_touching_hole_vertice_vertice() { |
| 118 |
typename U::Polygon py; |
| 119 |
py.push_back(linearring_2xsquare_around_origin<U>()); |
| 120 |
py.push_back( |
| 121 |
linearringFromVector<U>({-1., 0.0, 0.5, 0.25, 0.5, -0.25, -1, 0.0})); |
| 122 |
return py; |
| 123 |
} |
| 124 |
|
| 125 |
template <typename T> |
| 126 |
typename T::Polygon polygon_hourglass(); |
| 127 |
|
| 128 |
template <> |
| 129 |
gis::Geographic_polygon polygon_hourglass<Geographic_types>() { |
| 130 |
gis::Geographic_polygon py; |
| 131 |
py.push_back(linearringFromVector<Geographic_types>( |
| 132 |
{-0.5, 1, 0.5, 1, -0.5 + M_PI, 1, 0.5 - M_PI, 1})); |
| 133 |
return py; |
| 134 |
} |
| 135 |
template <> |
| 136 |
gis::Cartesian_polygon polygon_hourglass<Cartesian_types>() { |
| 137 |
gis::Cartesian_polygon py; |
| 138 |
py.push_back(linearringFromVector<Cartesian_types>( |
| 139 |
{-1, -1, 1, -1, -1, 1, 1, 1, -1, -1})); |
| 140 |
return py; |
| 141 |
} |
| 142 |
|
| 143 |
template <typename T> |
| 144 |
typename T::Polygon polygonSelfTouchEdgeVertice() { |
| 145 |
typename T::Polygon py; |
| 146 |
py.push_back(linearringFromVector<T>( |
| 147 |
{0, 0, 0.2, -0.2, 0, -0.4, 0, 0.2, -0.4, -0.6, 0.6, 0, 0, 0})); |
| 148 |
return py; |
| 149 |
} |
| 150 |
|
| 151 |
template <typename T> |
| 152 |
typename T::Polygon polygonDisconnectedLimit() { |
| 153 |
typename T::Polygon py; |
| 154 |
py.push_back(linearringFromVector<T>({0, 0, 0.2, 0, 0.2, 0.3, 0, 0.3, 0, 0})); |
| 155 |
py.push_back(linearringFromVector<T>({0, 0.4, 0.4, 0.4, 0.2, 0.2, 0, 0.4})); |
| 156 |
return py; |
| 157 |
} |
| 158 |
template <typename T> |
| 159 |
typename T::Polygon polygon_empty_hole() { |
| 160 |
typename T::Polygon py; |
| 161 |
py.push_back(linearringFromVector<T>({0, 0, 1, 0, 0, 1, 0, 0})); |
| 162 |
py.push_back(linearringFromVector<T>(std::vector<double>())); |
| 163 |
return py; |
| 164 |
} |
| 165 |
|
| 166 |
template <typename T> |
| 167 |
typename T::Polygon polygon_open() { |
| 168 |
typename T::Polygon py; |
| 169 |
py.push_back(linearringFromVector<T>({0, 0, 1, 0, 1, 0})); |
| 170 |
return py; |
| 171 |
} |
| 172 |
template <typename T> |
| 173 |
typename T::Polygon polygon_inner_partially_outside() { |
| 174 |
typename T::Polygon py; |
| 175 |
py.push_back(linearringFromVector<T>({0, 0, 1, 0, 1, 0, 0, 0})); |
| 176 |
py.push_back( |
| 177 |
linearringFromVector<T>({0.25, 0.25, 1, .25, .25, 1, 0.25, 0.25})); |
| 178 |
return py; |
| 179 |
} |
| 180 |
template <typename T> |
| 181 |
typename T::Polygon polygon_inner_wholly_outside() { |
| 182 |
typename T::Polygon py; |
| 183 |
py.push_back(linearringFromVector<T>({0, 0, 1, 0, 1, 0, 0, 0})); |
| 184 |
py.push_back(linearringFromVector<T>({1, 0.5, 0.5, 1, 1, 1, 1, 0.5})); |
| 185 |
return py; |
| 186 |
} |
| 187 |
template <typename T> |
| 188 |
typename T::Polygon polygon_inner_intersecting() { |
| 189 |
typename T::Polygon py; |
| 190 |
py.push_back(linearringFromVector<T>({0, 0, 1, 0, 1, 1, 1, 0, 0, 0})); |
| 191 |
py.push_back(linearringFromVector<T>({.2, 0.2, 0.2, .8, .8, .2, .2, .2})); |
| 192 |
py.push_back(linearringFromVector<T>({.4, 0.4, 0.4, .8, .8, .4, .4, .4})); |
| 193 |
return py; |
| 194 |
} |
| 195 |
template <typename T> |
| 196 |
typename T::Linearring linearring_unit_square() { |
| 197 |
return linearringFromVector<T>({0, 0, 1, 0, 1, 1, 0, 1, 0, 0}); |
| 198 |
} |
| 199 |
template <typename T> |
| 200 |
typename T::Polygon polygon_2_inner() { |
| 201 |
typename T::Polygon py; |
| 202 |
py.push_back(linearring_unit_square<T>()); |
| 203 |
py.push_back( |
| 204 |
linearringFromVector<T>({0.2, 0.2, 0.2, 0.8, 0.8, 0.2, 0.2, 0.2})); |
| 205 |
py.push_back( |
| 206 |
linearringFromVector<T>({0.8, 0.4, 0.4, 0.8, 0.8, 0.8, 0.8, 0.4})); |
| 207 |
return py; |
| 208 |
} |
| 209 |
template <typename T> |
| 210 |
typename T::Polygon polygon_2_inner_edge_to_edge0() { |
| 211 |
typename T::Polygon py; |
| 212 |
py.push_back(linearring_unit_square<T>()); |
| 213 |
py.push_back( |
| 214 |
linearringFromVector<T>({0.2, 0.2, 0.2, 0.8, 0.8, 0.2, 0.2, 0.2})); |
| 215 |
py.push_back( |
| 216 |
linearringFromVector<T>({0.8, 0.2, 0.2, 0.8, 0.8, 0.8, 0.8, 0.2})); |
| 217 |
return py; |
| 218 |
} |
| 219 |
template <typename T> |
| 220 |
typename T::Polygon polygon_2_inner_edge_to_edge1() { |
| 221 |
typename T::Polygon py; |
| 222 |
py.push_back(linearring_unit_square<T>()); |
| 223 |
py.push_back( |
| 224 |
linearringFromVector<T>({0.2, 0.2, 0.2, 0.8, 0.8, 0.2, 0.2, 0.2})); |
| 225 |
py.push_back( |
| 226 |
linearringFromVector<T>({0.8, 0.2, 0.4, 0.6, 0.8, 0.6, 0.8, 0.2})); |
| 227 |
return py; |
| 228 |
} |
| 229 |
template <typename T> |
| 230 |
typename T::Polygon polygon_2_inner_edge_to_vertice() { |
| 231 |
typename T::Polygon py; |
| 232 |
py.push_back(linearringFromVector<T>({-1, -1, 1, -1, 1, 1, -1, 1, -1, -1})); |
| 233 |
py.push_back( |
| 234 |
linearringFromVector<T>({-0.5, 0.0, 0.0, 0.5, 0.0, -0.5, -0.5, 0.0})); |
| 235 |
py.push_back( |
| 236 |
linearringFromVector<T>({0.0, 0.0, 0.5, 0.5, 0.5, -0.5, 0.0, 0.0})); |
| 237 |
return py; |
| 238 |
} |
| 239 |
template <typename T> |
| 240 |
typename T::Polygon polygon_2_inner_vertice_to_vertice() { |
| 241 |
typename T::Polygon py; |
| 242 |
py.push_back(linearring_2xsquare_around_origin<T>()); |
| 243 |
py.push_back( |
| 244 |
linearringFromVector<T>({-0.5, -0.5, -0.5, 0.5, 0.0, 0.0, -0.5, -0.5})); |
| 245 |
py.push_back( |
| 246 |
linearringFromVector<T>({0.0, 0.0, 0.5, 0.5, 0.5, -0.5, 0.0, 0.0})); |
| 247 |
return py; |
| 248 |
} |
| 249 |
template <typename T> |
| 250 |
typename T::Polygon polygon_1_1_bug26476445() { |
| 251 |
typename T::Polygon py; |
| 252 |
py.push_back(linearringFromVector<T>( |
| 253 |
{0.15707963267948966, 0.19198621771937624, 2.4958208303518914, |
| 254 |
0.9250245035569946, 0.24434609527920614, 0.6632251157578452, |
| 255 |
0.15707963267948966, 0.19198621771937624})); |
| 256 |
return py; |
| 257 |
} |
| 258 |
template <typename T> |
| 259 |
typename T::Polygon polygon_1_2_bug26476445() { |
| 260 |
typename T::Polygon py; |
| 261 |
py.push_back(linearringFromVector<T>( |
| 262 |
{-2.5132741228718345, -1.0122909661567112, -0.06981317007977318, |
| 263 |
-1.2217304763960306, -2.478367537831948, -0.10471975511965977, |
| 264 |
-2.5132741228718345, -1.0122909661567112})); |
| 265 |
return py; |
| 266 |
} |
| 267 |
template <typename T> |
| 268 |
typename T::Multipolygon multipolygon_1_bug26476445() { |
| 269 |
typename T::Multipolygon mpy; |
| 270 |
mpy.push_back(polygon_1_1_bug26476445<T>()); |
| 271 |
mpy.push_back(polygon_1_2_bug26476445<T>()); |
| 272 |
return mpy; |
| 273 |
} |
| 274 |
|
| 275 |
template <typename T> |
| 276 |
typename T::Polygon polygon_2_1_bug26476445() { |
| 277 |
typename T::Polygon py; |
| 278 |
py.push_back(linearringFromVector<T>( |
| 279 |
{0.15707963267948966, 0.19198621771937624, 0.7504915783575616, |
| 280 |
0.9424777960769379, 0.24434609527920614, 1.4660765716752369, |
| 281 |
0.15707963267948966, 0.19198621771937624})); |
| 282 |
return py; |
| 283 |
} |
| 284 |
template <typename T> |
| 285 |
typename T::Polygon polygon_2_2_bug26476445() { |
| 286 |
typename T::Polygon py; |
| 287 |
py.push_back(linearringFromVector<T>( |
| 288 |
{-2.5132741228718345, -1.0122909661567112, -0.06981317007977318, |
| 289 |
-1.2217304763960306, -2.478367537831948, -0.10471975511965977, |
| 290 |
-2.5132741228718345, -1.0122909661567112})); |
| 291 |
return py; |
| 292 |
} |
| 293 |
template <typename T> |
| 294 |
typename T::Multipolygon multipolygon_2_bug26476445() { |
| 295 |
typename T::Multipolygon mpy; |
| 296 |
mpy.push_back(polygon_2_1_bug26476445<T>()); |
| 297 |
mpy.push_back(polygon_2_2_bug26476445<T>()); |
| 298 |
return mpy; |
| 299 |
} |
| 300 |
|
| 301 |
template <typename T> |
| 302 |
typename T::Linestring linestringFromVector(std::vector<double> data) { |
| 303 |
if (data.size() % 2 != 0) { |
| 304 |
throw std::exception(); |
| 305 |
} |
| 306 |
typename T::Linearring ls; |
| 307 |
for (size_t i = 0; i + 1 < data.size(); i += 2) { |
| 308 |
ls.push_back(typename T::Point(data[i], data[i + 1])); |
| 309 |
} |
| 310 |
return ls; |
| 311 |
} |
| 312 |
|
| 313 |
template <typename T> |
| 314 |
typename T::Linestring linestring_3pt_normal() { |
| 315 |
return linestringFromVector<T>({0.0, 0.0, 0.56, 0.99, -.66, 2.0}); |
| 316 |
} |
| 317 |
|
| 318 |
template <typename T> |
| 319 |
typename T::Linestring linestring_ring() { |
| 320 |
return linestringFromVector<T>({0.0, 0.0, 0.56, 0.99, 0.0, 2.0, 0.0, 0.0}); |
| 321 |
} |
| 322 |
|
| 323 |
template <typename T> |
| 324 |
typename T::Linestring linestring_selfcrossing() { |
| 325 |
return linestringFromVector<T>({0.0, 0.0, 1.0, 0.0, 0.1, 1.0, 0.0, -2.0}); |
| 326 |
} |
| 327 |
|
| 328 |
#endif |