1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2012-2014 Barend Gehrels, Amsterdam, the Netherlands.
5 // This file was modified by Oracle on 2017.
6 // Modifications copyright (c) 2017, Oracle and/or its affiliates.
7 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
9 // Use, modification and distribution is subject to the Boost Software License,
10 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
11 // http://www.boost.org/LICENSE_1_0.txt)
13 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_BUFFER_BUFFER_POLICIES_HPP
14 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_BUFFER_BUFFER_POLICIES_HPP
16 #if ! defined(BOOST_GEOMETRY_NO_ROBUSTNESS)
17 # define BOOST_GEOMETRY_BUFFER_USE_SIDE_OF_INTERSECTION
22 #include <boost/range.hpp>
24 #include <boost/geometry/core/coordinate_type.hpp>
25 #include <boost/geometry/core/point_type.hpp>
27 #include <boost/geometry/algorithms/covered_by.hpp>
28 #include <boost/geometry/algorithms/detail/overlay/backtrack_check_si.hpp>
29 #include <boost/geometry/algorithms/detail/overlay/turn_info.hpp>
31 #include <boost/geometry/strategies/buffer.hpp>
34 namespace boost { namespace geometry
38 #ifndef DOXYGEN_NO_DETAIL
39 namespace detail { namespace buffer
43 enum intersection_location_type
45 location_ok, inside_buffer, location_discard
48 class backtrack_for_buffer
51 typedef detail::overlay::backtrack_state state_type;
60 typename RobustPolicy,
63 static inline void apply(std::size_t size_at_start,
64 Rings& rings, typename boost::range_value<Rings>::type& ring,
66 typename boost::range_value<Turns>::type const& /*turn*/,
68 detail::overlay::traverse_error_type /*traverse_error*/,
77 #if defined(BOOST_GEOMETRY_COUNT_BACKTRACK_WARNINGS)
78 extern int g_backtrack_warning_count;
79 g_backtrack_warning_count++;
82 //std::cout << "WARNING " << traverse_error_string(traverse_error) << std::endl;
86 // Make bad output clean
87 rings.resize(size_at_start);
90 // Reject this as a starting point
91 operation.visited.set_rejected();
93 // And clear all visit info
94 clear_visit_info(turns);
98 struct buffer_overlay_visitor
101 void print(char const* /*header*/)
105 template <typename Turns>
106 void print(char const* /*header*/, Turns const& /*turns*/, int /*turn_index*/)
110 template <typename Turns>
111 void print(char const* /*header*/, Turns const& /*turns*/, int /*turn_index*/, int /*op_index*/)
115 template <typename Turns>
116 void visit_turns(int , Turns const& ) {}
118 template <typename Clusters, typename Turns>
119 void visit_clusters(Clusters const& , Turns const& ) {}
121 template <typename Turns, typename Turn, typename Operation>
122 void visit_traverse(Turns const& /*turns*/, Turn const& /*turn*/, Operation const& /*op*/, const char* /*header*/)
126 template <typename Turns, typename Turn, typename Operation>
127 void visit_traverse_reject(Turns const& , Turn const& , Operation const& ,
128 detail::overlay::traverse_error_type )
131 template <typename Rings>
132 void visit_generated_rings(Rings const& )
137 // Should follow traversal-turn-concept (enrichment, visit structure)
138 // and adds index in piece vector to find it back
139 template <typename Point, typename SegmentRatio>
140 struct buffer_turn_operation
141 : public detail::overlay::traversal_turn_operation<Point, SegmentRatio>
143 signed_size_type piece_index;
144 signed_size_type index_in_robust_ring;
146 inline buffer_turn_operation()
148 , index_in_robust_ring(-1)
152 // Version for buffer including type of location, is_opposite, and helper variables
153 template <typename Point, typename RobustPoint, typename SegmentRatio>
154 struct buffer_turn_info
155 : public detail::overlay::turn_info
159 buffer_turn_operation<Point, SegmentRatio>
162 typedef Point point_type;
163 typedef RobustPoint robust_point_type;
165 std::size_t turn_index; // TODO: this might go if partition can operate on non-const input
167 RobustPoint robust_point;
168 #if defined(BOOST_GEOMETRY_BUFFER_ENLARGED_CLUSTERS)
169 // Will (most probably) be removed later
170 RobustPoint mapped_robust_point; // alas... we still need to adapt our points, offsetting them 1 integer to be co-located with neighbours
174 inline RobustPoint const& get_robust_point() const
176 #if defined(BOOST_GEOMETRY_BUFFER_ENLARGED_CLUSTERS)
177 return mapped_robust_point;
182 intersection_location_type location;
184 #if defined(BOOST_GEOMETRY_BUFFER_USE_SIDE_OF_INTERSECTION)
185 robust_point_type rob_pi, rob_pj, rob_qi, rob_qj;
188 std::size_t count_within;
190 bool within_original;
191 std::size_t count_on_original_boundary;
192 signed_size_type count_in_original; // increased by +1 for in ext.ring, -1 for int.ring
194 std::size_t count_on_offsetted;
195 std::size_t count_on_helper;
196 #if ! defined(BOOST_GEOMETRY_BUFFER_USE_SIDE_OF_INTERSECTION)
197 std::size_t count_within_near_offsetted;
200 bool remove_on_multi;
203 std::size_t count_on_occupied;
204 std::size_t count_on_multi;
206 inline buffer_turn_info()
208 , location(location_ok)
210 , within_original(false)
211 , count_on_original_boundary(0)
212 , count_in_original(0)
213 , count_on_offsetted(0)
215 #if ! defined(BOOST_GEOMETRY_BUFFER_USE_SIDE_OF_INTERSECTION)
216 , count_within_near_offsetted(0)
218 , remove_on_multi(false)
219 , count_on_occupied(0)
224 struct buffer_operation_less
226 template <typename Turn>
227 inline bool operator()(Turn const& left, Turn const& right) const
229 segment_identifier const& sl = left.seg_id;
230 segment_identifier const& sr = right.seg_id;
232 // Sort them descending
234 ? left.fraction < right.fraction
239 }} // namespace detail::buffer
240 #endif // DOXYGEN_NO_DETAIL
243 }} // namespace boost::geometry
245 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_BUFFER_BUFFER_POLICIES_HPP