Imported Upstream version 1.72.0
[platform/upstream/boost.git] / boost / geometry / algorithms / detail / overlay / get_intersection_points.hpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2
3 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
4
5 // This file was modified by Oracle on 2017.
6 // Modifications copyright (c) 2017 Oracle and/or its affiliates.
7
8 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
9
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)
13
14 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_GET_INTERSECTION_POINTS_HPP
15 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_GET_INTERSECTION_POINTS_HPP
16
17
18 #include <cstddef>
19
20 #include <boost/mpl/if.hpp>
21 #include <boost/range.hpp>
22
23 #include <boost/geometry/algorithms/convert.hpp>
24 #include <boost/geometry/algorithms/detail/overlay/get_turns.hpp>
25 #include <boost/geometry/policies/robustness/rescale_policy_tags.hpp>
26
27 #include <boost/geometry/geometries/segment.hpp>
28
29 namespace boost { namespace geometry
30 {
31
32
33 #ifndef DOXYGEN_NO_DETAIL
34 namespace detail { namespace get_intersection_points
35 {
36
37
38 template
39 <
40     typename Point1,
41     typename Point2,
42     typename TurnInfo
43 >
44 struct get_turn_without_info
45 {
46     template
47     <
48         typename UniqueSubRange1,
49         typename UniqueSubRange2,
50         typename Strategy,
51         typename RobustPolicy,
52         typename OutputIterator
53     >
54     static inline OutputIterator apply(UniqueSubRange1 const& range_p,
55                 UniqueSubRange2 const& range_q,
56                 TurnInfo const& ,
57                 Strategy const& strategy,
58                 RobustPolicy const& ,
59                 OutputIterator out)
60     {
61         // Make sure this is only called with no rescaling
62         BOOST_STATIC_ASSERT((boost::is_same
63            <
64                no_rescale_policy_tag,
65                typename rescale_policy_type<RobustPolicy>::type
66            >::value));
67
68         typedef typename TurnInfo::point_type turn_point_type;
69
70         typedef policies::relate::segments_intersection_points
71             <
72                 segment_intersection_points<turn_point_type>
73             > policy_type;
74
75         typename policy_type::return_type const result
76             = strategy.apply(range_p, range_q, policy_type());
77
78         for (std::size_t i = 0; i < result.count; i++)
79         {
80             TurnInfo tp;
81             geometry::convert(result.intersections[i], tp.point);
82             *out++ = tp;
83         }
84
85         return out;
86     }
87 };
88
89 }} // namespace detail::get_intersection_points
90 #endif // DOXYGEN_NO_DETAIL
91
92
93
94
95 template
96 <
97     typename Geometry1,
98     typename Geometry2,
99     typename RobustPolicy,
100     typename Turns,
101     typename Strategy
102 >
103 inline void get_intersection_points(Geometry1 const& geometry1,
104             Geometry2 const& geometry2,
105             RobustPolicy const& robust_policy,
106             Turns& turns,
107             Strategy const& strategy)
108 {
109     concepts::check_concepts_and_equal_dimensions<Geometry1 const, Geometry2 const>();
110
111     typedef detail::get_intersection_points::get_turn_without_info
112                         <
113                             typename point_type<Geometry1>::type,
114                             typename point_type<Geometry2>::type,
115                             typename boost::range_value<Turns>::type
116                         > TurnPolicy;
117
118     detail::get_turns::no_interrupt_policy interrupt_policy;
119
120     boost::mpl::if_c
121         <
122             reverse_dispatch<Geometry1, Geometry2>::type::value,
123             dispatch::get_turns_reversed
124             <
125                 typename tag<Geometry1>::type,
126                 typename tag<Geometry2>::type,
127                 Geometry1, Geometry2,
128                 false, false,
129                 TurnPolicy
130             >,
131             dispatch::get_turns
132             <
133                 typename tag<Geometry1>::type,
134                 typename tag<Geometry2>::type,
135                 Geometry1, Geometry2,
136                 false, false,
137                 TurnPolicy
138             >
139         >::type::apply(
140             0, geometry1,
141             1, geometry2,
142             strategy,
143             robust_policy,
144             turns, interrupt_policy);
145 }
146
147
148
149
150 }} // namespace boost::geometry
151
152 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_GET_INTERSECTION_POINTS_HPP