detail.hpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. // Boost.Geometry
  2. // Copyright (c) 2020, Oracle and/or its affiliates.
  3. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  4. // Licensed under the Boost Software License version 1.0.
  5. // http://www.boost.org/users/license.html
  6. #ifndef BOOST_GEOMETRY_STRATEGIES_DETAIL_HPP
  7. #define BOOST_GEOMETRY_STRATEGIES_DETAIL_HPP
  8. #include <boost/geometry/core/cs.hpp>
  9. #include <boost/geometry/strategies/geographic/parameters.hpp>
  10. #include <boost/geometry/strategies/spherical/get_radius.hpp>
  11. #include <boost/geometry/srs/sphere.hpp>
  12. #include <boost/geometry/srs/spheroid.hpp>
  13. #include <boost/geometry/util/type_traits.hpp>
  14. namespace boost { namespace geometry
  15. {
  16. namespace strategies
  17. {
  18. #ifndef DOXYGEN_NO_DETAIL
  19. namespace detail
  20. {
  21. struct umbrella_strategy {};
  22. template <typename Strategy>
  23. struct is_umbrella_strategy
  24. {
  25. static const bool value = std::is_base_of<umbrella_strategy, Strategy>::value;
  26. };
  27. struct cartesian_base : umbrella_strategy
  28. {
  29. typedef cartesian_tag cs_tag;
  30. };
  31. template <typename RadiusTypeOrSphere>
  32. class spherical_base : umbrella_strategy
  33. {
  34. protected:
  35. typedef typename strategy_detail::get_radius
  36. <
  37. RadiusTypeOrSphere
  38. >::type radius_type;
  39. public:
  40. typedef spherical_tag cs_tag;
  41. spherical_base()
  42. : m_radius(1.0)
  43. {}
  44. template <typename RadiusOrSphere>
  45. explicit spherical_base(RadiusOrSphere const& radius_or_sphere)
  46. : m_radius(strategy_detail::get_radius
  47. <
  48. RadiusOrSphere
  49. >::apply(radius_or_sphere))
  50. {}
  51. srs::sphere<radius_type> model() const
  52. {
  53. return srs::sphere<radius_type>(m_radius);
  54. }
  55. protected:
  56. radius_type const& radius() const
  57. {
  58. return m_radius;
  59. }
  60. radius_type m_radius;
  61. };
  62. template <>
  63. class spherical_base<void> : umbrella_strategy
  64. {
  65. protected:
  66. typedef double radius_type;
  67. public:
  68. typedef spherical_tag cs_tag;
  69. srs::sphere<radius_type> model() const
  70. {
  71. return srs::sphere<radius_type>(1.0);
  72. }
  73. protected:
  74. radius_type radius() const
  75. {
  76. return 1.0;
  77. }
  78. };
  79. template <typename Spheroid>
  80. class geographic_base : umbrella_strategy
  81. {
  82. public:
  83. typedef geographic_tag cs_tag;
  84. geographic_base()
  85. : m_spheroid()
  86. {}
  87. explicit geographic_base(Spheroid const& spheroid)
  88. : m_spheroid(spheroid)
  89. {}
  90. Spheroid model() const
  91. {
  92. return m_spheroid;
  93. }
  94. protected:
  95. Spheroid m_spheroid;
  96. };
  97. } // namespace detail
  98. #endif // DOXYGEN_NO_DETAIL
  99. } // namespace strategies
  100. }} // namespace boost::geometry
  101. #endif // BOOST_GEOMETRY_STRATEGIES_DETAIL_HPP