linear_segment_or_box.hpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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-2019.
  7. // Modifications copyright (c) 2013-2019, 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_SEGMENT_OR_BOX_HPP
  16. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_LINEAR_SEGMENT_OR_BOX_HPP
  17. #include <boost/geometry/algorithms/detail/disjoint/multirange_geometry.hpp>
  18. #include <boost/geometry/algorithms/dispatch/disjoint.hpp>
  19. #include <boost/geometry/algorithms/not_implemented.hpp>
  20. #include <boost/geometry/core/closure.hpp>
  21. #include <boost/geometry/geometries/segment.hpp>
  22. #include <boost/geometry/util/range.hpp>
  23. #include <boost/geometry/views/closeable_view.hpp>
  24. namespace boost { namespace geometry
  25. {
  26. #ifndef DOXYGEN_NO_DETAIL
  27. namespace detail { namespace disjoint
  28. {
  29. template
  30. <
  31. typename SegmentOrBox,
  32. typename Tag = typename tag<SegmentOrBox>::type
  33. >
  34. struct disjoint_point_segment_or_box
  35. : not_implemented<Tag>
  36. {};
  37. template <typename Segment>
  38. struct disjoint_point_segment_or_box<Segment, segment_tag>
  39. {
  40. template <typename Point, typename Strategy>
  41. static inline bool apply(Point const& point, Segment const& segment, Strategy const& strategy)
  42. {
  43. return dispatch::disjoint
  44. <
  45. Point, Segment
  46. >::apply(point, segment,
  47. strategy.template get_point_in_geometry_strategy<Point, Segment>());
  48. }
  49. };
  50. template <typename Box>
  51. struct disjoint_point_segment_or_box<Box, box_tag>
  52. {
  53. template <typename Point, typename Strategy>
  54. static inline bool apply(Point const& point, Box const& box, Strategy const& strategy)
  55. {
  56. return dispatch::disjoint
  57. <
  58. Point, Box
  59. >::apply(point, box,
  60. strategy.get_disjoint_point_box_strategy());
  61. }
  62. };
  63. template
  64. <
  65. typename Range,
  66. closure_selector Closure,
  67. typename SegmentOrBox
  68. >
  69. struct disjoint_range_segment_or_box
  70. {
  71. template <typename Strategy>
  72. static inline bool apply(Range const& range,
  73. SegmentOrBox const& segment_or_box,
  74. Strategy const& strategy)
  75. {
  76. typedef typename closeable_view<Range const, Closure>::type view_type;
  77. typedef typename ::boost::range_value<view_type>::type point_type;
  78. typedef typename ::boost::range_iterator
  79. <
  80. view_type const
  81. >::type const_iterator;
  82. typedef typename ::boost::range_size<view_type>::type size_type;
  83. typedef typename geometry::model::referring_segment
  84. <
  85. point_type const
  86. > range_segment;
  87. view_type view(range);
  88. const size_type count = ::boost::size(view);
  89. if ( count == 0 )
  90. {
  91. return false;
  92. }
  93. else if ( count == 1 )
  94. {
  95. return disjoint_point_segment_or_box
  96. <
  97. SegmentOrBox
  98. >::apply(geometry::range::front<view_type const>(view),
  99. segment_or_box,
  100. strategy);
  101. }
  102. else
  103. {
  104. const_iterator it0 = ::boost::begin(view);
  105. const_iterator it1 = ::boost::begin(view) + 1;
  106. const_iterator last = ::boost::end(view);
  107. for ( ; it1 != last ; ++it0, ++it1 )
  108. {
  109. range_segment rng_segment(*it0, *it1);
  110. if ( !dispatch::disjoint
  111. <
  112. range_segment, SegmentOrBox
  113. >::apply(rng_segment, segment_or_box, strategy) )
  114. {
  115. return false;
  116. }
  117. }
  118. return true;
  119. }
  120. }
  121. };
  122. template
  123. <
  124. typename Linear,
  125. typename SegmentOrBox,
  126. typename Tag = typename tag<Linear>::type
  127. >
  128. struct disjoint_linear_segment_or_box
  129. : not_implemented<Linear, SegmentOrBox>
  130. {};
  131. template <typename Linestring, typename SegmentOrBox>
  132. struct disjoint_linear_segment_or_box<Linestring, SegmentOrBox, linestring_tag>
  133. : disjoint_range_segment_or_box<Linestring, closed, SegmentOrBox>
  134. {};
  135. template <typename MultiLinestring, typename SegmentOrBox>
  136. struct disjoint_linear_segment_or_box
  137. <
  138. MultiLinestring, SegmentOrBox, multi_linestring_tag
  139. > : multirange_constant_size_geometry<MultiLinestring, SegmentOrBox>
  140. {};
  141. }} // namespace detail::disjoint
  142. #endif // DOXYGEN_NO_DETAIL
  143. #ifndef DOXYGEN_NO_DISPATCH
  144. namespace dispatch
  145. {
  146. template <typename Linear, typename Segment>
  147. struct disjoint<Linear, Segment, 2, linear_tag, segment_tag, false>
  148. : detail::disjoint::disjoint_linear_segment_or_box<Linear, Segment>
  149. {};
  150. template <typename Linear, typename Box, std::size_t DimensionCount>
  151. struct disjoint<Linear, Box, DimensionCount, linear_tag, box_tag, false>
  152. : detail::disjoint::disjoint_linear_segment_or_box<Linear, Box>
  153. {};
  154. } // namespace dispatch
  155. #endif // DOXYGEN_NO_DISPATCH
  156. }} // namespace boost::geometry
  157. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_LINEAR_SEGMENT_OR_BOX_HPP