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