| 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/gis/geometries.h" |
| 32 | #include "sql/gis/geometries_cs.h" |
| 33 | #include "sql/gis/geometry_visitor.h" |
| 34 | |
| 35 | namespace geometries_unittest { |
| 36 | |
| 37 | struct Cartesian_types { |
| 38 | typedef gis::Cartesian_point Point; |
| 39 | typedef gis::Cartesian_linestring Linestring; |
| 40 | typedef gis::Cartesian_linearring Linearring; |
| 41 | typedef gis::Cartesian_polygon Polygon; |
| 42 | typedef gis::Cartesian_geometrycollection Geometrycollection; |
| 43 | typedef gis::Cartesian_multipoint Multipoint; |
| 44 | typedef gis::Cartesian_multilinestring Multilinestring; |
| 45 | typedef gis::Cartesian_multipolygon Multipolygon; |
| 46 | |
| 47 | static gis::Coordinate_system coordinate_system() { |
| 48 | return gis::Coordinate_system::kCartesian; |
| 49 | } |
| 50 | }; |
| 51 | |
| 52 | struct Geographic_types { |
| 53 | typedef gis::Geographic_point Point; |
| 54 | typedef gis::Geographic_linestring Linestring; |
| 55 | typedef gis::Geographic_linearring Linearring; |
| 56 | typedef gis::Geographic_polygon Polygon; |
| 57 | typedef gis::Geographic_geometrycollection Geometrycollection; |
| 58 | typedef gis::Geographic_multipoint Multipoint; |
| 59 | typedef gis::Geographic_multilinestring Multilinestring; |
| 60 | typedef gis::Geographic_multipolygon Multipolygon; |
| 61 | |
| 62 | static gis::Coordinate_system coordinate_system() { |
| 63 | return gis::Coordinate_system::kGeographic; |
| 64 | } |
| 65 | }; |
| 66 | |
| 67 | template <typename Types> |
| 68 | class GeometriesTest : public ::testing::Test { |
| 69 | public: |
| 70 | GeometriesTest() = default; |
| 71 | |
| 72 | ~GeometriesTest() override = default; |
| 73 | }; |
| 74 | |
| 75 | typedef ::testing::Types<Cartesian_types, Geographic_types> Types; |
| 76 | TYPED_TEST_SUITE(GeometriesTest, Types); |
| 77 | |
| 78 | TYPED_TEST(GeometriesTest, Point) { |
| 79 | typename TypeParam::Point pt; |
| 80 | EXPECT_EQ(gis::Geometry_type::kPoint, pt.type()); |
| 81 | EXPECT_EQ(TypeParam::coordinate_system(), pt.coordinate_system()); |
| 82 | EXPECT_TRUE(std::isnan(pt.x())); |
| 83 | EXPECT_TRUE(std::isnan(pt.y())); |
| 84 | EXPECT_TRUE(pt.is_empty()); |
| 85 | |
| 86 | gis::Nop_visitor visitor; |
| 87 | EXPECT_FALSE(pt.accept(&visitor)); |
| 88 | |
| 89 | typename TypeParam::Point pt2(0.0, 0.0); |
| 90 | EXPECT_EQ(0.0, pt2.x()); |
| 91 | EXPECT_EQ(0.0, pt2.y()); |
| 92 | |
| 93 | pt.x(-1.0); |
| 94 | pt.y(-1.0); |
| 95 | EXPECT_EQ(-1.0, pt.x()); |
| 96 | EXPECT_EQ(-1.0, pt.y()); |
| 97 | EXPECT_FALSE(pt.is_empty()); |
| 98 | |
| 99 | pt.x(1.0); |
| 100 | pt.y(1.0); |
| 101 | EXPECT_EQ(1.0, pt.x()); |
| 102 | EXPECT_EQ(1.0, pt.y()); |
| 103 | |
| 104 | pt.x(1.7976931348623157e308); |
| 105 | pt.y(-1.7976931348623157e308); |
| 106 | EXPECT_EQ(1.7976931348623157e308, pt.x()); |
| 107 | EXPECT_EQ(-1.7976931348623157e308, pt.y()); |
| 108 | |
| 109 | std::unique_ptr<typename TypeParam::Point> pt_clone(pt.clone()); |
| 110 | EXPECT_FALSE(&pt == pt_clone.get()); |
| 111 | EXPECT_EQ(pt.type(), pt_clone.get()->type()); |
| 112 | EXPECT_EQ(pt.coordinate_system(), pt_clone.get()->coordinate_system()); |
| 113 | EXPECT_EQ(pt.x(), pt_clone.get()->x()); |
| 114 | EXPECT_EQ(pt.y(), pt_clone.get()->y()); |
| 115 | } |
| 116 | |
| 117 | TYPED_TEST(GeometriesTest, Curve) {} |
| 118 | |
| 119 | TYPED_TEST(GeometriesTest, Linestring) { |
| 120 | typename TypeParam::Linestring ls; |
| 121 | EXPECT_EQ(gis::Geometry_type::kLinestring, ls.type()); |
| 122 | EXPECT_EQ(TypeParam::coordinate_system(), ls.coordinate_system()); |
| 123 | EXPECT_EQ(0U, ls.size()); |
| 124 | EXPECT_TRUE(ls.empty()); |
| 125 | EXPECT_TRUE(ls.is_empty()); |
| 126 | |
| 127 | ls.push_back(typename TypeParam::Point(0.0, 0.0)); |
| 128 | ls.push_back(typename TypeParam::Point(10.0, 10.0)); |
| 129 | ls.push_back(typename TypeParam::Point(20.0, 0.0)); |
| 130 | ls.push_back(typename TypeParam::Point(30.0, 10.0)); |
| 131 | EXPECT_EQ(4U, ls.size()); |
| 132 | EXPECT_FALSE(ls.empty()); |
| 133 | EXPECT_FALSE(ls.is_empty()); |
| 134 | |
| 135 | gis::Nop_visitor visitor; |
| 136 | EXPECT_FALSE(ls.accept(&visitor)); |
| 137 | |
| 138 | EXPECT_EQ(0.0, ls[0].x()); |
| 139 | EXPECT_EQ(0.0, ls[0].y()); |
| 140 | EXPECT_EQ(30.0, ls[3].x()); |
| 141 | EXPECT_EQ(10.0, ls[3].y()); |
| 142 | |
| 143 | EXPECT_EQ(0.0, ls.front().x()); |
| 144 | EXPECT_EQ(0.0, ls.front().y()); |
| 145 | |
| 146 | ls.pop_front(); |
| 147 | EXPECT_EQ(3U, ls.size()); |
| 148 | EXPECT_EQ(10.0, ls.front().x()); |
| 149 | EXPECT_EQ(10.0, ls.front().y()); |
| 150 | |
| 151 | std::unique_ptr<gis::Linestring> ls_new( |
| 152 | gis::Linestring::create_linestring(ls.coordinate_system())); |
| 153 | EXPECT_FALSE(&ls == ls_new.get()); |
| 154 | EXPECT_EQ(gis::Geometry_type::kLinestring, ls_new.get()->type()); |
| 155 | EXPECT_EQ(ls.coordinate_system(), ls_new.get()->coordinate_system()); |
| 156 | EXPECT_TRUE(ls_new.get()->empty()); |
| 157 | EXPECT_TRUE(ls_new.get()->is_empty()); |
| 158 | |
| 159 | std::unique_ptr<typename TypeParam::Linestring> ls_clone(ls.clone()); |
| 160 | EXPECT_FALSE(&ls == ls_clone.get()); |
| 161 | EXPECT_EQ(ls.type(), ls_clone.get()->type()); |
| 162 | EXPECT_EQ(ls.coordinate_system(), ls_clone.get()->coordinate_system()); |
| 163 | EXPECT_EQ(ls.size(), ls_clone.get()->size()); |
| 164 | for (std::size_t i = 0; i < ls.size(); i++) { |
| 165 | EXPECT_EQ(ls[i].x(), (*ls_clone.get())[i].x()); |
| 166 | EXPECT_EQ(ls[i].y(), (*ls_clone.get())[i].y()); |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | TYPED_TEST(GeometriesTest, Linearring) { |
| 171 | typename TypeParam::Linearring lr; |
| 172 | EXPECT_EQ(gis::Geometry_type::kLinestring, lr.type()); |
| 173 | EXPECT_EQ(TypeParam::coordinate_system(), lr.coordinate_system()); |
| 174 | EXPECT_EQ(0U, lr.size()); |
| 175 | EXPECT_TRUE(lr.empty()); |
| 176 | EXPECT_TRUE(lr.is_empty()); |
| 177 | |
| 178 | lr.push_back(typename TypeParam::Point(0.0, 0.0)); |
| 179 | lr.push_back(typename TypeParam::Point(10.0, 10.0)); |
| 180 | lr.push_back(typename TypeParam::Point(20.0, 0.0)); |
| 181 | lr.push_back(typename TypeParam::Point(0.0, 10.0)); |
| 182 | EXPECT_EQ(4U, lr.size()); |
| 183 | EXPECT_FALSE(lr.empty()); |
| 184 | EXPECT_FALSE(lr.is_empty()); |
| 185 | |
| 186 | gis::Nop_visitor visitor; |
| 187 | EXPECT_FALSE(lr.accept(&visitor)); |
| 188 | |
| 189 | EXPECT_EQ(10.0, lr[1].x()); |
| 190 | EXPECT_EQ(10.0, lr[1].y()); |
| 191 | EXPECT_EQ(20.0, lr[2].x()); |
| 192 | EXPECT_EQ(0.0, lr[2].y()); |
| 193 | |
| 194 | EXPECT_EQ(0.0, lr.back().x()); |
| 195 | EXPECT_EQ(10.0, lr.back().y()); |
| 196 | |
| 197 | EXPECT_EQ(0.0, lr.front().x()); |
| 198 | EXPECT_EQ(0.0, lr.front().y()); |
| 199 | |
| 200 | lr.pop_front(); |
| 201 | EXPECT_EQ(3U, lr.size()); |
| 202 | EXPECT_EQ(10.0, lr.front().x()); |
| 203 | EXPECT_EQ(10.0, lr.front().y()); |
| 204 | |
| 205 | std::unique_ptr<gis::Linearring> lr_new( |
| 206 | gis::Linearring::create_linearring(lr.coordinate_system())); |
| 207 | EXPECT_FALSE(&lr == lr_new.get()); |
| 208 | EXPECT_EQ(gis::Geometry_type::kLinestring, lr_new.get()->type()); |
| 209 | EXPECT_EQ(lr.coordinate_system(), lr_new.get()->coordinate_system()); |
| 210 | EXPECT_TRUE(lr_new.get()->empty()); |
| 211 | EXPECT_TRUE(lr_new.get()->is_empty()); |
| 212 | |
| 213 | std::unique_ptr<typename TypeParam::Linearring> lr_clone( |
| 214 | static_cast<typename TypeParam::Linearring *>(lr.clone())); |
| 215 | EXPECT_FALSE(&lr == lr_clone.get()); |
| 216 | EXPECT_EQ(lr.type(), lr_clone.get()->type()); |
| 217 | EXPECT_EQ(lr.coordinate_system(), lr_clone.get()->coordinate_system()); |
| 218 | EXPECT_EQ(lr.size(), lr_clone.get()->size()); |
| 219 | for (std::size_t i = 0; i < lr.size(); i++) { |
| 220 | EXPECT_EQ(lr[i].x(), (*lr_clone.get())[i].x()); |
| 221 | EXPECT_EQ(lr[i].y(), (*lr_clone.get())[i].y()); |
| 222 | } |
| 223 | typename TypeParam::Polygon py; |
| 224 | py.push_back(*lr_clone.get()); |
| 225 | EXPECT_EQ(1U, py.size()); |
| 226 | } |
| 227 | |
| 228 | TYPED_TEST(GeometriesTest, Surface) {} |
| 229 | |
| 230 | TYPED_TEST(GeometriesTest, Polygon) { |
| 231 | typename TypeParam::Polygon py; |
| 232 | EXPECT_EQ(gis::Geometry_type::kPolygon, py.type()); |
| 233 | EXPECT_EQ(TypeParam::coordinate_system(), py.coordinate_system()); |
| 234 | EXPECT_EQ(0U, py.size()); |
| 235 | EXPECT_TRUE(py.empty()); |
| 236 | EXPECT_TRUE(py.is_empty()); |
| 237 | |
| 238 | typename TypeParam::Linearring exterior; |
| 239 | exterior.push_back(typename TypeParam::Point(0.0, 0.0)); |
| 240 | exterior.push_back(typename TypeParam::Point(10.0, 0.0)); |
| 241 | exterior.push_back(typename TypeParam::Point(10.0, 10.0)); |
| 242 | exterior.push_back(typename TypeParam::Point(0.0, 10.0)); |
| 243 | exterior.push_back(typename TypeParam::Point(0.0, 0.0)); |
| 244 | py.push_back(exterior); |
| 245 | EXPECT_FALSE(py.empty()); |
| 246 | EXPECT_FALSE(py.is_empty()); |
| 247 | |
| 248 | typename TypeParam::Linearring interior; |
| 249 | interior.push_back(typename TypeParam::Point(2.0, 2.0)); |
| 250 | interior.push_back(typename TypeParam::Point(2.0, 8.0)); |
| 251 | interior.push_back(typename TypeParam::Point(8.0, 8.0)); |
| 252 | interior.push_back(typename TypeParam::Point(8.0, 2.0)); |
| 253 | interior.push_back(typename TypeParam::Point(2.0, 2.0)); |
| 254 | py.push_back(std::move(interior)); |
| 255 | |
| 256 | EXPECT_EQ(2U, py.size()); |
| 257 | EXPECT_FALSE(py.empty()); |
| 258 | EXPECT_EQ(1U, py.interior_rings().size()); |
| 259 | EXPECT_FALSE(py.interior_ring(0).empty()); |
| 260 | |
| 261 | gis::Nop_visitor visitor; |
| 262 | EXPECT_FALSE(py.accept(&visitor)); |
| 263 | |
| 264 | std::unique_ptr<gis::Polygon> py_new( |
| 265 | gis::Polygon::create_polygon(py.coordinate_system())); |
| 266 | EXPECT_FALSE(&py == py_new.get()); |
| 267 | EXPECT_EQ(gis::Geometry_type::kPolygon, py_new.get()->type()); |
| 268 | EXPECT_EQ(py.coordinate_system(), py_new.get()->coordinate_system()); |
| 269 | EXPECT_TRUE(py_new.get()->empty()); |
| 270 | EXPECT_TRUE(py_new.get()->is_empty()); |
| 271 | |
| 272 | std::unique_ptr<typename TypeParam::Polygon> py_clone(py.clone()); |
| 273 | EXPECT_FALSE(&py == py_clone.get()); |
| 274 | EXPECT_EQ(py.type(), py_clone.get()->type()); |
| 275 | EXPECT_EQ(py.coordinate_system(), py_clone.get()->coordinate_system()); |
| 276 | EXPECT_EQ(py.size(), py_clone.get()->size()); |
| 277 | for (std::size_t i = 0; i < py.exterior_ring().size(); i++) { |
| 278 | EXPECT_EQ(py.exterior_ring()[i].x(), |
| 279 | py_clone.get()->exterior_ring()[i].x()); |
| 280 | EXPECT_EQ(py.exterior_ring()[i].y(), |
| 281 | py_clone.get()->exterior_ring()[i].y()); |
| 282 | } |
| 283 | for (std::size_t i = 0; i < py.interior_rings().size(); i++) { |
| 284 | for (std::size_t j = 0; j < py.interior_ring(i).size(); j++) { |
| 285 | EXPECT_EQ(py.interior_ring(i)[j].x(), |
| 286 | py_clone.get()->interior_ring(i)[j].x()); |
| 287 | EXPECT_EQ(py.interior_ring(i)[j].x(), |
| 288 | py_clone.get()->interior_ring(i)[j].x()); |
| 289 | } |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | TYPED_TEST(GeometriesTest, Geometrycollection) { |
| 294 | typename TypeParam::Geometrycollection gc; |
| 295 | EXPECT_EQ(gis::Geometry_type::kGeometrycollection, gc.type()); |
| 296 | EXPECT_EQ(TypeParam::coordinate_system(), gc.coordinate_system()); |
| 297 | EXPECT_TRUE(gc.empty()); |
| 298 | EXPECT_TRUE(gc.is_empty()); |
| 299 | |
| 300 | gc.push_back(typename TypeParam::Geometrycollection()); |
| 301 | EXPECT_FALSE(gc.empty()); |
| 302 | EXPECT_TRUE(gc.is_empty()); |
| 303 | |
| 304 | typename TypeParam::Geometrycollection gc2; |
| 305 | gc2.push_back(typename TypeParam::Geometrycollection()); |
| 306 | gc.push_back(std::move(gc2)); |
| 307 | EXPECT_TRUE(gc.is_empty()); |
| 308 | |
| 309 | gc.push_back(typename TypeParam::Point(0.0, 0.0)); |
| 310 | gc.push_back(typename TypeParam::Point(10.0, 0.0)); |
| 311 | gc.push_back(typename TypeParam::Point(10.0, 10.0)); |
| 312 | gc.push_back(typename TypeParam::Point(0.0, 10.0)); |
| 313 | gc.push_back(typename TypeParam::Point(0.0, 0.0)); |
| 314 | |
| 315 | typename TypeParam::Linestring ls; |
| 316 | ls.push_back(typename TypeParam::Point(0.0, 0.0)); |
| 317 | ls.push_back(typename TypeParam::Point(10.0, 0.0)); |
| 318 | ls.push_back(typename TypeParam::Point(10.0, 10.0)); |
| 319 | ls.push_back(typename TypeParam::Point(0.0, 10.0)); |
| 320 | ls.push_back(typename TypeParam::Point(0.0, 0.0)); |
| 321 | gc.push_back(std::move(ls)); |
| 322 | |
| 323 | typename TypeParam::Linearring exterior; |
| 324 | exterior.push_back(typename TypeParam::Point(0.0, 0.0)); |
| 325 | exterior.push_back(typename TypeParam::Point(10.0, 0.0)); |
| 326 | exterior.push_back(typename TypeParam::Point(10.0, 10.0)); |
| 327 | exterior.push_back(typename TypeParam::Point(0.0, 10.0)); |
| 328 | exterior.push_back(typename TypeParam::Point(0.0, 0.0)); |
| 329 | typename TypeParam::Polygon py; |
| 330 | py.push_back(std::move(exterior)); |
| 331 | gc.push_back(std::move(py)); |
| 332 | |
| 333 | typename TypeParam::Multipoint mpt; |
| 334 | mpt.push_back(typename TypeParam::Point(0.0, 0.0)); |
| 335 | gc.push_back(std::move(mpt)); |
| 336 | |
| 337 | typename TypeParam::Linestring ls2; |
| 338 | ls2.push_back(typename TypeParam::Point(0.0, 0.0)); |
| 339 | ls2.push_back(typename TypeParam::Point(1.0, 1.0)); |
| 340 | typename TypeParam::Multilinestring mls; |
| 341 | mls.push_back(std::move(ls2)); |
| 342 | gc.push_back(std::move(mls)); |
| 343 | |
| 344 | typename TypeParam::Multipolygon mpy; |
| 345 | gc.push_back(std::move(mpy)); |
| 346 | |
| 347 | typename TypeParam::Geometrycollection inner_gc; |
| 348 | gc.push_back(std::move(inner_gc)); |
| 349 | |
| 350 | EXPECT_EQ(13U, gc.size()); |
| 351 | EXPECT_FALSE(gc.empty()); |
| 352 | EXPECT_FALSE(gc.is_empty()); |
| 353 | |
| 354 | gis::Nop_visitor visitor; |
| 355 | EXPECT_FALSE(gc.accept(&visitor)); |
| 356 | |
| 357 | typename TypeParam::Geometrycollection gc_copy = gc; |
| 358 | EXPECT_EQ(13U, gc_copy.size()); |
| 359 | EXPECT_FALSE(gc.empty()); |
| 360 | EXPECT_FALSE(gc.is_empty()); |
| 361 | |
| 362 | EXPECT_EQ(gis::Geometry_type::kGeometrycollection, gc.front().type()); |
| 363 | |
| 364 | gc.pop_front(); |
| 365 | gc.pop_front(); |
| 366 | EXPECT_EQ(11U, gc.size()); |
| 367 | EXPECT_EQ(gis::Geometry_type::kPoint, gc.front().type()); |
| 368 | |
| 369 | std::unique_ptr<gis::Geometrycollection> gc_new( |
| 370 | gis::Geometrycollection::create_geometrycollection( |
| 371 | gc.coordinate_system())); |
| 372 | EXPECT_FALSE(&gc == gc_new.get()); |
| 373 | EXPECT_EQ(gis::Geometry_type::kGeometrycollection, gc_new.get()->type()); |
| 374 | EXPECT_EQ(gc.coordinate_system(), gc_new.get()->coordinate_system()); |
| 375 | EXPECT_TRUE(gc_new.get()->empty()); |
| 376 | EXPECT_TRUE(gc_new.get()->is_empty()); |
| 377 | |
| 378 | std::unique_ptr<typename TypeParam::Geometrycollection> gc_clone(gc.clone()); |
| 379 | EXPECT_FALSE(&gc == gc_clone.get()); |
| 380 | EXPECT_EQ(gc.type(), gc_clone.get()->type()); |
| 381 | EXPECT_EQ(gc.coordinate_system(), gc_clone.get()->coordinate_system()); |
| 382 | EXPECT_EQ(gc.size(), gc_clone.get()->size()); |
| 383 | for (std::size_t i = 0; i < gc.size(); i++) { |
| 384 | EXPECT_EQ(gc[i].type(), (*gc_clone.get())[i].type()); |
| 385 | EXPECT_EQ(gc[i].coordinate_system(), |
| 386 | (*gc_clone.get())[i].coordinate_system()); |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | TYPED_TEST(GeometriesTest, Multipoint) { |
| 391 | typename TypeParam::Multipoint mpt; |
| 392 | EXPECT_EQ(gis::Geometry_type::kMultipoint, mpt.type()); |
| 393 | EXPECT_EQ(TypeParam::coordinate_system(), mpt.coordinate_system()); |
| 394 | EXPECT_TRUE(mpt.empty()); |
| 395 | EXPECT_TRUE(mpt.is_empty()); |
| 396 | |
| 397 | mpt.push_back(typename TypeParam::Point(0.0, 0.0)); |
| 398 | EXPECT_EQ(1U, mpt.size()); |
| 399 | EXPECT_FALSE(mpt.empty()); |
| 400 | EXPECT_FALSE(mpt.is_empty()); |
| 401 | |
| 402 | mpt.push_back(typename TypeParam::Point(1.0, 1.0)); |
| 403 | EXPECT_EQ(2U, mpt.size()); |
| 404 | |
| 405 | gis::Nop_visitor visitor; |
| 406 | EXPECT_FALSE(mpt.accept(&visitor)); |
| 407 | |
| 408 | EXPECT_EQ(0.0, mpt.front().x()); |
| 409 | EXPECT_EQ(0.0, mpt.front().y()); |
| 410 | |
| 411 | mpt.pop_front(); |
| 412 | EXPECT_EQ(1U, mpt.size()); |
| 413 | EXPECT_EQ(1.0, mpt.front().x()); |
| 414 | EXPECT_EQ(1.0, mpt.front().y()); |
| 415 | |
| 416 | std::unique_ptr<gis::Multipoint> mpt_new( |
| 417 | gis::Multipoint::create_multipoint(mpt.coordinate_system())); |
| 418 | EXPECT_FALSE(&mpt == mpt_new.get()); |
| 419 | EXPECT_EQ(gis::Geometry_type::kMultipoint, mpt_new.get()->type()); |
| 420 | EXPECT_EQ(mpt.coordinate_system(), mpt_new.get()->coordinate_system()); |
| 421 | EXPECT_TRUE(mpt_new.get()->empty()); |
| 422 | EXPECT_TRUE(mpt_new.get()->is_empty()); |
| 423 | |
| 424 | std::unique_ptr<typename TypeParam::Multipoint> mpt_clone(mpt.clone()); |
| 425 | EXPECT_FALSE(&mpt == mpt_clone.get()); |
| 426 | EXPECT_EQ(mpt.type(), mpt_clone.get()->type()); |
| 427 | EXPECT_EQ(mpt.coordinate_system(), mpt_clone.get()->coordinate_system()); |
| 428 | EXPECT_EQ(mpt.size(), mpt_clone.get()->size()); |
| 429 | for (std::size_t i = 0; i < mpt.size(); i++) { |
| 430 | EXPECT_EQ(mpt[i].x(), (*mpt_clone.get())[i].x()); |
| 431 | EXPECT_EQ(mpt[i].y(), (*mpt_clone)[i].y()); |
| 432 | } |
| 433 | } |
| 434 | |
| 435 | TYPED_TEST(GeometriesTest, Multicurve) { |
| 436 | std::unique_ptr<gis::Multicurve> mc(new |
| 437 | typename TypeParam::Multilinestring()); |
| 438 | EXPECT_EQ(0U, mc->size()); |
| 439 | EXPECT_TRUE(mc->empty()); |
| 440 | EXPECT_TRUE(mc->is_empty()); |
| 441 | |
| 442 | gis::Nop_visitor visitor; |
| 443 | EXPECT_FALSE(mc->accept(&visitor)); |
| 444 | } |
| 445 | |
| 446 | TYPED_TEST(GeometriesTest, Multilinestring) { |
| 447 | typename TypeParam::Multilinestring mls; |
| 448 | EXPECT_EQ(gis::Geometry_type::kMultilinestring, mls.type()); |
| 449 | EXPECT_EQ(TypeParam::coordinate_system(), mls.coordinate_system()); |
| 450 | EXPECT_TRUE(mls.empty()); |
| 451 | EXPECT_TRUE(mls.is_empty()); |
| 452 | |
| 453 | typename TypeParam::Linestring ls; |
| 454 | ls.push_back(typename TypeParam::Point(0.0, 0.0)); |
| 455 | ls.push_back(typename TypeParam::Point(10.0, 0.0)); |
| 456 | ls.push_back(typename TypeParam::Point(10.0, 10.0)); |
| 457 | ls.push_back(typename TypeParam::Point(0.0, 10.0)); |
| 458 | ls.push_back(typename TypeParam::Point(0.0, 0.0)); |
| 459 | mls.push_back(std::move(ls)); |
| 460 | EXPECT_EQ(1U, mls.size()); |
| 461 | EXPECT_FALSE(mls.empty()); |
| 462 | EXPECT_FALSE(mls.is_empty()); |
| 463 | |
| 464 | typename TypeParam::Linestring ls2; |
| 465 | ls.push_back(typename TypeParam::Point(0.0, 0.0)); |
| 466 | ls.push_back(typename TypeParam::Point(20.0, 20.0)); |
| 467 | mls.push_back(std::move(ls)); |
| 468 | EXPECT_EQ(2U, mls.size()); |
| 469 | |
| 470 | gis::Nop_visitor visitor; |
| 471 | EXPECT_FALSE(mls.accept(&visitor)); |
| 472 | |
| 473 | EXPECT_EQ(5U, mls.front().size()); |
| 474 | |
| 475 | mls.pop_front(); |
| 476 | EXPECT_EQ(1U, mls.size()); |
| 477 | EXPECT_EQ(2U, mls.front().size()); |
| 478 | |
| 479 | std::unique_ptr<gis::Multilinestring> mls_new( |
| 480 | gis::Multilinestring::create_multilinestring(mls.coordinate_system())); |
| 481 | EXPECT_FALSE(&mls == mls_new.get()); |
| 482 | EXPECT_EQ(gis::Geometry_type::kMultilinestring, mls_new.get()->type()); |
| 483 | EXPECT_EQ(mls.coordinate_system(), mls_new.get()->coordinate_system()); |
| 484 | EXPECT_TRUE(mls_new.get()->empty()); |
| 485 | EXPECT_TRUE(mls_new.get()->is_empty()); |
| 486 | |
| 487 | std::unique_ptr<typename TypeParam::Multilinestring> mls_clone(mls.clone()); |
| 488 | EXPECT_FALSE(&mls == mls_clone.get()); |
| 489 | EXPECT_EQ(mls.type(), mls_clone.get()->type()); |
| 490 | EXPECT_EQ(mls.coordinate_system(), mls_clone.get()->coordinate_system()); |
| 491 | EXPECT_EQ(mls.size(), mls_clone.get()->size()); |
| 492 | for (std::size_t i = 0; i < mls.size(); i++) { |
| 493 | for (std::size_t j = 0; j < mls[i].size(); j++) { |
| 494 | EXPECT_EQ(mls[i][j].x(), (*mls_clone.get())[i][j].x()); |
| 495 | EXPECT_EQ(mls[i][j].y(), (*mls_clone.get())[i][j].y()); |
| 496 | } |
| 497 | } |
| 498 | } |
| 499 | |
| 500 | TYPED_TEST(GeometriesTest, Multisurface) { |
| 501 | std::unique_ptr<gis::Multisurface> ms(new typename TypeParam::Multipolygon()); |
| 502 | EXPECT_EQ(0U, ms->size()); |
| 503 | EXPECT_TRUE(ms->empty()); |
| 504 | EXPECT_TRUE(ms->is_empty()); |
| 505 | |
| 506 | gis::Nop_visitor visitor; |
| 507 | EXPECT_FALSE(ms->accept(&visitor)); |
| 508 | } |
| 509 | |
| 510 | TYPED_TEST(GeometriesTest, Multipolygon) { |
| 511 | typename TypeParam::Multipolygon mpy; |
| 512 | EXPECT_EQ(gis::Geometry_type::kMultipolygon, mpy.type()); |
| 513 | EXPECT_EQ(TypeParam::coordinate_system(), mpy.coordinate_system()); |
| 514 | EXPECT_TRUE(mpy.empty()); |
| 515 | EXPECT_TRUE(mpy.is_empty()); |
| 516 | |
| 517 | typename TypeParam::Linearring exterior; |
| 518 | exterior.push_back(typename TypeParam::Point(0.0, 0.0)); |
| 519 | exterior.push_back(typename TypeParam::Point(10.0, 0.0)); |
| 520 | exterior.push_back(typename TypeParam::Point(10.0, 10.0)); |
| 521 | exterior.push_back(typename TypeParam::Point(0.0, 10.0)); |
| 522 | exterior.push_back(typename TypeParam::Point(0.0, 0.0)); |
| 523 | |
| 524 | typename TypeParam::Linearring interior; |
| 525 | interior.push_back(typename TypeParam::Point(2.0, 2.0)); |
| 526 | interior.push_back(typename TypeParam::Point(2.0, 8.0)); |
| 527 | interior.push_back(typename TypeParam::Point(8.0, 8.0)); |
| 528 | interior.push_back(typename TypeParam::Point(8.0, 2.0)); |
| 529 | interior.push_back(typename TypeParam::Point(2.0, 2.0)); |
| 530 | |
| 531 | typename TypeParam::Polygon py; |
| 532 | py.push_back(std::move(exterior)); |
| 533 | py.push_back(std::move(interior)); |
| 534 | mpy.push_back(std::move(py)); |
| 535 | EXPECT_EQ(1U, mpy.size()); |
| 536 | EXPECT_FALSE(mpy.empty()); |
| 537 | EXPECT_FALSE(mpy.is_empty()); |
| 538 | |
| 539 | mpy.push_back(typename TypeParam::Polygon()); |
| 540 | EXPECT_EQ(2U, mpy.size()); |
| 541 | |
| 542 | gis::Nop_visitor visitor; |
| 543 | EXPECT_FALSE(mpy.accept(&visitor)); |
| 544 | |
| 545 | std::unique_ptr<gis::Multipolygon> mpy_new( |
| 546 | gis::Multipolygon::create_multipolygon(mpy.coordinate_system())); |
| 547 | EXPECT_FALSE(&mpy == mpy_new.get()); |
| 548 | EXPECT_EQ(gis::Geometry_type::kMultipolygon, mpy_new.get()->type()); |
| 549 | EXPECT_EQ(mpy.coordinate_system(), mpy_new.get()->coordinate_system()); |
| 550 | EXPECT_TRUE(mpy_new.get()->empty()); |
| 551 | EXPECT_TRUE(mpy_new.get()->is_empty()); |
| 552 | |
| 553 | std::unique_ptr<typename TypeParam::Multipolygon> mpy_clone(mpy.clone()); |
| 554 | EXPECT_FALSE(&mpy == mpy_clone.get()); |
| 555 | EXPECT_EQ(mpy.type(), mpy_clone.get()->type()); |
| 556 | EXPECT_EQ(mpy.coordinate_system(), mpy_clone.get()->coordinate_system()); |
| 557 | EXPECT_EQ(mpy.size(), mpy_clone.get()->size()); |
| 558 | for (std::size_t i = 0; i < mpy.size(); i++) { |
| 559 | for (std::size_t j = 0; j < mpy[i].exterior_ring().size(); j++) { |
| 560 | EXPECT_EQ(mpy[i].exterior_ring()[j].x(), |
| 561 | (*mpy_clone.get())[i].exterior_ring()[j].x()); |
| 562 | EXPECT_EQ(mpy[i].exterior_ring()[j].y(), |
| 563 | (*mpy_clone.get())[i].exterior_ring()[j].y()); |
| 564 | } |
| 565 | for (std::size_t j = 0; j < mpy[i].interior_rings().size(); j++) { |
| 566 | for (std::size_t k = 0; k < mpy[i].interior_ring(j).size(); k++) { |
| 567 | EXPECT_EQ(mpy[i].interior_ring(j)[k].x(), |
| 568 | (*mpy_clone.get())[i].interior_ring(j)[k].x()); |
| 569 | EXPECT_EQ(mpy[i].interior_ring(j)[k].y(), |
| 570 | (*mpy_clone.get())[i].interior_ring(j)[k].y()); |
| 571 | } |
| 572 | } |
| 573 | } |
| 574 | |
| 575 | EXPECT_EQ(2U, mpy.front().size()); |
| 576 | |
| 577 | mpy.pop_front(); |
| 578 | EXPECT_EQ(1U, mpy.size()); |
| 579 | EXPECT_EQ(0U, mpy.front().size()); |
| 580 | } |
| 581 | |
| 582 | } // namespace geometries_unittest |