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 )
133 // Should follow traversal-turn-concept (enrichment, visit structure)
134 // and adds index in piece vector to find it back
135 template <typename Point, typename SegmentRatio>
136 struct buffer_turn_operation
137 : public detail::overlay::traversal_turn_operation<Point, SegmentRatio>
139 signed_size_type piece_index;
140 signed_size_type index_in_robust_ring;
142 inline buffer_turn_operation()
144 , index_in_robust_ring(-1)
148 // Version for buffer including type of location, is_opposite, and helper variables
149 template <typename Point, typename RobustPoint, typename SegmentRatio>
150 struct buffer_turn_info
151 : public detail::overlay::turn_info
155 buffer_turn_operation<Point, SegmentRatio>
158 typedef Point point_type;
159 typedef RobustPoint robust_point_type;
161 std::size_t turn_index; // TODO: this might go if partition can operate on non-const input
163 RobustPoint robust_point;
164 #if defined(BOOST_GEOMETRY_BUFFER_ENLARGED_CLUSTERS)
165 // Will (most probably) be removed later
166 RobustPoint mapped_robust_point; // alas... we still need to adapt our points, offsetting them 1 integer to be co-located with neighbours
170 inline RobustPoint const& get_robust_point() const
172 #if defined(BOOST_GEOMETRY_BUFFER_ENLARGED_CLUSTERS)
173 return mapped_robust_point;
178 intersection_location_type location;
180 #if defined(BOOST_GEOMETRY_BUFFER_USE_SIDE_OF_INTERSECTION)
181 robust_point_type rob_pi, rob_pj, rob_qi, rob_qj;
184 std::size_t count_within;
186 bool within_original;
187 std::size_t count_on_original_boundary;
188 signed_size_type count_in_original; // increased by +1 for in ext.ring, -1 for int.ring
190 std::size_t count_on_offsetted;
191 std::size_t count_on_helper;
192 #if ! defined(BOOST_GEOMETRY_BUFFER_USE_SIDE_OF_INTERSECTION)
193 std::size_t count_within_near_offsetted;
196 bool remove_on_multi;
199 std::size_t count_on_occupied;
200 std::size_t count_on_multi;
202 inline buffer_turn_info()
204 , location(location_ok)
206 , within_original(false)
207 , count_on_original_boundary(0)
208 , count_in_original(0)
209 , count_on_offsetted(0)
211 #if ! defined(BOOST_GEOMETRY_BUFFER_USE_SIDE_OF_INTERSECTION)
212 , count_within_near_offsetted(0)
214 , remove_on_multi(false)
215 , count_on_occupied(0)
220 struct buffer_operation_less
222 template <typename Turn>
223 inline bool operator()(Turn const& left, Turn const& right) const
225 segment_identifier const& sl = left.seg_id;
226 segment_identifier const& sr = right.seg_id;
228 // Sort them descending
230 ? left.fraction < right.fraction
235 }} // namespace detail::buffer
236 #endif // DOXYGEN_NO_DETAIL
239 }} // namespace boost::geometry
241 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_BUFFER_BUFFER_POLICIES_HPP