1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2014-2017, Oracle and/or its affiliates.
5 // Licensed under the Boost Software License version 1.0.
6 // http://www.boost.org/users/license.html
8 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
9 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
12 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_LINEAR_LINEAR_HPP
13 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_LINEAR_LINEAR_HPP
18 #include <boost/range.hpp>
20 #include <boost/geometry/core/tag.hpp>
21 #include <boost/geometry/core/tags.hpp>
23 #include <boost/geometry/algorithms/detail/relate/turns.hpp>
25 #include <boost/geometry/algorithms/detail/turns/compare_turns.hpp>
26 #include <boost/geometry/algorithms/detail/turns/filter_continue_turns.hpp>
27 #include <boost/geometry/algorithms/detail/turns/remove_duplicate_turns.hpp>
29 #include <boost/geometry/algorithms/detail/overlay/overlay_type.hpp>
30 #include <boost/geometry/algorithms/detail/overlay/follow_linear_linear.hpp>
32 #include <boost/geometry/algorithms/convert.hpp>
36 namespace boost { namespace geometry
40 #ifndef DOXYGEN_NO_DETAIL
41 namespace detail { namespace overlay
47 typename LineStringOut,
48 overlay_type OverlayType,
52 struct linear_linear_no_intersections;
55 template <typename LineStringOut, typename LineString>
56 struct linear_linear_no_intersections
58 LineStringOut, overlay_difference, LineString, linestring_tag
61 template <typename OutputIterator>
62 static inline OutputIterator apply(LineString const& linestring,
66 geometry::convert(linestring, ls_out);
73 template <typename LineStringOut, typename MultiLineString>
74 struct linear_linear_no_intersections
82 template <typename OutputIterator>
83 static inline OutputIterator apply(MultiLineString const& multilinestring,
86 for (typename boost::range_iterator<MultiLineString const>::type
87 it = boost::begin(multilinestring);
88 it != boost::end(multilinestring); ++it)
91 geometry::convert(*it, ls_out);
99 template <typename LineStringOut, typename Geometry, typename GeometryTag>
100 struct linear_linear_no_intersections
102 LineStringOut, overlay_intersection, Geometry, GeometryTag
105 template <typename OutputIterator>
106 static inline OutputIterator apply(Geometry const&,
123 typename LinestringOut,
124 overlay_type OverlayType,
125 bool EnableFilterContinueTurns = false,
126 bool EnableRemoveDuplicateTurns = false,
127 bool EnableDegenerateTurns = true,
128 #ifdef BOOST_GEOMETRY_INTERSECTION_DO_NOT_INCLUDE_ISOLATED_POINTS
129 bool EnableFollowIsolatedPoints = false
131 bool EnableFollowIsolatedPoints = true
134 class linear_linear_linestring
139 static bool const include_no_turn = false;
140 static bool const include_degenerate = EnableDegenerateTurns;
141 static bool const include_opposite = false;
148 typename IntersectionInfo
150 static inline void apply(Info& , Point1 const& , Point2 const& ,
151 IntersectionInfo const& )
160 typename LinearGeometry1,
161 typename LinearGeometry2,
162 typename IntersectionStrategy,
163 typename RobustPolicy
165 static inline void compute_turns(Turns& turns,
166 LinearGeometry1 const& linear1,
167 LinearGeometry2 const& linear2,
168 IntersectionStrategy const& strategy,
169 RobustPolicy const& robust_policy)
173 detail::get_turns::no_interrupt_policy interrupt_policy;
175 geometry::detail::relate::turns::get_turns
179 detail::get_turns::get_turn_info_type
186 >::apply(turns, linear1, linear2, interrupt_policy, strategy, robust_policy);
192 overlay_type OverlayTypeForFollow,
193 bool FollowIsolatedPoints,
195 typename LinearGeometry1,
196 typename LinearGeometry2,
197 typename OutputIterator
199 static inline OutputIterator
200 sort_and_follow_turns(Turns& turns,
201 LinearGeometry1 const& linear1,
202 LinearGeometry2 const& linear2,
205 // remove turns that have no added value
206 turns::filter_continue_turns
209 EnableFilterContinueTurns && OverlayType != overlay_intersection
212 // sort by seg_id, distance, and operation
213 std::sort(boost::begin(turns), boost::end(turns),
214 detail::turns::less_seg_fraction_other_op<>());
216 // remove duplicate turns
217 turns::remove_duplicate_turns
219 Turns, EnableRemoveDuplicateTurns
222 return detail::overlay::following::linear::follow
227 OverlayTypeForFollow,
228 FollowIsolatedPoints,
229 !EnableFilterContinueTurns || OverlayType == overlay_intersection
230 >::apply(linear1, linear2, boost::begin(turns), boost::end(turns),
237 typename RobustPolicy, typename OutputIterator, typename Strategy
239 static inline OutputIterator apply(Linear1 const& linear1,
240 Linear2 const& linear2,
241 RobustPolicy const& robust_policy,
243 Strategy const& strategy)
245 typedef typename detail::relate::turns::get_turns
249 detail::get_turns::get_turn_info_type
256 >::turn_info turn_info;
258 typedef std::vector<turn_info> turns_container;
260 turns_container turns;
261 compute_turns(turns, linear1, linear2, strategy, robust_policy);
265 // the two linear geometries are disjoint
266 return linear_linear_no_intersections
271 typename tag<Linear1>::type
272 >::apply(linear1, oit);
275 return sort_and_follow_turns
278 EnableFollowIsolatedPoints
279 && OverlayType == overlay_intersection
280 >(turns, linear1, linear2, oit);
291 typename LinestringOut,
292 bool EnableFilterContinueTurns,
293 bool EnableRemoveDuplicateTurns,
294 bool EnableDegenerateTurns,
295 bool EnableFollowIsolatedPoints
297 struct linear_linear_linestring
299 Linear1, Linear2, LinestringOut, overlay_union,
300 EnableFilterContinueTurns, EnableRemoveDuplicateTurns,
301 EnableDegenerateTurns, EnableFollowIsolatedPoints
306 typename RobustPolicy, typename OutputIterator, typename Strategy
308 static inline OutputIterator apply(Linear1 const& linear1,
309 Linear2 const& linear2,
310 RobustPolicy const& robust_policy,
312 Strategy const& strategy)
314 oit = linear_linear_no_intersections
319 typename tag<Linear1>::type
320 >::apply(linear1, oit);
322 return linear_linear_linestring
324 Linear2, Linear1, LinestringOut, overlay_difference,
325 EnableFilterContinueTurns, EnableRemoveDuplicateTurns,
326 EnableDegenerateTurns, EnableFollowIsolatedPoints
327 >::apply(linear2, linear1, robust_policy, oit, strategy);
334 }} // namespace detail::overlay
335 #endif // DOXYGEN_NO_DETAIL
338 }} // namespace boost::geometry
342 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_LINEAR_LINEAR_HPP