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 
26 #include <boost/geometry/geometries/segment.hpp>
27 
28 #include <boost/geometry/policies/robustness/robust_point_type.hpp>
29 
30 namespace boost { namespace geometry
31 {
32 
33 
34 #ifndef DOXYGEN_NO_DETAIL
35 namespace detail { namespace get_intersection_points
36 {
37 
38 
39 template
40 <
41     typename Point1,
42     typename Point2,
43     typename TurnInfo
44 >
45 struct get_turn_without_info
46 {
47     template
48     <
49         typename UniqueSubRange1,
50         typename UniqueSubRange2,
51         typename Strategy,
52         typename RobustPolicy,
53         typename OutputIterator
54     >
applyboost::geometry::detail::get_intersection_points::get_turn_without_info55     static inline OutputIterator apply(UniqueSubRange1 const& range_p,
56                 UniqueSubRange2 const& range_q,
57                 TurnInfo const& ,
58                 Strategy const& strategy,
59                 RobustPolicy const& robust_policy,
60                 OutputIterator out)
61     {
62         typedef typename TurnInfo::point_type turn_point_type;
63 
64         typedef policies::relate::segments_intersection_points
65             <
66                 segment_intersection_points
67                     <
68                         turn_point_type,
69                         typename geometry::segment_ratio_type
70                             <
71                                 turn_point_type, RobustPolicy
72                             >::type
73                     >
74             > policy_type;
75 
76         typedef model::referring_segment<Point1 const> segment_type1;
77         typedef model::referring_segment<Point2 const> segment_type2;
78         Point1 const& pi = range_p.at(0);
79         Point1 const& pj = range_p.at(1);
80         Point2 const& qi = range_q.at(0);
81         Point2 const& qj = range_q.at(1);
82         segment_type1 p1(pi, pj);
83         segment_type2 q1(qi, qj);
84 
85         typedef typename geometry::robust_point_type
86             <
87                 Point1, RobustPolicy
88             >::type robust_point_type;
89 
90         robust_point_type pi_rob, pj_rob, qi_rob, qj_rob;
91         geometry::recalculate(pi_rob, pi, robust_policy);
92         geometry::recalculate(pj_rob, pj, robust_policy);
93         geometry::recalculate(qi_rob, qi, robust_policy);
94         geometry::recalculate(qj_rob, qj, robust_policy);
95         typename policy_type::return_type result
96             = strategy.apply(p1, q1, policy_type(), robust_policy,
97                              pi_rob, pj_rob, qi_rob, qj_rob);
98 
99         for (std::size_t i = 0; i < result.count; i++)
100         {
101             TurnInfo tp;
102             geometry::convert(result.intersections[i], tp.point);
103             *out++ = tp;
104         }
105 
106         return out;
107     }
108 };
109 
110 }} // namespace detail::get_intersection_points
111 #endif // DOXYGEN_NO_DETAIL
112 
113 
114 
115 
116 template
117 <
118     typename Geometry1,
119     typename Geometry2,
120     typename RobustPolicy,
121     typename Turns,
122     typename Strategy
123 >
get_intersection_points(Geometry1 const & geometry1,Geometry2 const & geometry2,RobustPolicy const & robust_policy,Turns & turns,Strategy const & strategy)124 inline void get_intersection_points(Geometry1 const& geometry1,
125             Geometry2 const& geometry2,
126             RobustPolicy const& robust_policy,
127             Turns& turns,
128             Strategy const& strategy)
129 {
130     concepts::check_concepts_and_equal_dimensions<Geometry1 const, Geometry2 const>();
131 
132     typedef detail::get_intersection_points::get_turn_without_info
133                         <
134                             typename point_type<Geometry1>::type,
135                             typename point_type<Geometry2>::type,
136                             typename boost::range_value<Turns>::type
137                         > TurnPolicy;
138 
139     detail::get_turns::no_interrupt_policy interrupt_policy;
140 
141     boost::mpl::if_c
142         <
143             reverse_dispatch<Geometry1, Geometry2>::type::value,
144             dispatch::get_turns_reversed
145             <
146                 typename tag<Geometry1>::type,
147                 typename tag<Geometry2>::type,
148                 Geometry1, Geometry2,
149                 false, false,
150                 TurnPolicy
151             >,
152             dispatch::get_turns
153             <
154                 typename tag<Geometry1>::type,
155                 typename tag<Geometry2>::type,
156                 Geometry1, Geometry2,
157                 false, false,
158                 TurnPolicy
159             >
160         >::type::apply(
161             0, geometry1,
162             1, geometry2,
163             strategy,
164             robust_policy,
165             turns, interrupt_policy);
166 }
167 
168 
169 
170 
171 }} // namespace boost::geometry
172 
173 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_GET_INTERSECTION_POINTS_HPP
174