covered_by.hpp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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_ALGORITHMS_COVERED_BY_HPP
  11. #define BOOST_GEOMETRY_ALGORITHMS_COVERED_BY_HPP
  12. #include <cstddef>
  13. #include <boost/geometry/algorithms/not_implemented.hpp>
  14. #include <boost/geometry/algorithms/within.hpp>
  15. #include <boost/geometry/strategies/cartesian/point_in_box.hpp>
  16. #include <boost/geometry/strategies/cartesian/box_in_box.hpp>
  17. namespace boost { namespace geometry
  18. {
  19. #ifndef DOXYGEN_NO_DISPATCH
  20. namespace dispatch
  21. {
  22. template
  23. <
  24. typename Geometry1,
  25. typename Geometry2,
  26. typename Tag1 = typename tag<Geometry1>::type,
  27. typename Tag2 = typename tag<Geometry2>::type
  28. >
  29. struct covered_by: not_implemented<Tag1, Tag2>
  30. {};
  31. template <typename Point, typename Box>
  32. struct covered_by<Point, Box, point_tag, box_tag>
  33. {
  34. template <typename Strategy>
  35. static inline bool apply(Point const& point, Box const& box, Strategy const& strategy)
  36. {
  37. ::boost::ignore_unused_variable_warning(strategy);
  38. return strategy.apply(point, box);
  39. }
  40. };
  41. template <typename Box1, typename Box2>
  42. struct covered_by<Box1, Box2, box_tag, box_tag>
  43. {
  44. template <typename Strategy>
  45. static inline bool apply(Box1 const& box1, Box2 const& box2, Strategy const& strategy)
  46. {
  47. assert_dimension_equal<Box1, Box2>();
  48. ::boost::ignore_unused_variable_warning(strategy);
  49. return strategy.apply(box1, box2);
  50. }
  51. };
  52. template <typename Point, typename Ring>
  53. struct covered_by<Point, Ring, point_tag, ring_tag>
  54. {
  55. template <typename Strategy>
  56. static inline bool apply(Point const& point, Ring const& ring, Strategy const& strategy)
  57. {
  58. return detail::within::point_in_ring
  59. <
  60. Point,
  61. Ring,
  62. order_as_direction<geometry::point_order<Ring>::value>::value,
  63. geometry::closure<Ring>::value,
  64. Strategy
  65. >::apply(point, ring, strategy) >= 0;
  66. }
  67. };
  68. template <typename Point, typename Polygon>
  69. struct covered_by<Point, Polygon, point_tag, polygon_tag>
  70. {
  71. template <typename Strategy>
  72. static inline bool apply(Point const& point, Polygon const& polygon, Strategy const& strategy)
  73. {
  74. return detail::within::point_in_polygon
  75. <
  76. Point,
  77. Polygon,
  78. order_as_direction<geometry::point_order<Polygon>::value>::value,
  79. geometry::closure<Polygon>::value,
  80. Strategy
  81. >::apply(point, polygon, strategy) >= 0;
  82. }
  83. };
  84. } // namespace dispatch
  85. #endif // DOXYGEN_NO_DISPATCH
  86. /*!
  87. \brief \brief_check12{is inside or on border}
  88. \ingroup covered_by
  89. \details \details_check12{covered_by, is inside or on border}.
  90. \tparam Geometry1 \tparam_geometry
  91. \tparam Geometry2 \tparam_geometry
  92. \param geometry1 \param_geometry which might be inside or on the border of the second geometry
  93. \param geometry2 \param_geometry which might cover the first geometry
  94. \return true if geometry1 is inside of or on the border of geometry2,
  95. else false
  96. \note The default strategy is used for covered_by detection
  97. \qbk{[include reference/algorithms/covered_by.qbk]}
  98. */
  99. template<typename Geometry1, typename Geometry2>
  100. inline bool covered_by(Geometry1 const& geometry1, Geometry2 const& geometry2)
  101. {
  102. concept::check<Geometry1 const>();
  103. concept::check<Geometry2 const>();
  104. assert_dimension_equal<Geometry1, Geometry2>();
  105. typedef typename point_type<Geometry1>::type point_type1;
  106. typedef typename point_type<Geometry2>::type point_type2;
  107. typedef typename strategy::covered_by::services::default_strategy
  108. <
  109. typename tag<Geometry1>::type,
  110. typename tag<Geometry2>::type,
  111. typename tag<Geometry1>::type,
  112. typename tag_cast<typename tag<Geometry2>::type, areal_tag>::type,
  113. typename tag_cast
  114. <
  115. typename cs_tag<point_type1>::type, spherical_tag
  116. >::type,
  117. typename tag_cast
  118. <
  119. typename cs_tag<point_type2>::type, spherical_tag
  120. >::type,
  121. Geometry1,
  122. Geometry2
  123. >::type strategy_type;
  124. return dispatch::covered_by
  125. <
  126. Geometry1,
  127. Geometry2
  128. >::apply(geometry1, geometry2, strategy_type());
  129. }
  130. /*!
  131. \brief \brief_check12{is inside or on border} \brief_strategy
  132. \ingroup covered_by
  133. \details \details_check12{covered_by, is inside or on border}, \brief_strategy. \details_strategy_reasons
  134. \tparam Geometry1 \tparam_geometry
  135. \tparam Geometry2 \tparam_geometry
  136. \param geometry1 \param_geometry which might be inside or on the border of the second geometry
  137. \param geometry2 \param_geometry which might cover the first geometry
  138. \param strategy strategy to be used
  139. \return true if geometry1 is inside of or on the border of geometry2,
  140. else false
  141. \qbk{distinguish,with strategy}
  142. \qbk{[include reference/algorithms/covered_by.qbk]}
  143. */
  144. template<typename Geometry1, typename Geometry2, typename Strategy>
  145. inline bool covered_by(Geometry1 const& geometry1, Geometry2 const& geometry2,
  146. Strategy const& strategy)
  147. {
  148. concept::within::check
  149. <
  150. typename tag<Geometry1>::type,
  151. typename tag<Geometry2>::type,
  152. typename tag_cast<typename tag<Geometry2>::type, areal_tag>::type,
  153. Strategy
  154. >();
  155. concept::check<Geometry1 const>();
  156. concept::check<Geometry2 const>();
  157. assert_dimension_equal<Geometry1, Geometry2>();
  158. return dispatch::covered_by
  159. <
  160. Geometry1,
  161. Geometry2
  162. >::apply(geometry1, geometry2, strategy);
  163. }
  164. }} // namespace boost::geometry
  165. #endif // BOOST_GEOMETRY_ALGORITHMS_COVERED_BY_HPP