1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Unit Test
3 
4 // Copyright (c) 2016-2017 Oracle and/or its affiliates.
5 // Contributed and/or modified by Vissarion Fisikopoulos, on behalf of Oracle
6 
7 // Use, modification and distribution is subject to the Boost Software License,
8 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
10 
11 #include <algorithms/test_perimeter.hpp>
12 #include <algorithms/perimeter/perimeter_polygon_cases.hpp>
13 
14 #include <boost/geometry/geometries/geometries.hpp>
15 #include <boost/geometry/geometries/point_xy.hpp>
16 
17 template <typename P>
18 struct geo_strategies
19 {
20     // Set radius type, but for integer coordinates we want to have floating
21     // point radius type
22     typedef typename bg::promote_floating_point
23     <
24         typename bg::coordinate_type<P>::type
25     >::type rtype;
26 
27     typedef bg::srs::spheroid<rtype> stype;
28     typedef bg::strategy::distance::andoyer<stype> andoyer_type;
29     typedef bg::strategy::distance::thomas<stype> thomas_type;
30     typedef bg::strategy::distance::vincenty<stype> vincenty_type;
31 };
32 
33 template <typename P>
test_default()34 void test_default() //this should use andoyer strategy
35 {
36     for (std::size_t i = 0; i <= 2; ++i)
37     {
38         test_geometry<bg::model::polygon<P> >(poly_data_geo[i],
39                                               1116814.237 + 1116152.605);
40     }
41 
42     //since the geodesic distance is the shortest path it should go over the pole
43     //in this case; thus the correct perimeter is the meridian length (below)
44     //and not 40075160 which is the legth of the equator
45     test_geometry<bg::model::polygon<P> >(poly_data_geo[3],
46                                           40007834.7139);
47 
48     //force to use equator path
49     test_geometry<bg::model::polygon<P> >(poly_data_geo[4],
50                                           40075016.6856);
51 
52     // Multipolygon
53     test_geometry<bg::model::multi_polygon<bg::model::polygon<P> > >
54                                             (multipoly_data[0], 60011752.0709);
55 
56     // Geometries with length zero
57     test_geometry<P>("POINT(0 0)", 0);
58     test_geometry<bg::model::linestring<P> >("LINESTRING(0 0,0 1,1 1,1 0,0 0)",
59                                              0);
60 }
61 
62 template <typename P, typename N, typename Strategy>
test_with_strategy(N exp_length,Strategy strategy)63 void test_with_strategy(N exp_length, Strategy strategy)
64 {
65     for (std::size_t i = 0; i <= 2; ++i)
66     {
67         test_geometry<bg::model::polygon<P> >(poly_data_geo[i],
68                                               exp_length,
69                                               strategy);
70     }
71     // Geometries with length zero
72     test_geometry<P>("POINT(0 0)", 0, strategy);
73     test_geometry<bg::model::linestring<P> >("LINESTRING(0 0,0 1,1 1,1 0,0 0)",
74                                              0,
75                                              strategy);
76 }
77 
78 template <typename P>
test_andoyer()79 void test_andoyer()
80 {
81     typename geo_strategies<P>::andoyer_type andoyer;
82     test_with_strategy<P>(1116814.237 + 1116152.605, andoyer);
83 }
84 
85 template <typename P>
test_thomas()86 void test_thomas()
87 {
88     typename geo_strategies<P>::thomas_type thomas;
89     test_with_strategy<P>(1116825.795 + 1116158.7417, thomas);
90 }
91 
92 template <typename P>
test_vincenty()93 void test_vincenty()
94 {
95     typename geo_strategies<P>::vincenty_type vincenty;
96     test_with_strategy<P>(1116825.857 + 1116159.144, vincenty);
97 }
98 
99 template <typename P>
test_all()100 void test_all()
101 {
102     test_default<P>();
103     test_andoyer<P>();
104     test_thomas<P>();
105     test_vincenty<P>();
106 }
107 
test_main(int,char * [])108 int test_main(int, char* [])
109 {
110     // Works only for double(?!)
111     //test_all<bg::model::d2::point_xy<int,
112     //                              bg::cs::geographic<bg::degree> > >();
113     //test_all<bg::model::d2::point_xy<float,
114     //                              bg::cs::geographic<bg::degree> > >();
115     test_all<bg::model::d2::point_xy<double,
116                                   bg::cs::geographic<bg::degree> > >();
117 
118     return 0;
119 }
120 
121