area_result.hpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. // Boost.Geometry
  2. // Copyright (c) 2017 Adam Wulkiewicz, Lodz, Poland.
  3. // This file was modified by Oracle on 2020.
  4. // Modifications copyright (c) 2020 Oracle and/or its affiliates.
  5. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  6. // Use, modification and distribution is subject to the Boost Software License,
  7. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt)
  9. #ifndef BOOST_GEOMETRY_ALGORITHMS_AREA_RESULT_HPP
  10. #define BOOST_GEOMETRY_ALGORITHMS_AREA_RESULT_HPP
  11. #include <type_traits>
  12. #include <boost/geometry/core/coordinate_type.hpp>
  13. #include <boost/geometry/core/cs.hpp>
  14. #include <boost/geometry/strategies/area/services.hpp>
  15. #include <boost/geometry/strategies/default_strategy.hpp>
  16. #include <boost/geometry/strategies/detail.hpp>
  17. #include <boost/geometry/strategy/area.hpp>
  18. #include <boost/geometry/util/select_most_precise.hpp>
  19. #include <boost/geometry/util/sequence.hpp>
  20. #include <boost/geometry/util/type_traits.hpp>
  21. #include <boost/variant/variant_fwd.hpp>
  22. namespace boost { namespace geometry
  23. {
  24. #ifndef DOXYGEN_NO_DETAIL
  25. namespace detail { namespace area
  26. {
  27. template
  28. <
  29. typename Geometry,
  30. typename Strategy,
  31. bool IsUmbrella = strategies::detail::is_umbrella_strategy<Strategy>::value
  32. >
  33. struct area_result
  34. {
  35. typedef decltype(std::declval<Strategy>().area(std::declval<Geometry>())) strategy_type;
  36. typedef typename strategy_type::template result_type<Geometry>::type type;
  37. };
  38. template <typename Geometry, typename Strategy>
  39. struct area_result<Geometry, Strategy, false>
  40. {
  41. typedef typename Strategy::template result_type<Geometry>::type type;
  42. };
  43. template
  44. <
  45. typename Geometry,
  46. bool IsGeometry = util::is_geometry<Geometry>::value
  47. >
  48. struct default_area_result
  49. : area_result
  50. <
  51. Geometry,
  52. typename geometry::strategies::area::services::default_strategy
  53. <
  54. Geometry
  55. >::type
  56. >
  57. {};
  58. // Workaround for VS2015
  59. #if defined(_MSC_VER) && (_MSC_VER < 1910)
  60. template
  61. <
  62. typename Geometry,
  63. bool IsGeometry = util::is_geometry<Geometry>::value
  64. >
  65. struct coordinate_type
  66. : geometry::coordinate_type<Geometry>
  67. {};
  68. template <typename Geometry>
  69. struct coordinate_type<Geometry, false>
  70. {
  71. typedef int type;
  72. };
  73. template <typename Geometry>
  74. struct default_area_result<Geometry, false>
  75. {
  76. typedef int type;
  77. };
  78. #endif
  79. template <typename Curr, typename Next>
  80. struct more_precise_coordinate_type
  81. : std::is_same
  82. <
  83. typename coordinate_type<Curr>::type,
  84. typename geometry::select_most_precise
  85. <
  86. typename coordinate_type<Curr>::type,
  87. typename coordinate_type<Next>::type
  88. >::type
  89. >
  90. {};
  91. template <typename Curr, typename Next>
  92. struct more_precise_default_area_result
  93. : std::is_same
  94. <
  95. typename default_area_result<Curr>::type,
  96. typename geometry::select_most_precise
  97. <
  98. typename default_area_result<Curr>::type,
  99. typename default_area_result<Next>::type
  100. >::type
  101. >
  102. {};
  103. }} // namespace detail::area
  104. #endif //DOXYGEN_NO_DETAIL
  105. /*!
  106. \brief Meta-function defining return type of area function
  107. \ingroup area
  108. \note The return-type is defined by Geometry and Strategy
  109. */
  110. template
  111. <
  112. typename Geometry,
  113. typename Strategy = default_strategy
  114. >
  115. struct area_result
  116. : detail::area::area_result<Geometry, Strategy>
  117. {};
  118. template <BOOST_VARIANT_ENUM_PARAMS(typename T), typename Strategy>
  119. struct area_result<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>, Strategy>
  120. : geometry::area_result
  121. <
  122. typename util::select_pack_element
  123. <
  124. detail::area::more_precise_coordinate_type,
  125. BOOST_VARIANT_ENUM_PARAMS(T)
  126. >::type,
  127. Strategy
  128. >
  129. {};
  130. template <typename Geometry>
  131. struct area_result<Geometry, default_strategy>
  132. : detail::area::default_area_result<Geometry>
  133. {};
  134. template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
  135. struct area_result<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>, default_strategy>
  136. : detail::area::default_area_result
  137. <
  138. typename util::select_pack_element
  139. <
  140. detail::area::more_precise_default_area_result,
  141. BOOST_VARIANT_ENUM_PARAMS(T)
  142. >::type
  143. >
  144. {};
  145. }} // namespace boost::geometry
  146. #endif // BOOST_GEOMETRY_ALGORITHMS_AREA_RESULT_HPP