]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/algorithms/is_valid_geo.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / geometry / test / algorithms / is_valid_geo.cpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Unit Test
3
4 // Copyright (c) 2014-2017, Oracle and/or its affiliates.
5
6 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
7 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
8
9 // Licensed under the Boost Software License version 1.0.
10 // http://www.boost.org/users/license.html
11
12 #ifndef BOOST_TEST_MODULE
13 #define BOOST_TEST_MODULE test_is_valid_geo
14 #endif
15
16 #include <limits>
17 #include <iostream>
18
19 #include <boost/test/included/unit_test.hpp>
20
21 #include "test_is_valid.hpp"
22
23 #include <boost/geometry/core/coordinate_type.hpp>
24
25 #include <boost/geometry/algorithms/correct.hpp>
26 #include <boost/geometry/algorithms/intersection.hpp>
27 #include <boost/geometry/algorithms/reverse.hpp>
28
29
30 BOOST_AUTO_TEST_CASE( test_is_valid_geo_polygon )
31 {
32 typedef bg::model::point<double, 2, bg::cs::geographic<bg::degree> > pt;
33 typedef bg::model::polygon<pt, false> G;
34
35 typedef validity_tester_geo_areal<false> tester;
36 typedef test_valid<tester, G> test;
37
38 test::apply("p01", "POLYGON((-1 -1, 1 -1, 1 1, -1 1, -1 -1),(-0.5 -0.5, -0.5 0.5, 0.0 0.0, -0.5 -0.5),(0.0 0.0, 0.5 0.5, 0.5 -0.5, 0.0 0.0))", true);
39 }
40
41 template <typename Poly, typename Spheroid>
42 void test_valid_s(std::string const& wkt,
43 Spheroid const& sph,
44 bool expected_result)
45 {
46 typedef typename bg::point_type<Poly>::type pt;
47
48 bg::strategy::intersection::geographic_segments<> is(sph);
49 bg::strategy::area::geographic<pt> as(sph);
50
51 Poly p;
52 bg::read_wkt(wkt, p);
53 bg::correct(p, as);
54
55 BOOST_CHECK(bg::is_valid(p, is) == expected_result);
56 }
57
58 BOOST_AUTO_TEST_CASE( test_is_valid_epsg4053_polygon )
59 {
60 typedef bg::model::point<double, 2, bg::cs::geographic<bg::degree> > pt;
61 typedef bg::model::polygon<pt, false> po;
62
63 bg::srs::spheroid<double> epsg4053(6371228, 6371228);
64 bg::srs::spheroid<double> wgs84;
65
66 // NOTE: the orientation is different in these CSes,
67 // in one of them the polygon is corrected before passing it into is_valid()
68
69 test_valid_s<po>("POLYGON((-148 -68,178 -74,76 0,-148 -68))", wgs84, true);
70 test_valid_s<po>("POLYGON((-148 -68,178 -74,76 0,-148 -68))", epsg4053, true);
71
72 test_valid_s<po>("POLYGON((-152 -54,-56 43,142 -52,-152 -54))", wgs84, true);
73 test_valid_s<po>("POLYGON((-152 -54,-56 43,142 -52,-152 -54))", epsg4053, true);
74
75 return;
76 }