buffer_policies.hpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2012-2014 Barend Gehrels, Amsterdam, the Netherlands.
  3. // This file was modified by Oracle on 2017, 2018.
  4. // Modifications copyright (c) 2017-2018, Oracle and/or its affiliates.
  5. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  6. // Use, modification and distribution is subject to the Boost Software License,
  7. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt)
  9. #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_BUFFER_BUFFER_POLICIES_HPP
  10. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_BUFFER_BUFFER_POLICIES_HPP
  11. #include <cstddef>
  12. #include <boost/range.hpp>
  13. #include <boost/geometry/core/coordinate_type.hpp>
  14. #include <boost/geometry/core/point_type.hpp>
  15. #include <boost/geometry/algorithms/covered_by.hpp>
  16. #include <boost/geometry/algorithms/detail/overlay/backtrack_check_si.hpp>
  17. #include <boost/geometry/algorithms/detail/overlay/traversal_info.hpp>
  18. #include <boost/geometry/algorithms/detail/overlay/turn_info.hpp>
  19. #include <boost/geometry/strategies/buffer.hpp>
  20. namespace boost { namespace geometry
  21. {
  22. #ifndef DOXYGEN_NO_DETAIL
  23. namespace detail { namespace buffer
  24. {
  25. enum intersection_location_type
  26. {
  27. location_ok, inside_buffer, location_discard
  28. };
  29. class backtrack_for_buffer
  30. {
  31. public :
  32. typedef detail::overlay::backtrack_state state_type;
  33. template
  34. <
  35. typename Operation,
  36. typename Rings,
  37. typename Turns,
  38. typename Geometry,
  39. typename Strategy,
  40. typename RobustPolicy,
  41. typename Visitor
  42. >
  43. static inline void apply(std::size_t size_at_start,
  44. Rings& rings, typename boost::range_value<Rings>::type& ring,
  45. Turns& turns,
  46. typename boost::range_value<Turns>::type const& /*turn*/,
  47. Operation& operation,
  48. detail::overlay::traverse_error_type /*traverse_error*/,
  49. Geometry const& ,
  50. Geometry const& ,
  51. Strategy const& ,
  52. RobustPolicy const& ,
  53. state_type& state,
  54. Visitor& /*visitor*/
  55. )
  56. {
  57. #if defined(BOOST_GEOMETRY_COUNT_BACKTRACK_WARNINGS)
  58. extern int g_backtrack_warning_count;
  59. g_backtrack_warning_count++;
  60. #endif
  61. //std::cout << "!";
  62. //std::cout << "WARNING " << traverse_error_string(traverse_error) << std::endl;
  63. state.m_good = false;
  64. // Make bad output clean
  65. rings.resize(size_at_start);
  66. ring.clear();
  67. // Reject this as a starting point
  68. operation.visited.set_rejected();
  69. // And clear all visit info
  70. clear_visit_info(turns);
  71. }
  72. };
  73. struct buffer_overlay_visitor
  74. {
  75. public :
  76. void print(char const* /*header*/)
  77. {
  78. }
  79. template <typename Turns>
  80. void print(char const* /*header*/, Turns const& /*turns*/, int /*turn_index*/)
  81. {
  82. }
  83. template <typename Turns>
  84. void print(char const* /*header*/, Turns const& /*turns*/, int /*turn_index*/, int /*op_index*/)
  85. {
  86. }
  87. template <typename Turns>
  88. void visit_turns(int , Turns const& ) {}
  89. template <typename Clusters, typename Turns>
  90. void visit_clusters(Clusters const& , Turns const& ) {}
  91. template <typename Turns, typename Turn, typename Operation>
  92. void visit_traverse(Turns const& /*turns*/, Turn const& /*turn*/, Operation const& /*op*/, const char* /*header*/)
  93. {
  94. }
  95. template <typename Turns, typename Turn, typename Operation>
  96. void visit_traverse_reject(Turns const& , Turn const& , Operation const& ,
  97. detail::overlay::traverse_error_type )
  98. {}
  99. template <typename Rings>
  100. void visit_generated_rings(Rings const& )
  101. {}
  102. };
  103. // Should follow traversal-turn-concept (enrichment, visit structure)
  104. // and adds index in piece vector to find it back
  105. template <typename Point, typename SegmentRatio>
  106. struct buffer_turn_operation
  107. : public detail::overlay::traversal_turn_operation<Point, SegmentRatio>
  108. {
  109. signed_size_type piece_index;
  110. signed_size_type index_in_robust_ring;
  111. inline buffer_turn_operation()
  112. : piece_index(-1)
  113. , index_in_robust_ring(-1)
  114. {}
  115. };
  116. // Version for buffer including type of location, is_opposite, and helper variables
  117. template <typename Point, typename RobustPoint, typename SegmentRatio>
  118. struct buffer_turn_info
  119. : public detail::overlay::turn_info
  120. <
  121. Point,
  122. SegmentRatio,
  123. buffer_turn_operation<Point, SegmentRatio>
  124. >
  125. {
  126. typedef Point point_type;
  127. typedef RobustPoint robust_point_type;
  128. std::size_t turn_index; // TODO: this might go if partition can operate on non-const input
  129. RobustPoint robust_point;
  130. #if defined(BOOST_GEOMETRY_BUFFER_ENLARGED_CLUSTERS)
  131. // Will (most probably) be removed later
  132. RobustPoint mapped_robust_point; // alas... we still need to adapt our points, offsetting them 1 integer to be co-located with neighbours
  133. #endif
  134. inline RobustPoint const& get_robust_point() const
  135. {
  136. #if defined(BOOST_GEOMETRY_BUFFER_ENLARGED_CLUSTERS)
  137. return mapped_robust_point;
  138. #endif
  139. return robust_point;
  140. }
  141. intersection_location_type location;
  142. robust_point_type rob_pi, rob_pj, rob_qi, rob_qj;
  143. std::size_t count_within;
  144. bool within_original;
  145. std::size_t count_on_original_boundary;
  146. signed_size_type count_in_original; // increased by +1 for in ext.ring, -1 for int.ring
  147. std::size_t count_on_offsetted;
  148. std::size_t count_on_helper;
  149. std::size_t count_within_near_offsetted;
  150. bool remove_on_multi;
  151. // Obsolete:
  152. std::size_t count_on_occupied;
  153. std::size_t count_on_multi;
  154. inline buffer_turn_info()
  155. : turn_index(0)
  156. , location(location_ok)
  157. , count_within(0)
  158. , within_original(false)
  159. , count_on_original_boundary(0)
  160. , count_in_original(0)
  161. , count_on_offsetted(0)
  162. , count_on_helper(0)
  163. , count_within_near_offsetted(0)
  164. , remove_on_multi(false)
  165. , count_on_occupied(0)
  166. , count_on_multi(0)
  167. {}
  168. };
  169. struct buffer_operation_less
  170. {
  171. template <typename Turn>
  172. inline bool operator()(Turn const& left, Turn const& right) const
  173. {
  174. segment_identifier const& sl = left.seg_id;
  175. segment_identifier const& sr = right.seg_id;
  176. // Sort them descending
  177. return sl == sr
  178. ? left.fraction < right.fraction
  179. : sl < sr;
  180. }
  181. };
  182. }} // namespace detail::buffer
  183. #endif // DOXYGEN_NO_DETAIL
  184. }} // namespace boost::geometry
  185. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_BUFFER_BUFFER_POLICIES_HPP