cartesian.hpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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_CENTROID_CARTESIAN_HPP
  7. #define BOOST_GEOMETRY_STRATEGIES_CENTROID_CARTESIAN_HPP
  8. #include <boost/geometry/strategies/cartesian/centroid_average.hpp>
  9. #include <boost/geometry/strategies/cartesian/centroid_bashein_detmer.hpp>
  10. #include <boost/geometry/strategies/cartesian/centroid_weighted_length.hpp>
  11. #include <boost/geometry/strategies/detail.hpp>
  12. #include <boost/geometry/strategies/centroid/services.hpp>
  13. #include <boost/geometry/util/type_traits.hpp>
  14. namespace boost { namespace geometry
  15. {
  16. namespace strategies { namespace centroid
  17. {
  18. template <typename CalculationType = void>
  19. struct cartesian
  20. : public strategies::detail::cartesian_base
  21. {
  22. template <typename Geometry>
  23. static auto centroid(Geometry const&,
  24. std::enable_if_t
  25. <
  26. util::is_pointlike<Geometry>::value
  27. > * = nullptr)
  28. {
  29. return strategy::centroid::average<>();
  30. }
  31. template <typename Geometry>
  32. static auto centroid(Geometry const&,
  33. std::enable_if_t
  34. <
  35. util::is_polylinear<Geometry>::value
  36. > * = nullptr)
  37. {
  38. return strategy::centroid::weighted_length<void, void, CalculationType>();
  39. }
  40. template <typename Geometry>
  41. static auto centroid(Geometry const&,
  42. std::enable_if_t
  43. <
  44. util::is_polygonal<Geometry>::value
  45. // TODO: This condition was used for the legacy default strategy
  46. // && geometry::dimension<Geometry>::value == 2
  47. > * = nullptr)
  48. {
  49. return strategy::centroid::bashein_detmer<void, void, CalculationType>();
  50. }
  51. // TODO: Box and Segment should have proper strategies.
  52. template <typename Geometry, typename Point>
  53. static auto centroid(Geometry const&, Point const&,
  54. std::enable_if_t
  55. <
  56. util::is_segment<Geometry>::value
  57. || util::is_box<Geometry>::value
  58. > * = nullptr)
  59. {
  60. return strategy::centroid::not_applicable_strategy();
  61. }
  62. };
  63. namespace services
  64. {
  65. template <typename Geometry>
  66. struct default_strategy<Geometry, cartesian_tag>
  67. {
  68. using type = strategies::centroid::cartesian<>;
  69. };
  70. template <typename PC, typename PG>
  71. struct strategy_converter<strategy::centroid::average<PC, PG> >
  72. {
  73. static auto get(strategy::centroid::average<PC, PG> const&)
  74. {
  75. return strategies::centroid::cartesian<>();
  76. }
  77. };
  78. template <typename PC, typename PG>
  79. struct strategy_converter<strategy::centroid::weighted_length<PC, PG> >
  80. {
  81. static auto get(strategy::centroid::weighted_length<PC, PG> const&)
  82. {
  83. return strategies::centroid::cartesian<>();
  84. }
  85. };
  86. template <typename PC, typename PG, typename CT>
  87. struct strategy_converter<strategy::centroid::bashein_detmer<PC, PG, CT> >
  88. {
  89. static auto get(strategy::centroid::bashein_detmer<PC, PG, CT> const&)
  90. {
  91. return strategies::centroid::cartesian<CT>();
  92. }
  93. };
  94. } // namespace services
  95. }} // namespace strategies::centroid
  96. }} // namespace boost::geometry
  97. #endif // BOOST_GEOMETRY_STRATEGIES_CENTROID_CARTESIAN_HPP