]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 2014. | |
6 | // Modifications copyright (c) 2014, 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_INTERSECTION_INTERFACE_HPP | |
15 | #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_INTERSECTION_INTERFACE_HPP | |
16 | ||
17 | ||
18 | // TODO: those headers probably may be removed | |
19 | #include <boost/geometry/core/coordinate_dimension.hpp> | |
20 | #include <boost/geometry/algorithms/intersects.hpp> | |
21 | ||
22 | #include <boost/geometry/algorithms/detail/overlay/intersection_insert.hpp> | |
23 | #include <boost/geometry/policies/robustness/get_rescale_policy.hpp> | |
24 | ||
25 | ||
26 | namespace boost { namespace geometry | |
27 | { | |
28 | ||
29 | ||
30 | #ifndef DOXYGEN_NO_DISPATCH | |
31 | namespace dispatch | |
32 | { | |
33 | ||
34 | // By default, all is forwarded to the intersection_insert-dispatcher | |
35 | template | |
36 | < | |
37 | typename Geometry1, typename Geometry2, | |
38 | typename Tag1 = typename geometry::tag<Geometry1>::type, | |
39 | typename Tag2 = typename geometry::tag<Geometry2>::type, | |
40 | bool Reverse = reverse_dispatch<Geometry1, Geometry2>::type::value | |
41 | > | |
42 | struct intersection | |
43 | { | |
44 | template <typename RobustPolicy, typename GeometryOut, typename Strategy> | |
45 | static inline bool apply(Geometry1 const& geometry1, | |
46 | Geometry2 const& geometry2, | |
47 | RobustPolicy const& robust_policy, | |
48 | GeometryOut& geometry_out, | |
49 | Strategy const& strategy) | |
50 | { | |
51 | typedef typename boost::range_value<GeometryOut>::type OneOut; | |
52 | ||
53 | intersection_insert | |
54 | < | |
55 | Geometry1, Geometry2, OneOut, | |
56 | overlay_intersection | |
57 | >::apply(geometry1, geometry2, robust_policy, range::back_inserter(geometry_out), strategy); | |
58 | ||
59 | return true; | |
60 | } | |
61 | ||
62 | }; | |
63 | ||
64 | ||
65 | // If reversal is needed, perform it | |
66 | template | |
67 | < | |
68 | typename Geometry1, typename Geometry2, | |
69 | typename Tag1, typename Tag2 | |
70 | > | |
71 | struct intersection | |
72 | < | |
73 | Geometry1, Geometry2, | |
74 | Tag1, Tag2, | |
75 | true | |
76 | > | |
77 | : intersection<Geometry2, Geometry1, Tag2, Tag1, false> | |
78 | { | |
79 | template <typename RobustPolicy, typename GeometryOut, typename Strategy> | |
80 | static inline bool apply( | |
81 | Geometry1 const& g1, | |
82 | Geometry2 const& g2, | |
83 | RobustPolicy const& robust_policy, | |
84 | GeometryOut& out, | |
85 | Strategy const& strategy) | |
86 | { | |
87 | return intersection< | |
88 | Geometry2, Geometry1, | |
89 | Tag2, Tag1, | |
90 | false | |
91 | >::apply(g2, g1, robust_policy, out, strategy); | |
92 | } | |
93 | }; | |
94 | ||
95 | ||
96 | } // namespace dispatch | |
97 | #endif // DOXYGEN_NO_DISPATCH | |
98 | ||
99 | ||
100 | namespace resolve_variant | |
101 | { | |
102 | ||
103 | template <typename Geometry1, typename Geometry2> | |
104 | struct intersection | |
105 | { | |
106 | template <typename GeometryOut> | |
107 | static inline bool | |
108 | apply( | |
109 | const Geometry1& geometry1, | |
110 | const Geometry2& geometry2, | |
111 | GeometryOut& geometry_out) | |
112 | { | |
113 | concepts::check<Geometry1 const>(); | |
114 | concepts::check<Geometry2 const>(); | |
115 | ||
116 | typedef typename geometry::rescale_overlay_policy_type | |
117 | < | |
118 | Geometry1, | |
119 | Geometry2 | |
120 | >::type rescale_policy_type; | |
121 | ||
122 | rescale_policy_type robust_policy | |
123 | = geometry::get_rescale_policy<rescale_policy_type>(geometry1, | |
124 | geometry2); | |
125 | ||
126 | typedef intersection_strategies | |
127 | < | |
128 | typename cs_tag<Geometry1>::type, | |
129 | Geometry1, | |
130 | Geometry2, | |
131 | typename geometry::point_type<Geometry1>::type, | |
132 | rescale_policy_type | |
133 | > strategy; | |
134 | ||
135 | return dispatch::intersection | |
136 | < | |
137 | Geometry1, | |
138 | Geometry2 | |
139 | >::apply(geometry1, geometry2, robust_policy, geometry_out, strategy()); | |
140 | } | |
141 | }; | |
142 | ||
143 | ||
144 | template <BOOST_VARIANT_ENUM_PARAMS(typename T), typename Geometry2> | |
145 | struct intersection<variant<BOOST_VARIANT_ENUM_PARAMS(T)>, Geometry2> | |
146 | { | |
147 | template <typename GeometryOut> | |
148 | struct visitor: static_visitor<bool> | |
149 | { | |
150 | Geometry2 const& m_geometry2; | |
151 | GeometryOut& m_geometry_out; | |
152 | ||
153 | visitor(Geometry2 const& geometry2, | |
154 | GeometryOut& geometry_out) | |
155 | : m_geometry2(geometry2) | |
156 | , m_geometry_out(geometry_out) | |
157 | {} | |
158 | ||
159 | template <typename Geometry1> | |
160 | result_type operator()(Geometry1 const& geometry1) const | |
161 | { | |
162 | return intersection | |
163 | < | |
164 | Geometry1, | |
165 | Geometry2 | |
166 | >::template apply | |
167 | < | |
168 | GeometryOut | |
169 | > | |
170 | (geometry1, m_geometry2, m_geometry_out); | |
171 | } | |
172 | }; | |
173 | ||
174 | template <typename GeometryOut> | |
175 | static inline bool | |
176 | apply(variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry1, | |
177 | Geometry2 const& geometry2, | |
178 | GeometryOut& geometry_out) | |
179 | { | |
180 | return boost::apply_visitor(visitor<GeometryOut>(geometry2, geometry_out), geometry1); | |
181 | } | |
182 | }; | |
183 | ||
184 | ||
185 | template <typename Geometry1, BOOST_VARIANT_ENUM_PARAMS(typename T)> | |
186 | struct intersection<Geometry1, variant<BOOST_VARIANT_ENUM_PARAMS(T)> > | |
187 | { | |
188 | template <typename GeometryOut> | |
189 | struct visitor: static_visitor<bool> | |
190 | { | |
191 | Geometry1 const& m_geometry1; | |
192 | GeometryOut& m_geometry_out; | |
193 | ||
194 | visitor(Geometry1 const& geometry1, | |
195 | GeometryOut& geometry_out) | |
196 | : m_geometry1(geometry1) | |
197 | , m_geometry_out(geometry_out) | |
198 | {} | |
199 | ||
200 | template <typename Geometry2> | |
201 | result_type operator()(Geometry2 const& geometry2) const | |
202 | { | |
203 | return intersection | |
204 | < | |
205 | Geometry1, | |
206 | Geometry2 | |
207 | >::template apply | |
208 | < | |
209 | GeometryOut | |
210 | > | |
211 | (m_geometry1, geometry2, m_geometry_out); | |
212 | } | |
213 | }; | |
214 | ||
215 | template <typename GeometryOut> | |
216 | static inline bool | |
217 | apply(Geometry1 const& geometry1, | |
218 | const variant<BOOST_VARIANT_ENUM_PARAMS(T)>& geometry2, | |
219 | GeometryOut& geometry_out) | |
220 | { | |
221 | return boost::apply_visitor(visitor<GeometryOut>(geometry1, geometry_out), geometry2); | |
222 | } | |
223 | }; | |
224 | ||
225 | ||
226 | template <BOOST_VARIANT_ENUM_PARAMS(typename T1), BOOST_VARIANT_ENUM_PARAMS(typename T2)> | |
227 | struct intersection<variant<BOOST_VARIANT_ENUM_PARAMS(T1)>, variant<BOOST_VARIANT_ENUM_PARAMS(T2)> > | |
228 | { | |
229 | template <typename GeometryOut> | |
230 | struct visitor: static_visitor<bool> | |
231 | { | |
232 | GeometryOut& m_geometry_out; | |
233 | ||
234 | visitor(GeometryOut& geometry_out) | |
235 | : m_geometry_out(geometry_out) | |
236 | {} | |
237 | ||
238 | template <typename Geometry1, typename Geometry2> | |
239 | result_type operator()(Geometry1 const& geometry1, | |
240 | Geometry2 const& geometry2) const | |
241 | { | |
242 | return intersection | |
243 | < | |
244 | Geometry1, | |
245 | Geometry2 | |
246 | >::template apply | |
247 | < | |
248 | GeometryOut | |
249 | > | |
250 | (geometry1, geometry2, m_geometry_out); | |
251 | } | |
252 | }; | |
253 | ||
254 | template <typename GeometryOut> | |
255 | static inline bool | |
256 | apply(const variant<BOOST_VARIANT_ENUM_PARAMS(T1)>& geometry1, | |
257 | const variant<BOOST_VARIANT_ENUM_PARAMS(T2)>& geometry2, | |
258 | GeometryOut& geometry_out) | |
259 | { | |
260 | return boost::apply_visitor(visitor<GeometryOut>(geometry_out), geometry1, geometry2); | |
261 | } | |
262 | }; | |
263 | ||
264 | } // namespace resolve_variant | |
265 | ||
266 | ||
267 | /*! | |
268 | \brief \brief_calc2{intersection} | |
269 | \ingroup intersection | |
270 | \details \details_calc2{intersection, spatial set theoretic intersection}. | |
271 | \tparam Geometry1 \tparam_geometry | |
272 | \tparam Geometry2 \tparam_geometry | |
273 | \tparam GeometryOut Collection of geometries (e.g. std::vector, std::deque, boost::geometry::multi*) of which | |
274 | the value_type fulfills a \p_l_or_c concept, or it is the output geometry (e.g. for a box) | |
275 | \param geometry1 \param_geometry | |
276 | \param geometry2 \param_geometry | |
277 | \param geometry_out The output geometry, either a multi_point, multi_polygon, | |
278 | multi_linestring, or a box (for intersection of two boxes) | |
279 | ||
280 | \qbk{[include reference/algorithms/intersection.qbk]} | |
281 | */ | |
282 | template | |
283 | < | |
284 | typename Geometry1, | |
285 | typename Geometry2, | |
286 | typename GeometryOut | |
287 | > | |
288 | inline bool intersection(Geometry1 const& geometry1, | |
289 | Geometry2 const& geometry2, | |
290 | GeometryOut& geometry_out) | |
291 | { | |
292 | return resolve_variant::intersection | |
293 | < | |
294 | Geometry1, | |
295 | Geometry2 | |
296 | >::template apply | |
297 | < | |
298 | GeometryOut | |
299 | > | |
300 | (geometry1, geometry2, geometry_out); | |
301 | } | |
302 | ||
303 | ||
304 | }} // namespace boost::geometry | |
305 | ||
306 | ||
307 | #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_INTERSECTION_INTERFACE_HPP |