spherical.hpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. // Boost.Geometry
  2. // Copyright (c) 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_SIMPLIFY_SPHERICAL_HPP
  7. #define BOOST_GEOMETRY_STRATEGIES_SIMPLIFY_SPHERICAL_HPP
  8. #include <boost/geometry/strategies/detail.hpp>
  9. #include <boost/geometry/strategies/distance/comparable.hpp>
  10. #include <boost/geometry/strategies/distance/detail.hpp>
  11. #include <boost/geometry/strategies/simplify/services.hpp>
  12. #include <boost/geometry/strategies/agnostic/simplify_douglas_peucker.hpp>
  13. #include <boost/geometry/strategies/spherical/distance_haversine.hpp>
  14. #include <boost/geometry/strategies/spherical/distance_cross_track.hpp>
  15. #include <boost/geometry/strategies/spherical/point_in_point.hpp>
  16. #include <boost/geometry/strategy/spherical/area.hpp>
  17. namespace boost { namespace geometry
  18. {
  19. namespace strategies { namespace simplify
  20. {
  21. template
  22. <
  23. typename RadiusTypeOrSphere = double,
  24. typename CalculationType = void
  25. >
  26. class spherical
  27. : public strategies::detail::spherical_base<RadiusTypeOrSphere>
  28. {
  29. using base_t = strategies::detail::spherical_base<RadiusTypeOrSphere>;
  30. public:
  31. spherical() = default;
  32. template <typename RadiusOrSphere>
  33. explicit spherical(RadiusOrSphere const& radius_or_sphere)
  34. : base_t(radius_or_sphere)
  35. {}
  36. // TODO: Replace this if calculate_point_order() is used in simplify
  37. template <typename Geometry>
  38. auto area(Geometry const&) const
  39. {
  40. return strategy::area::spherical
  41. <
  42. typename base_t::radius_type, CalculationType
  43. >(base_t::radius());
  44. }
  45. // For perimeter()
  46. template <typename Geometry1, typename Geometry2>
  47. auto distance(Geometry1 const&, Geometry2 const&,
  48. distance::detail::enable_if_pp_t<Geometry1, Geometry2> * = nullptr) const
  49. {
  50. return strategy::distance::haversine
  51. <
  52. typename base_t::radius_type, CalculationType
  53. >(base_t::radius());
  54. }
  55. // For douglas_peucker
  56. template <typename Geometry1, typename Geometry2>
  57. auto distance(Geometry1 const&, Geometry2 const&,
  58. distance::detail::enable_if_ps_t<Geometry1, Geometry2> * = nullptr) const
  59. {
  60. return strategy::distance::cross_track
  61. <
  62. CalculationType,
  63. strategy::distance::haversine<typename base_t::radius_type, CalculationType>
  64. >(base_t::radius());
  65. }
  66. // For equals()
  67. template <typename Geometry1, typename Geometry2>
  68. static auto relate(Geometry1 const&, Geometry2 const&,
  69. std::enable_if_t
  70. <
  71. util::is_pointlike<Geometry1>::value
  72. && util::is_pointlike<Geometry2>::value
  73. > * = nullptr)
  74. {
  75. return strategy::within::spherical_point_point();
  76. }
  77. };
  78. namespace services
  79. {
  80. template <typename Geometry>
  81. struct default_strategy<Geometry, spherical_equatorial_tag>
  82. {
  83. using type = strategies::simplify::spherical<>;
  84. };
  85. template <typename P, typename CT, typename S>
  86. struct strategy_converter
  87. <
  88. strategy::simplify::douglas_peucker
  89. <
  90. P,
  91. strategy::distance::cross_track<CT, S>
  92. >
  93. >
  94. {
  95. template <typename Strategy>
  96. static auto get(Strategy const& )
  97. {
  98. return strategies::simplify::spherical<typename S::radius_type, CT>();
  99. }
  100. };
  101. template <typename P, typename CT, typename S>
  102. struct strategy_converter
  103. <
  104. strategy::simplify::douglas_peucker
  105. <
  106. P,
  107. strategy::distance::comparable::cross_track<CT, S>
  108. >
  109. >
  110. {
  111. template <typename Strategy>
  112. static auto get(Strategy const& )
  113. {
  114. return strategies::distance::detail::comparable
  115. <
  116. strategies::simplify::spherical<typename S::radius_type, CT>
  117. >();
  118. }
  119. };
  120. } // namespace services
  121. }} // namespace strategies::simplify
  122. }} // namespace boost::geometry
  123. #endif // BOOST_GEOMETRY_STRATEGIES_SIMPLIFY_SPHERICAL_HPP