1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 
3 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
4 
5 // Use, modification and distribution is subject to the Boost Software License,
6 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
8 
9 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_GET_INTERSECTION_POINTS_HPP
10 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_GET_INTERSECTION_POINTS_HPP
11 
12 
13 #include <cstddef>
14 
15 #include <boost/mpl/if.hpp>
16 #include <boost/range.hpp>
17 
18 #include <boost/geometry/algorithms/convert.hpp>
19 #include <boost/geometry/algorithms/detail/overlay/get_turns.hpp>
20 
21 #include <boost/geometry/geometries/segment.hpp>
22 
23 #include <boost/geometry/policies/robustness/robust_point_type.hpp>
24 
25 namespace boost { namespace geometry
26 {
27 
28 
29 #ifndef DOXYGEN_NO_DETAIL
30 namespace detail { namespace get_intersection_points
31 {
32 
33 
34 template
35 <
36     typename Point1,
37     typename Point2,
38     typename TurnInfo
39 >
40 struct get_turn_without_info
41 {
42     template <typename RobustPolicy, typename OutputIterator>
applyboost::geometry::detail::get_intersection_points::get_turn_without_info43     static inline OutputIterator apply(
44                 Point1 const& pi, Point1 const& pj, Point1 const& /*pk*/,
45                 Point2 const& qi, Point2 const& qj, Point2 const& /*qk*/,
46                 bool /*is_p_first*/, bool /*is_p_last*/,
47                 bool /*is_q_first*/, bool /*is_q_last*/,
48                 TurnInfo const& ,
49                 RobustPolicy const& robust_policy,
50                 OutputIterator out)
51     {
52         typedef strategy_intersection
53             <
54                 typename cs_tag<typename TurnInfo::point_type>::type,
55                 Point1,
56                 Point2,
57                 typename TurnInfo::point_type,
58                 RobustPolicy
59             > si;
60 
61         typedef typename si::segment_intersection_strategy_type strategy;
62 
63         typedef model::referring_segment<Point1 const> segment_type1;
64         typedef model::referring_segment<Point1 const> segment_type2;
65         segment_type1 p1(pi, pj);
66         segment_type2 q1(qi, qj);
67 
68         typedef typename geometry::robust_point_type
69             <
70                 Point1, RobustPolicy
71             >::type robust_point_type;
72 
73         robust_point_type pi_rob, pj_rob, qi_rob, qj_rob;
74         geometry::recalculate(pi_rob, pi, robust_policy);
75         geometry::recalculate(pj_rob, pj, robust_policy);
76         geometry::recalculate(qi_rob, qi, robust_policy);
77         geometry::recalculate(qj_rob, qj, robust_policy);
78         typename strategy::return_type result
79             = strategy::apply(p1, q1, robust_policy,
80                               pi_rob, pj_rob, qi_rob, qj_rob);
81 
82         for (std::size_t i = 0; i < result.template get<0>().count; i++)
83         {
84 
85             TurnInfo tp;
86             geometry::convert(result.template get<0>().intersections[i], tp.point);
87             *out++ = tp;
88         }
89 
90         return out;
91     }
92 };
93 
94 }} // namespace detail::get_intersection_points
95 #endif // DOXYGEN_NO_DETAIL
96 
97 
98 
99 
100 template
101 <
102     typename Geometry1,
103     typename Geometry2,
104     typename RobustPolicy,
105     typename Turns
106 >
get_intersection_points(Geometry1 const & geometry1,Geometry2 const & geometry2,RobustPolicy const & robust_policy,Turns & turns)107 inline void get_intersection_points(Geometry1 const& geometry1,
108             Geometry2 const& geometry2,
109             RobustPolicy const& robust_policy,
110             Turns& turns)
111 {
112     concept::check_concepts_and_equal_dimensions<Geometry1 const, Geometry2 const>();
113 
114     typedef detail::get_intersection_points::get_turn_without_info
115                         <
116                             typename point_type<Geometry1>::type,
117                             typename point_type<Geometry2>::type,
118                             typename boost::range_value<Turns>::type
119                         > TurnPolicy;
120 
121     detail::get_turns::no_interrupt_policy interrupt_policy;
122 
123     boost::mpl::if_c
124         <
125             reverse_dispatch<Geometry1, Geometry2>::type::value,
126             dispatch::get_turns_reversed
127             <
128                 typename tag<Geometry1>::type,
129                 typename tag<Geometry2>::type,
130                 Geometry1, Geometry2,
131                 false, false,
132                 TurnPolicy
133             >,
134             dispatch::get_turns
135             <
136                 typename tag<Geometry1>::type,
137                 typename tag<Geometry2>::type,
138                 Geometry1, Geometry2,
139                 false, false,
140                 TurnPolicy
141             >
142         >::type::apply(
143             0, geometry1,
144             1, geometry2,
145             robust_policy,
146             turns, interrupt_policy);
147 }
148 
149 
150 
151 
152 }} // namespace boost::geometry
153 
154 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_GET_INTERSECTION_POINTS_HPP
155