distance_concept.hpp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands.
  3. // Copyright (c) 2008-2014 Bruno Lalande, Paris, France.
  4. // Copyright (c) 2009-2014 Mateusz Loskot, London, UK.
  5. // This file was modified by Oracle on 2014.
  6. // Modifications copyright (c) 2014, Oracle and/or its affiliates.
  7. // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
  8. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  9. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  10. // Use, modification and distribution is subject to the Boost Software License,
  11. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  12. // http://www.boost.org/LICENSE_1_0.txt)
  13. #ifndef BOOST_GEOMETRY_STRATEGIES_CONCEPTS_DISTANCE_CONCEPT_HPP
  14. #define BOOST_GEOMETRY_STRATEGIES_CONCEPTS_DISTANCE_CONCEPT_HPP
  15. #include <vector>
  16. #include <iterator>
  17. #include <boost/concept_check.hpp>
  18. #include <boost/core/ignore_unused.hpp>
  19. #include <boost/mpl/assert.hpp>
  20. #include <boost/type_traits/is_same.hpp>
  21. #include <boost/geometry/util/parameter_type_of.hpp>
  22. #include <boost/geometry/geometries/concepts/point_concept.hpp>
  23. #include <boost/geometry/geometries/segment.hpp>
  24. #include <boost/geometry/geometries/point.hpp>
  25. #include <boost/geometry/strategies/tags.hpp>
  26. namespace boost { namespace geometry { namespace concepts
  27. {
  28. /*!
  29. \brief Checks strategy for point-point or point-box or box-box distance
  30. \ingroup distance
  31. */
  32. template <typename Strategy, typename Point1, typename Point2>
  33. struct PointDistanceStrategy
  34. {
  35. #ifndef DOXYGEN_NO_CONCEPT_MEMBERS
  36. private :
  37. struct checker
  38. {
  39. template <typename ApplyMethod>
  40. static void apply(ApplyMethod)
  41. {
  42. // 1: inspect and define both arguments of apply
  43. typedef typename parameter_type_of
  44. <
  45. ApplyMethod, 0
  46. >::type ptype1;
  47. typedef typename parameter_type_of
  48. <
  49. ApplyMethod, 1
  50. >::type ptype2;
  51. // 2) must define meta-function "return_type"
  52. typedef typename strategy::distance::services::return_type
  53. <
  54. Strategy, ptype1, ptype2
  55. >::type rtype;
  56. // 3) must define meta-function "comparable_type"
  57. typedef typename strategy::distance::services::comparable_type
  58. <
  59. Strategy
  60. >::type ctype;
  61. // 4) must define meta-function "tag"
  62. typedef typename strategy::distance::services::tag
  63. <
  64. Strategy
  65. >::type tag;
  66. static const bool is_correct_strategy_tag =
  67. boost::is_same<tag, strategy_tag_distance_point_point>::value
  68. || boost::is_same<tag, strategy_tag_distance_point_box>::value
  69. || boost::is_same<tag, strategy_tag_distance_box_box>::value;
  70. BOOST_MPL_ASSERT_MSG
  71. ((is_correct_strategy_tag),
  72. INCORRECT_STRATEGY_TAG,
  73. (types<tag>));
  74. // 5) must implement apply with arguments
  75. Strategy* str = 0;
  76. ptype1 *p1 = 0;
  77. ptype2 *p2 = 0;
  78. rtype r = str->apply(*p1, *p2);
  79. // 6) must define (meta)struct "get_comparable" with apply
  80. ctype c = strategy::distance::services::get_comparable
  81. <
  82. Strategy
  83. >::apply(*str);
  84. // 7) must define (meta)struct "result_from_distance" with apply
  85. r = strategy::distance::services::result_from_distance
  86. <
  87. Strategy,
  88. ptype1, ptype2
  89. >::apply(*str, 1.0);
  90. boost::ignore_unused<tag>();
  91. boost::ignore_unused(str, c, r);
  92. }
  93. };
  94. public :
  95. BOOST_CONCEPT_USAGE(PointDistanceStrategy)
  96. {
  97. checker::apply(&Strategy::template apply<Point1, Point2>);
  98. }
  99. #endif
  100. };
  101. /*!
  102. \brief Checks strategy for point-segment distance
  103. \ingroup strategy_concepts
  104. */
  105. template <typename Strategy, typename Point, typename PointOfSegment>
  106. struct PointSegmentDistanceStrategy
  107. {
  108. #ifndef DOXYGEN_NO_CONCEPT_MEMBERS
  109. private :
  110. struct checker
  111. {
  112. template <typename ApplyMethod>
  113. static void apply(ApplyMethod)
  114. {
  115. // 1) inspect and define both arguments of apply
  116. typedef typename parameter_type_of
  117. <
  118. ApplyMethod, 0
  119. >::type ptype;
  120. typedef typename parameter_type_of
  121. <
  122. ApplyMethod, 1
  123. >::type sptype;
  124. namespace services = strategy::distance::services;
  125. // 2) must define meta-function "tag"
  126. typedef typename services::tag<Strategy>::type tag;
  127. BOOST_MPL_ASSERT_MSG
  128. ((boost::is_same
  129. <
  130. tag, strategy_tag_distance_point_segment
  131. >::value),
  132. INCORRECT_STRATEGY_TAG,
  133. (types<tag>));
  134. // 3) must define meta-function "return_type"
  135. typedef typename services::return_type
  136. <
  137. Strategy, ptype, sptype
  138. >::type rtype;
  139. // 4) must define meta-function "comparable_type"
  140. typedef typename services::comparable_type<Strategy>::type ctype;
  141. // 5) must implement apply with arguments
  142. Strategy *str = 0;
  143. ptype *p = 0;
  144. sptype *sp1 = 0;
  145. sptype *sp2 = 0;
  146. rtype r = str->apply(*p, *sp1, *sp2);
  147. // 6) must define (meta-)struct "get_comparable" with apply
  148. ctype cstrategy = services::get_comparable<Strategy>::apply(*str);
  149. // 7) must define (meta-)struct "result_from_distance" with apply
  150. r = services::result_from_distance
  151. <
  152. Strategy, ptype, sptype
  153. >::apply(*str, rtype(1.0));
  154. boost::ignore_unused(str, r, cstrategy);
  155. }
  156. };
  157. public :
  158. BOOST_CONCEPT_USAGE(PointSegmentDistanceStrategy)
  159. {
  160. checker::apply(&Strategy::template apply<Point, PointOfSegment>);
  161. }
  162. #endif
  163. };
  164. }}} // namespace boost::geometry::concepts
  165. #endif // BOOST_GEOMETRY_STRATEGIES_CONCEPTS_DISTANCE_CONCEPT_HPP