distance_result.hpp 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
  3. // Copyright (c) 2008-2015 Bruno Lalande, Paris, France.
  4. // Copyright (c) 2009-2015 Mateusz Loskot, London, UK.
  5. // Copyright (c) 2013-2015 Adam Wulkiewicz, Lodz, Poland.
  6. // Copyright (c) 2014-2015 Samuel Debionne, Grenoble, France.
  7. // This file was modified by Oracle on 2014, 2015.
  8. // Modifications copyright (c) 2014-2015, Oracle and/or its affiliates.
  9. // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
  10. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  11. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  12. // Use, modification and distribution is subject to the Boost Software License,
  13. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  14. // http://www.boost.org/LICENSE_1_0.txt)
  15. #ifndef BOOST_GEOMETRY_STRATEGIES_DISTANCE_RESULT_HPP
  16. #define BOOST_GEOMETRY_STRATEGIES_DISTANCE_RESULT_HPP
  17. #include <boost/mpl/always.hpp>
  18. #include <boost/mpl/bool.hpp>
  19. #include <boost/mpl/vector.hpp>
  20. #include <boost/variant/variant_fwd.hpp>
  21. #include <boost/geometry/core/point_type.hpp>
  22. #include <boost/geometry/strategies/default_strategy.hpp>
  23. #include <boost/geometry/strategies/distance.hpp>
  24. #include <boost/geometry/util/compress_variant.hpp>
  25. #include <boost/geometry/util/transform_variant.hpp>
  26. #include <boost/geometry/util/combine_if.hpp>
  27. #include <boost/geometry/algorithms/detail/distance/default_strategies.hpp>
  28. namespace boost { namespace geometry
  29. {
  30. namespace resolve_strategy
  31. {
  32. template <typename Geometry1, typename Geometry2, typename Strategy>
  33. struct distance_result
  34. : strategy::distance::services::return_type
  35. <
  36. Strategy,
  37. typename point_type<Geometry1>::type,
  38. typename point_type<Geometry2>::type
  39. >
  40. {};
  41. template <typename Geometry1, typename Geometry2>
  42. struct distance_result<Geometry1, Geometry2, default_strategy>
  43. : distance_result
  44. <
  45. Geometry1,
  46. Geometry2,
  47. typename detail::distance::default_strategy
  48. <
  49. Geometry1, Geometry2
  50. >::type
  51. >
  52. {};
  53. } // namespace resolve_strategy
  54. namespace resolve_variant
  55. {
  56. template <typename Geometry1, typename Geometry2, typename Strategy>
  57. struct distance_result
  58. : resolve_strategy::distance_result
  59. <
  60. Geometry1,
  61. Geometry2,
  62. Strategy
  63. >
  64. {};
  65. template
  66. <
  67. typename Geometry1,
  68. BOOST_VARIANT_ENUM_PARAMS(typename T),
  69. typename Strategy
  70. >
  71. struct distance_result
  72. <
  73. Geometry1, boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>, Strategy
  74. >
  75. {
  76. // A set of all variant type combinations that are compatible and
  77. // implemented
  78. typedef typename util::combine_if<
  79. typename boost::mpl::vector1<Geometry1>,
  80. typename boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>::types,
  81. // Here we want should remove most of the combinations that
  82. // are not valid, mostly to limit the size of the resulting MPL set.
  83. // But is_implementedn is not ready for prime time
  84. //
  85. // util::is_implemented2<boost::mpl::_1, boost::mpl::_2, dispatch::distance<boost::mpl::_1, boost::mpl::_2> >
  86. boost::mpl::always<boost::mpl::true_>
  87. >::type possible_input_types;
  88. // The (possibly variant) result type resulting from these combinations
  89. typedef typename compress_variant<
  90. typename transform_variant<
  91. possible_input_types,
  92. resolve_strategy::distance_result<
  93. boost::mpl::first<boost::mpl::_>,
  94. boost::mpl::second<boost::mpl::_>,
  95. Strategy
  96. >,
  97. boost::mpl::back_inserter<boost::mpl::vector0<> >
  98. >::type
  99. >::type type;
  100. };
  101. // Distance arguments are commutative
  102. template
  103. <
  104. BOOST_VARIANT_ENUM_PARAMS(typename T),
  105. typename Geometry2,
  106. typename Strategy
  107. >
  108. struct distance_result
  109. <
  110. boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>,
  111. Geometry2,
  112. Strategy
  113. > : public distance_result
  114. <
  115. Geometry2, boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>, Strategy
  116. >
  117. {};
  118. template <BOOST_VARIANT_ENUM_PARAMS(typename T), typename Strategy>
  119. struct distance_result
  120. <
  121. boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>,
  122. boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>,
  123. Strategy
  124. >
  125. {
  126. // A set of all variant type combinations that are compatible and
  127. // implemented
  128. typedef typename util::combine_if
  129. <
  130. typename boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>::types,
  131. typename boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>::types,
  132. // Here we want to try to remove most of the combinations
  133. // that are not valid, mostly to limit the size of the
  134. // resulting MPL vector.
  135. // But is_implemented is not ready for prime time
  136. //
  137. // util::is_implemented2<boost::mpl::_1, boost::mpl::_2, dispatch::distance<boost::mpl::_1, boost::mpl::_2> >
  138. boost::mpl::always<boost::mpl::true_>
  139. >::type possible_input_types;
  140. // The (possibly variant) result type resulting from these combinations
  141. typedef typename compress_variant<
  142. typename transform_variant<
  143. possible_input_types,
  144. resolve_strategy::distance_result<
  145. boost::mpl::first<boost::mpl::_>,
  146. boost::mpl::second<boost::mpl::_>,
  147. Strategy
  148. >,
  149. boost::mpl::back_inserter<boost::mpl::vector0<> >
  150. >::type
  151. >::type type;
  152. };
  153. } // namespace resolve_variant
  154. /*!
  155. \brief Meta-function defining return type of distance function
  156. \ingroup distance
  157. \note The strategy defines the return-type (so this situation is different
  158. from length, where distance is sqr/sqrt, but length always squared)
  159. */
  160. template
  161. <
  162. typename Geometry1,
  163. typename Geometry2 = Geometry1,
  164. typename Strategy = void
  165. >
  166. struct distance_result
  167. : resolve_variant::distance_result<Geometry1, Geometry2, Strategy>
  168. {};
  169. template <typename Geometry1, typename Geometry2>
  170. struct distance_result<Geometry1, Geometry2, void>
  171. : distance_result<Geometry1, Geometry2, default_strategy>
  172. {};
  173. }} // namespace boost::geometry
  174. #endif // BOOST_GEOMETRY_STRATEGIES_DISTANCE_RESULT_HPP