within.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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_MULTI_ALGORITHMS_WITHIN_HPP
  11. #define BOOST_GEOMETRY_MULTI_ALGORITHMS_WITHIN_HPP
  12. #include <boost/range.hpp>
  13. #include <boost/geometry/algorithms/within.hpp>
  14. #include <boost/geometry/multi/core/closure.hpp>
  15. #include <boost/geometry/multi/core/point_order.hpp>
  16. #include <boost/geometry/multi/core/tags.hpp>
  17. #include <boost/geometry/multi/geometries/concepts/check.hpp>
  18. namespace boost { namespace geometry
  19. {
  20. #ifndef DOXYGEN_NO_DETAIL
  21. namespace detail { namespace within
  22. {
  23. template
  24. <
  25. typename Geometry,
  26. typename MultiGeometry,
  27. typename Strategy,
  28. typename Policy
  29. >
  30. struct geometry_multi_within_code
  31. {
  32. static inline int apply(Geometry const& geometry,
  33. MultiGeometry const& multi,
  34. Strategy const& strategy)
  35. {
  36. for (typename boost::range_iterator<MultiGeometry const>::type it
  37. = boost::begin(multi);
  38. it != boost::end(multi);
  39. ++it)
  40. {
  41. // Geometry coding on multi: 1 (within) if within one of them;
  42. // 0 (touch) if on border of one of them
  43. int const code = Policy::apply(geometry, *it, strategy);
  44. if (code != -1)
  45. {
  46. return code;
  47. }
  48. }
  49. return -1;
  50. }
  51. };
  52. }} // namespace detail::within
  53. #endif // DOXYGEN_NO_DETAIL
  54. #ifndef DOXYGEN_NO_DISPATCH
  55. namespace dispatch
  56. {
  57. template <typename Point, typename MultiPolygon>
  58. struct within<Point, MultiPolygon, point_tag, multi_polygon_tag>
  59. {
  60. template <typename Strategy>
  61. static inline bool apply(Point const& point,
  62. MultiPolygon const& multi_polygon, Strategy const& strategy)
  63. {
  64. return detail::within::geometry_multi_within_code
  65. <
  66. Point,
  67. MultiPolygon,
  68. Strategy,
  69. detail::within::point_in_polygon
  70. <
  71. Point,
  72. typename boost::range_value<MultiPolygon>::type,
  73. order_as_direction
  74. <
  75. geometry::point_order<MultiPolygon>::value
  76. >::value,
  77. geometry::closure<MultiPolygon>::value,
  78. Strategy
  79. >
  80. >::apply(point, multi_polygon, strategy) == 1;
  81. }
  82. };
  83. } // namespace dispatch
  84. #endif // DOXYGEN_NO_DISPATCH
  85. }} // namespace boost::geometry
  86. #endif // BOOST_GEOMETRY_MULTI_ALGORITHMS_WITHIN_HPP