• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 
3 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
4 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
5 // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
6 
7 // This file was modified by Oracle on 2014, 2016, 2017, 2018, 2020.
8 // Modifications copyright (c) 2014-2020 Oracle and/or its affiliates.
9 
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 #ifndef BOOST_GEOMETRY_SRS_SPHEROID_HPP
20 #define BOOST_GEOMETRY_SRS_SPHEROID_HPP
21 
22 
23 #include <cstddef>
24 
25 #include <boost/static_assert.hpp>
26 
27 #include <boost/geometry/core/radius.hpp>
28 #include <boost/geometry/core/tag.hpp>
29 #include <boost/geometry/core/tags.hpp>
30 
31 #if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
32 #include <boost/geometry/core/assert.hpp>
33 #endif
34 
35 
36 namespace boost { namespace geometry
37 {
38 
39 namespace srs
40 {
41 
42 /*!
43     \brief Defines spheroid radius values for use in geographical CS calculations
44     \ingroup srs
45     \note See http://en.wikipedia.org/wiki/Figure_of_the_Earth
46           and http://en.wikipedia.org/wiki/World_Geodetic_System#A_new_World_Geodetic_System:_WGS84
47     \tparam RadiusType tparam_radius
48 */
49 template <typename RadiusType>
50 class spheroid
51 {
52 public:
spheroid(RadiusType const & a,RadiusType const & b)53     spheroid(RadiusType const& a, RadiusType const& b)
54         : m_a(a)
55         , m_b(b)
56     {
57 #if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
58         m_created = 1;
59 #endif
60     }
61 
spheroid()62     spheroid()
63         : m_a(RadiusType(6378137.0))
64         , m_b(RadiusType(6356752.3142451793))
65     {
66 #if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
67         m_created = 1;
68 #endif
69     }
70 
71 #if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
~spheroid()72     ~spheroid()
73     {
74         m_created = 0;
75     }
76 #endif
77 
78     template <std::size_t I>
get_radius() const79     RadiusType get_radius() const
80     {
81 #if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
82         if (m_created != 1)
83         {
84             int a = 10;
85         }
86         BOOST_GEOMETRY_ASSERT(m_created == 1);
87 #endif
88 
89         BOOST_STATIC_ASSERT(I < 3);
90 
91         return I < 2 ? m_a : m_b;
92     }
93 
94     template <std::size_t I>
set_radius(RadiusType const & radius)95     void set_radius(RadiusType const& radius)
96     {
97 #if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
98         BOOST_GEOMETRY_ASSERT(m_created == 1);
99 #endif
100 
101         BOOST_STATIC_ASSERT(I < 3);
102 
103         (I < 2 ? m_a : m_b) = radius;
104     }
105 
106 private:
107     RadiusType m_a, m_b; // equatorial radius, polar radius
108 
109 #if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
110     int m_created;
111 #endif
112 };
113 
114 } // namespace srs
115 
116 // Traits specializations for spheroid
117 #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
118 namespace traits
119 {
120 
121 template <typename RadiusType>
122 struct tag< srs::spheroid<RadiusType> >
123 {
124     typedef srs_spheroid_tag type;
125 };
126 
127 template <typename RadiusType>
128 struct radius_type< srs::spheroid<RadiusType> >
129 {
130     typedef RadiusType type;
131 };
132 
133 template <typename RadiusType, std::size_t Dimension>
134 struct radius_access<srs::spheroid<RadiusType>, Dimension>
135 {
136     typedef srs::spheroid<RadiusType> spheroid_type;
137 
getboost::geometry::traits::radius_access138     static inline RadiusType get(spheroid_type const& s)
139     {
140         return s.template get_radius<Dimension>();
141     }
142 
setboost::geometry::traits::radius_access143     static inline void set(spheroid_type& s, RadiusType const& value)
144     {
145         s.template set_radius<Dimension>(value);
146     }
147 };
148 
149 } // namespace traits
150 #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
151 
152 
153 }} // namespace boost::geometry
154 
155 
156 #endif // BOOST_GEOMETRY_SRS_SPHEROID_HPP
157