1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Unit Test
3 
4 // Copyright (c) 2017 Adam Wulkiewicz, Lodz, Poland.
5 
6 // Copyright (c) 2014-2018, Oracle and/or its affiliates.
7 
8 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
9 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
10 
11 // Licensed under the Boost Software License version 1.0.
12 // http://www.boost.org/users/license.html
13 
14 #ifndef BOOST_TEST_MODULE
15 #define BOOST_TEST_MODULE test_is_valid_geo
16 #endif
17 
18 #include <limits>
19 #include <iostream>
20 
21 #include <boost/test/included/unit_test.hpp>
22 
23 #include "test_is_valid.hpp"
24 
25 #include <boost/geometry/core/coordinate_type.hpp>
26 
27 #include <boost/geometry/algorithms/correct.hpp>
28 #include <boost/geometry/algorithms/intersection.hpp>
29 #include <boost/geometry/algorithms/reverse.hpp>
30 
31 
BOOST_AUTO_TEST_CASE(test_is_valid_geo_polygon)32 BOOST_AUTO_TEST_CASE( test_is_valid_geo_polygon )
33 {
34     typedef bg::model::point<double, 2, bg::cs::geographic<bg::degree> > pt;
35     typedef bg::model::polygon<pt, false> G;
36 
37     typedef validity_tester_geo_areal<false> tester;
38     typedef test_valid<tester, G> test;
39 
40     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);
41 }
42 
43 template <typename Poly, typename Spheroid>
test_valid_s(std::string const & wkt,Spheroid const & sph,bool expected_result)44 void test_valid_s(std::string const& wkt,
45                   Spheroid const& sph,
46                   bool expected_result)
47 {
48     bg::strategy::intersection::geographic_segments<> is(sph);
49     bg::strategy::area::geographic<> 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 
BOOST_AUTO_TEST_CASE(test_is_valid_epsg4053_polygon)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 }