]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/core/radian_access.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / geometry / test / core / radian_access.cpp
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 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
9 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
10
11 // Use, modification and distribution is subject to the Boost Software License,
12 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
13 // http://www.boost.org/LICENSE_1_0.txt)
14
15
16 #include <geometry_test_common.hpp>
17
18 #include <boost/geometry/core/radian_access.hpp>
19
20 #include <boost/geometry/core/cs.hpp>
21 #include <boost/geometry/core/coordinate_type.hpp>
22 #include <boost/geometry/geometries/point.hpp>
23
24
25 template <std::size_t D, typename P, typename T>
26 void test_get(T const& c, T const& e)
27 {
28 //std::cout << "get_as_radian " << typeid(P).name() << std::endl;
29
30 typedef typename bg::coordinate_type<P>::type coordinate_type;
31
32 P p;
33 bg::set<D>(p, coordinate_type(c));
34
35 coordinate_type g = bg::get_as_radian<D>(p);
36
37 BOOST_CHECK_CLOSE(double(g), double(e), 0.0001);
38 }
39
40
41 template <std::size_t D, typename P, typename T>
42 void test_set(T const& c, T const& e)
43 {
44 //std::cout << "set_from_radian " << typeid(P).name() << std::endl;
45
46 typedef typename bg::coordinate_type<P>::type coordinate_type;
47
48 P p;
49 bg::set_from_radian<D>(p, coordinate_type(c));
50
51 coordinate_type g = bg::get<D>(p);
52
53 BOOST_CHECK_CLOSE(double(g), double(e), 0.0001);
54 }
55
56
57 template <typename T>
58 void test()
59 {
60 double d2r = 3.1415926535897932384626433832795 / 180.0;
61
62 // Degree
63 test_get<0, bg::model::point<T, 2, bg::cs::spherical<bg::degree> > >
64 (1.0, 1.0 * d2r);
65 test_get<1, bg::model::point<T, 2, bg::cs::spherical<bg::degree> > >
66 (2.0, 2.0 * d2r);
67
68 test_set<0, bg::model::point<T, 2, bg::cs::spherical<bg::degree> > >
69 (1.0, 1.0 / d2r);
70 test_set<1, bg::model::point<T, 2, bg::cs::spherical<bg::degree> > >
71 (2.0, 2.0 / d2r);
72
73
74 // Radian
75 test_get<0, bg::model::point<T, 2, bg::cs::spherical<bg::radian> > >
76 (1.0, 1.0);
77 test_get<1, bg::model::point<T, 2, bg::cs::spherical<bg::radian> > >
78 (1.0, 1.0);
79
80 test_set<0, bg::model::point<T, 2, bg::cs::spherical<bg::radian> > >
81 (1.0, 1.0);
82 test_set<1, bg::model::point<T, 2, bg::cs::spherical<bg::radian> > >
83 (1.0, 1.0);
84
85
86 // Cartesian (== untouched, no conversion)
87 test_get<0, bg::model::point<T, 2, bg::cs::cartesian> >
88 (1.0, 1.0);
89 test_get<1, bg::model::point<T, 2, bg::cs::cartesian> >
90 (1.0, 1.0);
91
92 // Dimension >=2, should always be untouched, even for degree
93 // (assuming lat/lon + height)
94 test_set<2, bg::model::point<T, 3, bg::cs::spherical<bg::radian> > >
95 (1.0, 1.0);
96 test_set<2, bg::model::point<T, 3, bg::cs::spherical<bg::degree> > >
97 (1.0, 1.0);
98
99 }
100
101
102
103
104 int test_main(int, char* [])
105 {
106 //test<float>();
107 test<double>();
108
109 return 0;
110 }