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.
8 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
10 // Use, modification and distribution is subject to the Boost Software License,
11 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
12 // http://www.boost.org/LICENSE_1_0.txt)
14 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_OCCUPATION_INFO_HPP
15 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_OCCUPATION_INFO_HPP
18 #include <boost/range.hpp>
20 #include <boost/geometry/core/assert.hpp>
21 #include <boost/geometry/core/coordinate_type.hpp>
22 #include <boost/geometry/core/point_type.hpp>
24 #include <boost/geometry/policies/compare.hpp>
25 #include <boost/geometry/iterators/closing_iterator.hpp>
27 #include <boost/geometry/algorithms/detail/get_left_turns.hpp>
30 namespace boost { namespace geometry
34 #ifndef DOXYGEN_NO_DETAIL
38 template <typename Point, typename T>
42 typedef Point point_type;
44 segment_identifier seg_id;
45 std::size_t turn_index;
47 std::size_t cluster_index;
48 Point intersection_point;
49 Point point; // either incoming or outgoing point
60 template <typename AngleInfo>
64 typedef std::vector<AngleInfo> collection_type;
68 inline occupation_info()
72 template <typename RobustPoint>
73 inline void add(RobustPoint const& incoming_point,
74 RobustPoint const& outgoing_point,
75 RobustPoint const& intersection_point,
76 std::size_t turn_index, int operation_index,
77 segment_identifier const& seg_id)
79 geometry::equal_to<RobustPoint> comparator;
80 if (comparator(incoming_point, intersection_point))
84 if (comparator(outgoing_point, intersection_point))
91 info.turn_index = turn_index;
92 info.operation_index = operation_index;
93 info.intersection_point = intersection_point;
96 info.point = incoming_point;
98 m_angles.push_back(info);
101 info.point = outgoing_point;
102 info.incoming = false;
103 m_angles.push_back(info);
107 template <typename RobustPoint, typename Turns, typename SideStrategy>
108 inline void get_left_turns(RobustPoint const& origin, Turns& turns,
109 SideStrategy const& strategy)
111 typedef detail::left_turns::angle_less
113 typename AngleInfo::point_type,
118 std::sort(m_angles.begin(), m_angles.end(), angle_less(origin, strategy));
120 // Group same-angled elements
121 std::size_t cluster_size = detail::left_turns::assign_cluster_indices(m_angles, origin);
122 // Block all turns on the right side of any turn
123 detail::left_turns::block_turns(m_angles, cluster_size);
124 detail::left_turns::get_left_turns(m_angles, turns);
127 #if defined(BOOST_GEOMETRY_BUFFER_ENLARGED_CLUSTERS)
128 template <typename RobustPoint>
129 inline bool has_rounding_issues(RobustPoint const& origin) const
131 return detail::left_turns::has_rounding_issues(angles, origin);
136 collection_type m_angles; // each turn splitted in incoming/outgoing vectors
139 template<typename Pieces>
140 inline void move_index(Pieces const& pieces, signed_size_type& index, signed_size_type& piece_index, int direction)
142 BOOST_GEOMETRY_ASSERT(direction == 1 || direction == -1);
143 BOOST_GEOMETRY_ASSERT(
145 && piece_index < static_cast<signed_size_type>(boost::size(pieces)) );
146 BOOST_GEOMETRY_ASSERT(
148 && index < static_cast<signed_size_type>(boost::size(pieces[piece_index].robust_ring)));
150 // NOTE: both index and piece_index must be in valid range
151 // this means that then they could be of type std::size_t
152 // if the code below was refactored
155 if (direction == -1 && index < 0)
160 piece_index = boost::size(pieces) - 1;
162 index = boost::size(pieces[piece_index].robust_ring) - 1;
165 && index >= static_cast<signed_size_type>(boost::size(pieces[piece_index].robust_ring)))
168 if (piece_index >= static_cast<signed_size_type>(boost::size(pieces)))
179 typename RobustPoint,
184 inline void add_incoming_and_outgoing_angles(
185 RobustPoint const& intersection_point, // rescaled
187 Pieces const& pieces, // using rescaled offsets of it
189 segment_identifier seg_id,
192 segment_identifier real_seg_id = seg_id;
193 geometry::equal_to<RobustPoint> comparator;
195 // Move backward and forward
196 RobustPoint direction_points[2];
197 for (int i = 0; i < 2; i++)
199 signed_size_type index = turn.operations[operation_index].index_in_robust_ring;
200 signed_size_type piece_index = turn.operations[operation_index].piece_index;
201 while(comparator(pieces[piece_index].robust_ring[index], intersection_point))
203 move_index(pieces, index, piece_index, i == 0 ? -1 : 1);
205 direction_points[i] = pieces[piece_index].robust_ring[index];
208 info.add(direction_points[0], direction_points[1], intersection_point,
209 turn.turn_index, operation_index, real_seg_id);
213 } // namespace detail
214 #endif // DOXYGEN_NO_DETAIL
217 }} // namespace boost::geometry
219 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_OCCUPATION_INFO_HPP