linear_linear.hpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. // Copyright (c) 2013-2014 Adam Wulkiewicz, Lodz, Poland.
  6. // This file was modified by Oracle on 2013-2017.
  7. // Modifications copyright (c) 2013-2017, Oracle and/or its affiliates.
  8. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  9. // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
  10. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  11. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  12. // Use, modification and distribution is subject to the Boost Software License,
  13. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  14. // http://www.boost.org/LICENSE_1_0.txt)
  15. #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_LINEAR_LINEAR_HPP
  16. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_LINEAR_LINEAR_HPP
  17. #include <cstddef>
  18. #include <deque>
  19. #include <boost/range.hpp>
  20. #include <boost/geometry/util/range.hpp>
  21. #include <boost/geometry/core/point_type.hpp>
  22. #include <boost/geometry/core/tag.hpp>
  23. #include <boost/geometry/core/tags.hpp>
  24. #include <boost/geometry/algorithms/detail/overlay/turn_info.hpp>
  25. #include <boost/geometry/algorithms/detail/overlay/get_turns.hpp>
  26. #include <boost/geometry/algorithms/detail/overlay/do_reverse.hpp>
  27. #include <boost/geometry/algorithms/detail/overlay/segment_as_subrange.hpp>
  28. #include <boost/geometry/policies/disjoint_interrupt_policy.hpp>
  29. #include <boost/geometry/policies/robustness/no_rescale_policy.hpp>
  30. #include <boost/geometry/algorithms/dispatch/disjoint.hpp>
  31. namespace boost { namespace geometry
  32. {
  33. #ifndef DOXYGEN_NO_DETAIL
  34. namespace detail { namespace disjoint
  35. {
  36. template <typename Segment1, typename Segment2>
  37. struct disjoint_segment
  38. {
  39. template <typename Strategy>
  40. static inline bool apply(Segment1 const& segment1, Segment2 const& segment2,
  41. Strategy const& strategy)
  42. {
  43. typedef typename point_type<Segment1>::type point_type;
  44. typedef segment_intersection_points<point_type> intersection_return_type;
  45. typedef policies::relate::segments_intersection_points
  46. <
  47. intersection_return_type
  48. > intersection_policy;
  49. detail::segment_as_subrange<Segment1> sub_range1(segment1);
  50. detail::segment_as_subrange<Segment2> sub_range2(segment2);
  51. intersection_return_type is = strategy.apply(sub_range1, sub_range2,
  52. intersection_policy());
  53. return is.count == 0;
  54. }
  55. };
  56. struct assign_disjoint_policy
  57. {
  58. // We want to include all points:
  59. static bool const include_no_turn = true;
  60. static bool const include_degenerate = true;
  61. static bool const include_opposite = true;
  62. };
  63. template <typename Geometry1, typename Geometry2>
  64. struct disjoint_linear
  65. {
  66. template <typename Strategy>
  67. static inline bool apply(Geometry1 const& geometry1,
  68. Geometry2 const& geometry2,
  69. Strategy const& strategy)
  70. {
  71. typedef typename geometry::point_type<Geometry1>::type point_type;
  72. typedef geometry::segment_ratio
  73. <
  74. typename coordinate_type<point_type>::type
  75. > ratio_type;
  76. typedef overlay::turn_info
  77. <
  78. point_type,
  79. ratio_type,
  80. typename detail::get_turns::turn_operation_type
  81. <
  82. Geometry1, Geometry2, ratio_type
  83. >::type
  84. > turn_info_type;
  85. std::deque<turn_info_type> turns;
  86. // Specify two policies:
  87. // 1) Stop at any intersection
  88. // 2) In assignment, include also degenerate points (which are normally skipped)
  89. disjoint_interrupt_policy interrupt_policy;
  90. dispatch::get_turns
  91. <
  92. typename geometry::tag<Geometry1>::type,
  93. typename geometry::tag<Geometry2>::type,
  94. Geometry1,
  95. Geometry2,
  96. overlay::do_reverse<geometry::point_order<Geometry1>::value>::value, // should be false
  97. overlay::do_reverse<geometry::point_order<Geometry2>::value>::value, // should be false
  98. detail::get_turns::get_turn_info_type
  99. <
  100. Geometry1, Geometry2, assign_disjoint_policy
  101. >
  102. >::apply(0, geometry1, 1, geometry2,
  103. strategy, detail::no_rescale_policy(), turns, interrupt_policy);
  104. return !interrupt_policy.has_intersections;
  105. }
  106. };
  107. }} // namespace detail::disjoint
  108. #endif // DOXYGEN_NO_DETAIL
  109. #ifndef DOXYGEN_NO_DISPATCH
  110. namespace dispatch
  111. {
  112. template <typename Linear1, typename Linear2>
  113. struct disjoint<Linear1, Linear2, 2, linear_tag, linear_tag, false>
  114. : detail::disjoint::disjoint_linear<Linear1, Linear2>
  115. {};
  116. template <typename Segment1, typename Segment2>
  117. struct disjoint<Segment1, Segment2, 2, segment_tag, segment_tag, false>
  118. : detail::disjoint::disjoint_segment<Segment1, Segment2>
  119. {};
  120. } // namespace dispatch
  121. #endif // DOXYGEN_NO_DISPATCH
  122. }} // namespace boost::geometry
  123. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_LINEAR_LINEAR_HPP