sphere.hpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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, 2018.
  6. // Modifications copyright (c) 2014-2018 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_SPHERE_HPP
  14. #define BOOST_GEOMETRY_SRS_SPHERE_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. namespace boost { namespace geometry
  21. {
  22. namespace srs
  23. {
  24. /*!
  25. \brief Defines sphere radius value for use in spherical CS calculations
  26. \ingroup srs
  27. \tparam RadiusType tparam_radius
  28. */
  29. template <typename RadiusType>
  30. class sphere
  31. {
  32. public:
  33. explicit sphere(RadiusType const& r)
  34. : m_r(r)
  35. {}
  36. sphere()
  37. : m_r(RadiusType((2.0 * 6378137.0 + 6356752.3142451793) / 3.0))
  38. {}
  39. template <std::size_t I>
  40. RadiusType get_radius() const
  41. {
  42. BOOST_STATIC_ASSERT(I < 3);
  43. return m_r;
  44. }
  45. template <std::size_t I>
  46. void set_radius(RadiusType const& radius)
  47. {
  48. BOOST_STATIC_ASSERT(I < 3);
  49. m_r = radius;
  50. }
  51. private:
  52. RadiusType m_r; // radius
  53. };
  54. } // namespace srs
  55. // Traits specializations for sphere
  56. #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  57. namespace traits
  58. {
  59. template <typename RadiusType>
  60. struct tag< srs::sphere<RadiusType> >
  61. {
  62. typedef srs_sphere_tag type;
  63. };
  64. template <typename RadiusType>
  65. struct radius_type< srs::sphere<RadiusType> >
  66. {
  67. typedef RadiusType type;
  68. };
  69. template <typename RadiusType, std::size_t Dimension>
  70. struct radius_access<srs::sphere<RadiusType>, Dimension>
  71. {
  72. typedef srs::sphere<RadiusType> sphere_type;
  73. static inline RadiusType get(sphere_type const& s)
  74. {
  75. return s.template get_radius<Dimension>();
  76. }
  77. static inline void set(sphere_type& s, RadiusType const& value)
  78. {
  79. s.template set_radius<Dimension>(value);
  80. }
  81. };
  82. } // namespace traits
  83. #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  84. }} // namespace boost::geometry
  85. #endif // BOOST_GEOMETRY_SRS_SPHERE_HPP