spheroid.hpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
  3. // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
  4. // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
  5. // This file was modified by Oracle on 2014, 2016, 2017, 2018, 2020.
  6. // Modifications copyright (c) 2014-2020 Oracle and/or its affiliates.
  7. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  8. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  9. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  10. // Use, modification and distribution is subject to the Boost Software License,
  11. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  12. // http://www.boost.org/LICENSE_1_0.txt)
  13. #ifndef BOOST_GEOMETRY_SRS_SPHEROID_HPP
  14. #define BOOST_GEOMETRY_SRS_SPHEROID_HPP
  15. #include <cstddef>
  16. #include <boost/static_assert.hpp>
  17. #include <boost/geometry/core/radius.hpp>
  18. #include <boost/geometry/core/tag.hpp>
  19. #include <boost/geometry/core/tags.hpp>
  20. #if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
  21. #include <boost/geometry/core/assert.hpp>
  22. #endif
  23. namespace boost { namespace geometry
  24. {
  25. namespace srs
  26. {
  27. /*!
  28. \brief Defines spheroid radius values for use in geographical CS calculations
  29. \ingroup srs
  30. \note See http://en.wikipedia.org/wiki/Figure_of_the_Earth
  31. and http://en.wikipedia.org/wiki/World_Geodetic_System#A_new_World_Geodetic_System:_WGS84
  32. \tparam RadiusType tparam_radius
  33. */
  34. template <typename RadiusType>
  35. class spheroid
  36. {
  37. public:
  38. spheroid(RadiusType const& a, RadiusType const& b)
  39. : m_a(a)
  40. , m_b(b)
  41. {
  42. #if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
  43. m_created = 1;
  44. #endif
  45. }
  46. spheroid()
  47. : m_a(RadiusType(6378137.0))
  48. , m_b(RadiusType(6356752.3142451793))
  49. {
  50. #if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
  51. m_created = 1;
  52. #endif
  53. }
  54. #if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
  55. ~spheroid()
  56. {
  57. m_created = 0;
  58. }
  59. #endif
  60. template <std::size_t I>
  61. RadiusType get_radius() const
  62. {
  63. #if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
  64. if (m_created != 1)
  65. {
  66. int a = 10;
  67. }
  68. BOOST_GEOMETRY_ASSERT(m_created == 1);
  69. #endif
  70. BOOST_STATIC_ASSERT(I < 3);
  71. return I < 2 ? m_a : m_b;
  72. }
  73. template <std::size_t I>
  74. void set_radius(RadiusType const& radius)
  75. {
  76. #if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
  77. BOOST_GEOMETRY_ASSERT(m_created == 1);
  78. #endif
  79. BOOST_STATIC_ASSERT(I < 3);
  80. (I < 2 ? m_a : m_b) = radius;
  81. }
  82. private:
  83. RadiusType m_a, m_b; // equatorial radius, polar radius
  84. #if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
  85. int m_created;
  86. #endif
  87. };
  88. } // namespace srs
  89. // Traits specializations for spheroid
  90. #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  91. namespace traits
  92. {
  93. template <typename RadiusType>
  94. struct tag< srs::spheroid<RadiusType> >
  95. {
  96. typedef srs_spheroid_tag type;
  97. };
  98. template <typename RadiusType>
  99. struct radius_type< srs::spheroid<RadiusType> >
  100. {
  101. typedef RadiusType type;
  102. };
  103. template <typename RadiusType, std::size_t Dimension>
  104. struct radius_access<srs::spheroid<RadiusType>, Dimension>
  105. {
  106. typedef srs::spheroid<RadiusType> spheroid_type;
  107. static inline RadiusType get(spheroid_type const& s)
  108. {
  109. return s.template get_radius<Dimension>();
  110. }
  111. static inline void set(spheroid_type& s, RadiusType const& value)
  112. {
  113. s.template set_radius<Dimension>(value);
  114. }
  115. };
  116. } // namespace traits
  117. #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  118. }} // namespace boost::geometry
  119. #endif // BOOST_GEOMETRY_SRS_SPHEROID_HPP