distance_concept.hpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
  3. // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
  4. // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
  5. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  6. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  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_STRATEGIES_CONCEPTS_DISTANCE_CONCEPT_HPP
  11. #define BOOST_GEOMETRY_STRATEGIES_CONCEPTS_DISTANCE_CONCEPT_HPP
  12. #include <vector>
  13. #include <iterator>
  14. #include <boost/concept_check.hpp>
  15. #include <boost/geometry/util/parameter_type_of.hpp>
  16. #include <boost/geometry/geometries/concepts/point_concept.hpp>
  17. #include <boost/geometry/geometries/segment.hpp>
  18. #include <boost/geometry/geometries/point.hpp>
  19. namespace boost { namespace geometry { namespace concept
  20. {
  21. /*!
  22. \brief Checks strategy for point-segment-distance
  23. \ingroup distance
  24. */
  25. template <typename Strategy, typename Point1, typename Point2>
  26. struct PointDistanceStrategy
  27. {
  28. #ifndef DOXYGEN_NO_CONCEPT_MEMBERS
  29. private :
  30. struct checker
  31. {
  32. template <typename ApplyMethod>
  33. static void apply(ApplyMethod)
  34. {
  35. // 1: inspect and define both arguments of apply
  36. typedef typename parameter_type_of
  37. <
  38. ApplyMethod, 0
  39. >::type ptype1;
  40. typedef typename parameter_type_of
  41. <
  42. ApplyMethod, 1
  43. >::type ptype2;
  44. // 2) must define meta-function return_type
  45. typedef typename strategy::distance::services::return_type
  46. <
  47. Strategy, ptype1, ptype2
  48. >::type rtype;
  49. // 3) must define meta-function "comparable_type"
  50. typedef typename strategy::distance::services::comparable_type
  51. <
  52. Strategy
  53. >::type ctype;
  54. // 4) must define meta-function "tag"
  55. typedef typename strategy::distance::services::tag
  56. <
  57. Strategy
  58. >::type tag;
  59. // 5) must implement apply with arguments
  60. Strategy* str = 0;
  61. ptype1 *p1 = 0;
  62. ptype2 *p2 = 0;
  63. rtype r = str->apply(*p1, *p2);
  64. // 6) must define (meta)struct "get_comparable" with apply
  65. ctype c = strategy::distance::services::get_comparable
  66. <
  67. Strategy
  68. >::apply(*str);
  69. // 7) must define (meta)struct "result_from_distance" with apply
  70. r = strategy::distance::services::result_from_distance
  71. <
  72. Strategy,
  73. ptype1, ptype2
  74. >::apply(*str, 1.0);
  75. boost::ignore_unused_variable_warning(str);
  76. boost::ignore_unused_variable_warning(c);
  77. boost::ignore_unused_variable_warning(r);
  78. }
  79. };
  80. public :
  81. BOOST_CONCEPT_USAGE(PointDistanceStrategy)
  82. {
  83. checker::apply(&Strategy::template apply<Point1, Point2>);
  84. }
  85. #endif
  86. };
  87. /*!
  88. \brief Checks strategy for point-segment-distance
  89. \ingroup strategy_concepts
  90. */
  91. template <typename Strategy, typename Point, typename PointOfSegment>
  92. struct PointSegmentDistanceStrategy
  93. {
  94. #ifndef DOXYGEN_NO_CONCEPT_MEMBERS
  95. private :
  96. struct checker
  97. {
  98. template <typename ApplyMethod>
  99. static void apply(ApplyMethod)
  100. {
  101. typedef typename parameter_type_of
  102. <
  103. ApplyMethod, 0
  104. >::type ptype;
  105. typedef typename parameter_type_of
  106. <
  107. ApplyMethod, 1
  108. >::type sptype;
  109. // 1) must define meta-function return_type
  110. typedef typename strategy::distance::services::return_type<Strategy, ptype, sptype>::type rtype;
  111. // 2) must define underlying point-distance-strategy
  112. typedef typename strategy::distance::services::strategy_point_point<Strategy>::type stype;
  113. BOOST_CONCEPT_ASSERT
  114. (
  115. (concept::PointDistanceStrategy<stype, Point, PointOfSegment>)
  116. );
  117. Strategy *str = 0;
  118. ptype *p = 0;
  119. sptype *sp1 = 0;
  120. sptype *sp2 = 0;
  121. rtype r = str->apply(*p, *sp1, *sp2);
  122. boost::ignore_unused_variable_warning(str);
  123. boost::ignore_unused_variable_warning(r);
  124. }
  125. };
  126. public :
  127. BOOST_CONCEPT_USAGE(PointSegmentDistanceStrategy)
  128. {
  129. checker::apply(&Strategy::template apply<Point, PointOfSegment>);
  130. }
  131. #endif
  132. };
  133. }}} // namespace boost::geometry::concept
  134. #endif // BOOST_GEOMETRY_STRATEGIES_CONCEPTS_DISTANCE_CONCEPT_HPP