• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Unit Test
3 
4 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
5 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
6 // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
7 
8 // This file was modified by Oracle on 2017, 2018.
9 // Modifications copyright (c) 2017-2018, Oracle and/or its affiliates.
10 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
11 
12 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
13 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
14 
15 // Use, modification and distribution is subject to the Boost Software License,
16 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
17 // http://www.boost.org/LICENSE_1_0.txt)
18 
19 #if defined(_MSC_VER)
20 #pragma warning( disable : 4305 ) // truncation double -> float
21 #endif // defined(_MSC_VER)
22 
23 
24 #include <boost/core/ignore_unused.hpp>
25 
26 #include <geometry_test_common.hpp>
27 
28 #include <boost/geometry/srs/epsg.hpp>
29 #include <boost/geometry/srs/projection.hpp>
30 
31 #include <boost/geometry/core/coordinate_type.hpp>
32 
33 #include <boost/geometry/geometries/adapted/c_array.hpp>
34 #include <boost/geometry/geometries/geometries.hpp>
35 #include <boost/geometry/geometries/point_xy.hpp>
36 #include <test_common/test_point.hpp>
37 
38 namespace srs = bg::srs;
39 
40 template <int E, typename P1, typename P2>
test_one(double lon,double lat,typename bg::coordinate_type<P2>::type x,typename bg::coordinate_type<P2>::type y)41 void test_one(double lon, double lat,
42               typename bg::coordinate_type<P2>::type x,
43               typename bg::coordinate_type<P2>::type y)
44 {
45     srs::projection<srs::static_epsg<E> > prj;
46 
47     P1 ll;
48     bg::set<0>(ll, lon);
49     bg::set<1>(ll, lat);
50 
51     P2 xy;
52     bg::set<0>(xy, 0.0);
53     bg::set<1>(xy, 0.0);
54     prj.forward(ll, xy);
55 
56     BOOST_CHECK_CLOSE(bg::get<0>(xy), x, 0.001);
57     BOOST_CHECK_CLOSE(bg::get<1>(xy), y, 0.001);
58 }
59 
60 template <typename D, typename P>
test_deg_rad(double factor)61 void test_deg_rad(double factor)
62 {
63     typedef typename bg::coordinate_type<P>::type coord_type;
64     typedef bg::model::point<coord_type, 2, bg::cs::geographic<D> > point_type;
65 
66     // sterea
67     test_one<28992, point_type, P>(4.897000 * factor, 52.371000 * factor, 121590.388077, 487013.903377);
68     // utm
69     test_one<29118, point_type, P>(4.897000 * factor, 52.371000 * factor, 4938115.7568751378, 9139797.6057944782);
70 }
71 
72 template <typename P>
test_all()73 void test_all()
74 {
75     test_deg_rad<bg::degree, P>(1.0);
76     test_deg_rad<bg::radian, P>(bg::math::d2r<double>());
77 }
78 
test_main(int,char * [])79 int test_main(int, char* [])
80 {
81     // Commented out most the types because otherwise it cannot be linked
82     //test_all<int[2]>();
83     //test_all<float[2]>();
84     //test_all<double[2]>();
85     //test_all<test::test_point>();
86     //test_all<bg::model::d2::point_xy<int> >();
87     ////test_all<bg::model::d2::point_xy<float> >();
88     ////test_all<bg::model::d2::point_xy<long double> >();
89 
90     test_all<bg::model::d2::point_xy<double> >();
91 
92     return 0;
93 }
94