distance_concept.hpp 6.5 KB

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