intersects.hpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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_INTERSECTS_HPP
  11. #define BOOST_GEOMETRY_ALGORITHMS_INTERSECTS_HPP
  12. #include <deque>
  13. #include <boost/geometry/geometries/concepts/check.hpp>
  14. #include <boost/geometry/algorithms/detail/overlay/self_turn_points.hpp>
  15. #include <boost/geometry/algorithms/disjoint.hpp>
  16. namespace boost { namespace geometry
  17. {
  18. /*!
  19. \brief \brief_check{has at least one intersection (crossing or self-tangency)}
  20. \note This function can be called for one geometry (self-intersection) and
  21. also for two geometries (intersection)
  22. \ingroup intersects
  23. \tparam Geometry \tparam_geometry
  24. \param geometry \param_geometry
  25. \return \return_check{is self-intersecting}
  26. \qbk{distinguish,one geometry}
  27. \qbk{[def __one_parameter__]}
  28. \qbk{[include reference/algorithms/intersects.qbk]}
  29. */
  30. template <typename Geometry>
  31. inline bool intersects(Geometry const& geometry)
  32. {
  33. concept::check<Geometry const>();
  34. typedef detail::overlay::turn_info
  35. <
  36. typename geometry::point_type<Geometry>::type
  37. > turn_info;
  38. std::deque<turn_info> turns;
  39. typedef typename strategy_intersection
  40. <
  41. typename cs_tag<Geometry>::type,
  42. Geometry,
  43. Geometry,
  44. typename geometry::point_type<Geometry>::type
  45. >::segment_intersection_strategy_type segment_intersection_strategy_type;
  46. typedef detail::overlay::get_turn_info
  47. <
  48. typename point_type<Geometry>::type,
  49. typename point_type<Geometry>::type,
  50. turn_info,
  51. detail::overlay::assign_null_policy
  52. > TurnPolicy;
  53. detail::disjoint::disjoint_interrupt_policy policy;
  54. detail::self_get_turn_points::get_turns
  55. <
  56. Geometry,
  57. std::deque<turn_info>,
  58. TurnPolicy,
  59. detail::disjoint::disjoint_interrupt_policy
  60. >::apply(geometry, turns, policy);
  61. return policy.has_intersections;
  62. }
  63. /*!
  64. \brief \brief_check2{have at least one intersection}
  65. \ingroup intersects
  66. \tparam Geometry1 \tparam_geometry
  67. \tparam Geometry2 \tparam_geometry
  68. \param geometry1 \param_geometry
  69. \param geometry2 \param_geometry
  70. \return \return_check2{intersect each other}
  71. \qbk{distinguish,two geometries}
  72. \qbk{[include reference/algorithms/intersects.qbk]}
  73. */
  74. template <typename Geometry1, typename Geometry2>
  75. inline bool intersects(Geometry1 const& geometry1, Geometry2 const& geometry2)
  76. {
  77. concept::check<Geometry1 const>();
  78. concept::check<Geometry2 const>();
  79. return ! geometry::disjoint(geometry1, geometry2);
  80. }
  81. }} // namespace boost::geometry
  82. #endif // BOOST_GEOMETRY_ALGORITHMS_INTERSECTS_HPP