cartesian.hpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. // Boost.Geometry
  2. // Copyright (c) 2025 Adam Wulkiewicz, Lodz, Poland.
  3. // Copyright (c) 2021, Oracle and/or its affiliates.
  4. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  5. // Licensed under the Boost Software License version 1.0.
  6. // http://www.boost.org/users/license.html
  7. #ifndef BOOST_GEOMETRY_STRATEGIES_CENTROID_CARTESIAN_HPP
  8. #define BOOST_GEOMETRY_STRATEGIES_CENTROID_CARTESIAN_HPP
  9. #include <boost/geometry/strategies/cartesian/centroid_average.hpp>
  10. #include <boost/geometry/strategies/cartesian/centroid_bashein_detmer.hpp>
  11. #include <boost/geometry/strategies/cartesian/centroid_weighted_length.hpp>
  12. #include <boost/geometry/strategies/detail.hpp>
  13. #include <boost/geometry/strategies/centroid/services.hpp>
  14. #include <boost/geometry/util/type_traits.hpp>
  15. namespace boost { namespace geometry
  16. {
  17. namespace strategies { namespace centroid
  18. {
  19. #ifndef DOXYGEN_NO_DETAIL
  20. namespace detail
  21. {
  22. template <typename CalculationType = void>
  23. struct cartesian
  24. {
  25. template <typename Geometry>
  26. static auto centroid(Geometry const&,
  27. std::enable_if_t
  28. <
  29. util::is_pointlike<Geometry>::value
  30. > * = nullptr)
  31. {
  32. return strategy::centroid::average<>();
  33. }
  34. template <typename Geometry>
  35. static auto centroid(Geometry const&,
  36. std::enable_if_t
  37. <
  38. util::is_polylinear<Geometry>::value
  39. > * = nullptr)
  40. {
  41. return strategy::centroid::weighted_length<void, void, CalculationType>();
  42. }
  43. template <typename Geometry>
  44. static auto centroid(Geometry const&,
  45. std::enable_if_t
  46. <
  47. util::is_polygonal<Geometry>::value
  48. // TODO: This condition was used for the legacy default strategy
  49. // && geometry::dimension<Geometry>::value == 2
  50. > * = nullptr)
  51. {
  52. return strategy::centroid::bashein_detmer<void, void, CalculationType>();
  53. }
  54. // TODO: Box and Segment should have proper strategies.
  55. template <typename Geometry, typename Point>
  56. static auto centroid(Geometry const&, Point const&,
  57. std::enable_if_t
  58. <
  59. util::is_segment<Geometry>::value
  60. || util::is_box<Geometry>::value
  61. > * = nullptr)
  62. {
  63. return strategy::centroid::not_applicable_strategy();
  64. }
  65. };
  66. } // namespace detail
  67. #endif // DOXYGEN_NO_DETAIL
  68. template <typename CalculationType = void>
  69. struct cartesian
  70. : public strategies::detail::cartesian_base
  71. , public strategies::centroid::detail::cartesian<CalculationType>
  72. {};
  73. namespace services
  74. {
  75. template <typename Geometry>
  76. struct default_strategy<Geometry, cartesian_tag>
  77. {
  78. using type = strategies::centroid::cartesian<>;
  79. };
  80. template <typename PC, typename PG>
  81. struct strategy_converter<strategy::centroid::average<PC, PG> >
  82. {
  83. static auto get(strategy::centroid::average<PC, PG> const&)
  84. {
  85. return strategies::centroid::cartesian<>();
  86. }
  87. };
  88. template <typename PC, typename PG>
  89. struct strategy_converter<strategy::centroid::weighted_length<PC, PG> >
  90. {
  91. static auto get(strategy::centroid::weighted_length<PC, PG> const&)
  92. {
  93. return strategies::centroid::cartesian<>();
  94. }
  95. };
  96. template <typename PC, typename PG, typename CT>
  97. struct strategy_converter<strategy::centroid::bashein_detmer<PC, PG, CT> >
  98. {
  99. static auto get(strategy::centroid::bashein_detmer<PC, PG, CT> const&)
  100. {
  101. return strategies::centroid::cartesian<CT>();
  102. }
  103. };
  104. } // namespace services
  105. }} // namespace strategies::centroid
  106. }} // namespace boost::geometry
  107. #endif // BOOST_GEOMETRY_STRATEGIES_CENTROID_CARTESIAN_HPP