1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2012-2014 Barend Gehrels, Amsterdam, the Netherlands.
5 // Use, modification and distribution is subject to the Boost Software License,
6 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 // 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
12 #if ! defined(BOOST_GEOMETRY_NO_ROBUSTNESS)
13 # define BOOST_GEOMETRY_BUFFER_USE_SIDE_OF_INTERSECTION
18 #include <boost/range.hpp>
20 #include <boost/geometry/core/coordinate_type.hpp>
21 #include <boost/geometry/core/point_type.hpp>
23 #include <boost/geometry/algorithms/covered_by.hpp>
24 #include <boost/geometry/algorithms/detail/overlay/backtrack_check_si.hpp>
25 #include <boost/geometry/algorithms/detail/overlay/turn_info.hpp>
27 #include <boost/geometry/strategies/buffer.hpp>
30 namespace boost { namespace geometry
34 #ifndef DOXYGEN_NO_DETAIL
35 namespace detail { namespace buffer
39 enum intersection_location_type
41 location_ok, inside_buffer, location_discard
44 class backtrack_for_buffer
47 typedef detail::overlay::backtrack_state state_type;
55 typename RobustPolicy,
58 static inline void apply(std::size_t size_at_start,
59 Rings& rings, typename boost::range_value<Rings>::type& ring,
61 typename boost::range_value<Turns>::type const& /*turn*/,
63 detail::overlay::traverse_error_type /*traverse_error*/,
71 #if defined(BOOST_GEOMETRY_COUNT_BACKTRACK_WARNINGS)
72 extern int g_backtrack_warning_count;
73 g_backtrack_warning_count++;
76 //std::cout << "WARNING " << traverse_error_string(traverse_error) << std::endl;
80 // Make bad output clean
81 rings.resize(size_at_start);
84 // Reject this as a starting point
85 operation.visited.set_rejected();
87 // And clear all visit info
88 clear_visit_info(turns);
92 struct buffer_overlay_visitor
95 void print(char const* /*header*/)
99 template <typename Turns>
100 void print(char const* /*header*/, Turns const& /*turns*/, int /*turn_index*/)
104 template <typename Turns>
105 void print(char const* /*header*/, Turns const& /*turns*/, int /*turn_index*/, int /*op_index*/)
109 template <typename Turns>
110 void visit_turns(int , Turns const& ) {}
112 template <typename Clusters, typename Turns>
113 void visit_clusters(Clusters const& , Turns const& ) {}
115 template <typename Turns, typename Turn, typename Operation>
116 void visit_traverse(Turns const& /*turns*/, Turn const& /*turn*/, Operation const& /*op*/, const char* /*header*/)
120 template <typename Turns, typename Turn, typename Operation>
121 void visit_traverse_reject(Turns const& , Turn const& , Operation const& ,
122 detail::overlay::traverse_error_type )
127 // Should follow traversal-turn-concept (enrichment, visit structure)
128 // and adds index in piece vector to find it back
129 template <typename Point, typename SegmentRatio>
130 struct buffer_turn_operation
131 : public detail::overlay::traversal_turn_operation<Point, SegmentRatio>
133 signed_size_type piece_index;
134 signed_size_type index_in_robust_ring;
136 inline buffer_turn_operation()
138 , index_in_robust_ring(-1)
142 // Version for buffer including type of location, is_opposite, and helper variables
143 template <typename Point, typename RobustPoint, typename SegmentRatio>
144 struct buffer_turn_info
145 : public detail::overlay::turn_info
149 buffer_turn_operation<Point, SegmentRatio>
152 typedef Point point_type;
153 typedef RobustPoint robust_point_type;
155 std::size_t turn_index; // TODO: this might go if partition can operate on non-const input
157 RobustPoint robust_point;
158 #if defined(BOOST_GEOMETRY_BUFFER_ENLARGED_CLUSTERS)
159 // Will (most probably) be removed later
160 RobustPoint mapped_robust_point; // alas... we still need to adapt our points, offsetting them 1 integer to be co-located with neighbours
164 inline RobustPoint const& get_robust_point() const
166 #if defined(BOOST_GEOMETRY_BUFFER_ENLARGED_CLUSTERS)
167 return mapped_robust_point;
172 intersection_location_type location;
174 #if defined(BOOST_GEOMETRY_BUFFER_USE_SIDE_OF_INTERSECTION)
175 robust_point_type rob_pi, rob_pj, rob_qi, rob_qj;
178 std::size_t count_within;
180 bool within_original;
181 std::size_t count_on_original_boundary;
182 signed_size_type count_in_original; // increased by +1 for in ext.ring, -1 for int.ring
184 std::size_t count_on_offsetted;
185 std::size_t count_on_helper;
186 #if ! defined(BOOST_GEOMETRY_BUFFER_USE_SIDE_OF_INTERSECTION)
187 std::size_t count_within_near_offsetted;
190 bool remove_on_multi;
193 std::size_t count_on_occupied;
194 std::size_t count_on_multi;
196 inline buffer_turn_info()
198 , location(location_ok)
200 , within_original(false)
201 , count_on_original_boundary(0)
202 , count_in_original(0)
203 , count_on_offsetted(0)
205 #if ! defined(BOOST_GEOMETRY_BUFFER_USE_SIDE_OF_INTERSECTION)
206 , count_within_near_offsetted(0)
208 , remove_on_multi(false)
209 , count_on_occupied(0)
214 struct buffer_operation_less
216 template <typename Turn>
217 inline bool operator()(Turn const& left, Turn const& right) const
219 segment_identifier const& sl = left.seg_id;
220 segment_identifier const& sr = right.seg_id;
222 // Sort them descending
224 ? left.fraction < right.fraction
229 }} // namespace detail::buffer
230 #endif // DOXYGEN_NO_DETAIL
233 }} // namespace boost::geometry
235 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_BUFFER_BUFFER_POLICIES_HPP