detail.hpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. // Boost.Geometry
  2. // Copyright (c) 2020-2021, 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. struct not_implemented {};
  23. template <typename Strategy>
  24. struct is_umbrella_strategy
  25. {
  26. static const bool value = std::is_base_of<umbrella_strategy, Strategy>::value;
  27. };
  28. struct cartesian_base : umbrella_strategy
  29. {
  30. typedef cartesian_tag cs_tag;
  31. };
  32. template <typename RadiusTypeOrSphere>
  33. class spherical_base : umbrella_strategy
  34. {
  35. protected:
  36. typedef typename strategy_detail::get_radius
  37. <
  38. RadiusTypeOrSphere
  39. >::type radius_type;
  40. public:
  41. typedef spherical_tag cs_tag;
  42. spherical_base()
  43. : m_radius(1.0)
  44. {}
  45. template <typename RadiusOrSphere>
  46. explicit spherical_base(RadiusOrSphere const& radius_or_sphere)
  47. : m_radius(strategy_detail::get_radius
  48. <
  49. RadiusOrSphere
  50. >::apply(radius_or_sphere))
  51. {}
  52. srs::sphere<radius_type> model() const
  53. {
  54. return srs::sphere<radius_type>(m_radius);
  55. }
  56. protected:
  57. radius_type const& radius() const
  58. {
  59. return m_radius;
  60. }
  61. radius_type m_radius;
  62. };
  63. template <>
  64. class spherical_base<void> : umbrella_strategy
  65. {
  66. protected:
  67. typedef double radius_type;
  68. public:
  69. typedef spherical_tag cs_tag;
  70. srs::sphere<radius_type> model() const
  71. {
  72. return srs::sphere<radius_type>(1.0);
  73. }
  74. protected:
  75. radius_type radius() const
  76. {
  77. return 1.0;
  78. }
  79. };
  80. template <typename Spheroid>
  81. class geographic_base : umbrella_strategy
  82. {
  83. public:
  84. typedef geographic_tag cs_tag;
  85. geographic_base()
  86. : m_spheroid()
  87. {}
  88. explicit geographic_base(Spheroid const& spheroid)
  89. : m_spheroid(spheroid)
  90. {}
  91. Spheroid model() const
  92. {
  93. return m_spheroid;
  94. }
  95. protected:
  96. Spheroid m_spheroid;
  97. };
  98. } // namespace detail
  99. #endif // DOXYGEN_NO_DETAIL
  100. } // namespace strategies
  101. }} // namespace boost::geometry
  102. #endif // BOOST_GEOMETRY_STRATEGIES_DETAIL_HPP