linear_linear.hpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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-2020.
  7. // Modifications copyright (c) 2013-2020, 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/geometry/core/point_type.hpp>
  20. #include <boost/geometry/core/tag.hpp>
  21. #include <boost/geometry/core/tags.hpp>
  22. #include <boost/geometry/algorithms/detail/overlay/turn_info.hpp>
  23. #include <boost/geometry/algorithms/detail/overlay/get_turns.hpp>
  24. #include <boost/geometry/algorithms/detail/overlay/do_reverse.hpp>
  25. #include <boost/geometry/algorithms/detail/overlay/segment_as_subrange.hpp>
  26. #include <boost/geometry/geometries/helper_geometry.hpp>
  27. #include <boost/geometry/policies/disjoint_interrupt_policy.hpp>
  28. #include <boost/geometry/policies/robustness/no_rescale_policy.hpp>
  29. #include <boost/geometry/algorithms/dispatch/disjoint.hpp>
  30. namespace boost { namespace geometry
  31. {
  32. #ifndef DOXYGEN_NO_DETAIL
  33. namespace detail { namespace disjoint
  34. {
  35. template <typename Segment1, typename Segment2>
  36. struct disjoint_segment
  37. {
  38. template <typename Strategy>
  39. static inline bool apply(Segment1 const& segment1, Segment2 const& segment2,
  40. Strategy const& strategy)
  41. {
  42. typedef typename point_type<Segment1>::type point_type;
  43. typedef segment_intersection_points<point_type> intersection_return_type;
  44. typedef policies::relate::segments_intersection_points
  45. <
  46. intersection_return_type
  47. > intersection_policy;
  48. detail::segment_as_subrange<Segment1> sub_range1(segment1);
  49. detail::segment_as_subrange<Segment2> sub_range2(segment2);
  50. intersection_return_type is = strategy.relate().apply(sub_range1, sub_range2,
  51. intersection_policy());
  52. return is.count == 0;
  53. }
  54. };
  55. struct assign_disjoint_policy
  56. {
  57. // We want to include all points:
  58. static bool const include_no_turn = true;
  59. static bool const include_degenerate = true;
  60. static bool const include_opposite = true;
  61. static bool const include_start_turn = false;
  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. using point_type = typename geometry::point_type<Geometry1>::type;
  72. using mutable_point_type = typename helper_geometry<point_type>::type;
  73. using ratio_type = geometry::segment_ratio
  74. <
  75. typename coordinate_type<point_type>::type
  76. > ;
  77. using turn_info_type = overlay::turn_info
  78. <
  79. mutable_point_type,
  80. ratio_type,
  81. typename detail::get_turns::turn_operation_type
  82. <
  83. Geometry1, Geometry2, mutable_point_type, ratio_type
  84. >::type
  85. >;
  86. std::deque<turn_info_type> turns;
  87. // Specify two policies:
  88. // 1) Stop at any intersection
  89. // 2) In assignment, include also degenerate points (which are normally skipped)
  90. disjoint_interrupt_policy interrupt_policy;
  91. dispatch::get_turns
  92. <
  93. typename geometry::tag<Geometry1>::type,
  94. typename geometry::tag<Geometry2>::type,
  95. Geometry1,
  96. Geometry2,
  97. overlay::do_reverse<geometry::point_order<Geometry1>::value>::value, // should be false
  98. overlay::do_reverse<geometry::point_order<Geometry2>::value>::value, // should be false
  99. detail::get_turns::get_turn_info_type
  100. <
  101. Geometry1, Geometry2, assign_disjoint_policy
  102. >
  103. >::apply(0, geometry1, 1, geometry2,
  104. strategy, detail::no_rescale_policy(), turns, interrupt_policy);
  105. return !interrupt_policy.has_intersections;
  106. }
  107. };
  108. }} // namespace detail::disjoint
  109. #endif // DOXYGEN_NO_DETAIL
  110. #ifndef DOXYGEN_NO_DISPATCH
  111. namespace dispatch
  112. {
  113. template <typename Linear1, typename Linear2>
  114. struct disjoint<Linear1, Linear2, 2, linear_tag, linear_tag, false>
  115. : detail::disjoint::disjoint_linear<Linear1, Linear2>
  116. {};
  117. template <typename Segment1, typename Segment2>
  118. struct disjoint<Segment1, Segment2, 2, segment_tag, segment_tag, false>
  119. : detail::disjoint::disjoint_segment<Segment1, Segment2>
  120. {};
  121. } // namespace dispatch
  122. #endif // DOXYGEN_NO_DISPATCH
  123. }} // namespace boost::geometry
  124. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_LINEAR_LINEAR_HPP