area_result.hpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. // Boost.Geometry
  2. // Copyright (c) 2017 Adam Wulkiewicz, Lodz, Poland.
  3. // This file was modified by Oracle on 2020-2023.
  4. // Modifications copyright (c) 2020-2023 Oracle and/or its affiliates.
  5. // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
  6. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  7. // Use, modification and distribution is subject to the Boost Software License,
  8. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  9. // http://www.boost.org/LICENSE_1_0.txt)
  10. #ifndef BOOST_GEOMETRY_ALGORITHMS_AREA_RESULT_HPP
  11. #define BOOST_GEOMETRY_ALGORITHMS_AREA_RESULT_HPP
  12. #include <type_traits>
  13. #include <boost/geometry/algorithms/detail/select_geometry_type.hpp>
  14. #include <boost/geometry/core/coordinate_type.hpp>
  15. #include <boost/geometry/strategies/area/services.hpp>
  16. #include <boost/geometry/strategies/default_strategy.hpp>
  17. #include <boost/geometry/strategies/detail.hpp>
  18. #include <boost/geometry/util/select_most_precise.hpp>
  19. namespace boost { namespace geometry
  20. {
  21. #ifndef DOXYGEN_NO_DETAIL
  22. namespace detail { namespace area
  23. {
  24. template
  25. <
  26. typename Geometry,
  27. typename Strategy,
  28. bool IsUmbrella = strategies::detail::is_umbrella_strategy<Strategy>::value
  29. >
  30. struct area_result
  31. {
  32. typedef decltype(std::declval<Strategy>().area(std::declval<Geometry>())) strategy_type;
  33. typedef typename strategy_type::template result_type<Geometry>::type type;
  34. };
  35. template <typename Geometry, typename Strategy>
  36. struct area_result<Geometry, Strategy, false>
  37. {
  38. typedef typename Strategy::template result_type<Geometry>::type type;
  39. };
  40. template <typename Geometry>
  41. struct default_area_result
  42. : area_result
  43. <
  44. Geometry,
  45. typename geometry::strategies::area::services::default_strategy
  46. <
  47. Geometry
  48. >::type
  49. >
  50. {};
  51. template <typename Curr, typename Next>
  52. struct more_precise_coordinate_type
  53. : std::is_same
  54. <
  55. typename geometry::coordinate_type<Curr>::type,
  56. typename geometry::select_most_precise
  57. <
  58. typename geometry::coordinate_type<Curr>::type,
  59. typename geometry::coordinate_type<Next>::type
  60. >::type
  61. >
  62. {};
  63. template <typename Curr, typename Next>
  64. struct more_precise_default_area_result
  65. : std::is_same
  66. <
  67. typename default_area_result<Curr>::type,
  68. typename geometry::select_most_precise
  69. <
  70. typename default_area_result<Curr>::type,
  71. typename default_area_result<Next>::type
  72. >::type
  73. >
  74. {};
  75. }} // namespace detail::area
  76. #endif //DOXYGEN_NO_DETAIL
  77. /*!
  78. \brief Meta-function defining return type of area function
  79. \ingroup area
  80. \note The return-type is defined by Geometry and Strategy
  81. */
  82. template
  83. <
  84. typename Geometry,
  85. typename Strategy = default_strategy
  86. >
  87. struct area_result
  88. : detail::area::area_result
  89. <
  90. typename detail::select_geometry_type
  91. <
  92. Geometry,
  93. detail::area::more_precise_coordinate_type
  94. >::type,
  95. Strategy
  96. >
  97. {};
  98. template <typename Geometry>
  99. struct area_result<Geometry, default_strategy>
  100. : detail::area::default_area_result
  101. <
  102. typename detail::select_geometry_type
  103. <
  104. Geometry,
  105. detail::area::more_precise_default_area_result
  106. >::type
  107. >
  108. {};
  109. }} // namespace boost::geometry
  110. #endif // BOOST_GEOMETRY_ALGORITHMS_AREA_RESULT_HPP