1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
5 // This file was modified by Oracle on 2014, 2017.
6 // Modifications copyright (c) 2014-2017, Oracle and/or its affiliates.
8 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
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)
14 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_INTERSECTION_INTERFACE_HPP
15 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_INTERSECTION_INTERFACE_HPP
18 #include <boost/variant/apply_visitor.hpp>
19 #include <boost/variant/static_visitor.hpp>
20 #include <boost/variant/variant_fwd.hpp>
22 #include <boost/geometry/algorithms/detail/overlay/intersection_insert.hpp>
23 #include <boost/geometry/policies/robustness/get_rescale_policy.hpp>
24 #include <boost/geometry/strategies/default_strategy.hpp>
25 #include <boost/geometry/util/range.hpp>
28 namespace boost { namespace geometry
32 #ifndef DOXYGEN_NO_DISPATCH
36 // By default, all is forwarded to the intersection_insert-dispatcher
39 typename Geometry1, typename Geometry2,
40 typename Tag1 = typename geometry::tag<Geometry1>::type,
41 typename Tag2 = typename geometry::tag<Geometry2>::type,
42 bool Reverse = reverse_dispatch<Geometry1, Geometry2>::type::value
46 template <typename RobustPolicy, typename GeometryOut, typename Strategy>
47 static inline bool apply(Geometry1 const& geometry1,
48 Geometry2 const& geometry2,
49 RobustPolicy const& robust_policy,
50 GeometryOut& geometry_out,
51 Strategy const& strategy)
53 typedef typename boost::range_value<GeometryOut>::type OneOut;
57 Geometry1, Geometry2, OneOut,
59 >::apply(geometry1, geometry2, robust_policy,
60 range::back_inserter(geometry_out), strategy);
68 // If reversal is needed, perform it
71 typename Geometry1, typename Geometry2,
72 typename Tag1, typename Tag2
80 : intersection<Geometry2, Geometry1, Tag2, Tag1, false>
82 template <typename RobustPolicy, typename GeometryOut, typename Strategy>
83 static inline bool apply(
86 RobustPolicy const& robust_policy,
88 Strategy const& strategy)
95 >::apply(g2, g1, robust_policy, out, strategy);
100 } // namespace dispatch
101 #endif // DOXYGEN_NO_DISPATCH
104 namespace resolve_strategy {
112 typename RobustPolicy,
113 typename GeometryOut,
116 static inline bool apply(Geometry1 const& geometry1,
117 Geometry2 const& geometry2,
118 RobustPolicy const& robust_policy,
119 GeometryOut & geometry_out,
120 Strategy const& strategy)
122 return dispatch::intersection
126 >::apply(geometry1, geometry2, robust_policy, geometry_out,
134 typename RobustPolicy,
137 static inline bool apply(Geometry1 const& geometry1,
138 Geometry2 const& geometry2,
139 RobustPolicy const& robust_policy,
140 GeometryOut & geometry_out,
143 typedef typename strategy::relate::services::default_strategy
146 >::type strategy_type;
148 return dispatch::intersection
152 >::apply(geometry1, geometry2, robust_policy, geometry_out,
157 } // resolve_strategy
160 namespace resolve_variant
163 template <typename Geometry1, typename Geometry2>
166 template <typename GeometryOut, typename Strategy>
167 static inline bool apply(Geometry1 const& geometry1,
168 Geometry2 const& geometry2,
169 GeometryOut& geometry_out,
170 Strategy const& strategy)
172 concepts::check<Geometry1 const>();
173 concepts::check<Geometry2 const>();
175 typedef typename geometry::rescale_overlay_policy_type
179 >::type rescale_policy_type;
181 rescale_policy_type robust_policy
182 = geometry::get_rescale_policy<rescale_policy_type>(geometry1,
185 return resolve_strategy::intersection::apply(geometry1,
194 template <BOOST_VARIANT_ENUM_PARAMS(typename T), typename Geometry2>
195 struct intersection<variant<BOOST_VARIANT_ENUM_PARAMS(T)>, Geometry2>
197 template <typename GeometryOut, typename Strategy>
198 struct visitor: static_visitor<bool>
200 Geometry2 const& m_geometry2;
201 GeometryOut& m_geometry_out;
202 Strategy const& m_strategy;
204 visitor(Geometry2 const& geometry2,
205 GeometryOut& geometry_out,
206 Strategy const& strategy)
207 : m_geometry2(geometry2)
208 , m_geometry_out(geometry_out)
209 , m_strategy(strategy)
212 template <typename Geometry1>
213 bool operator()(Geometry1 const& geometry1) const
219 >::apply(geometry1, m_geometry2, m_geometry_out, m_strategy);
223 template <typename GeometryOut, typename Strategy>
225 apply(variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry1,
226 Geometry2 const& geometry2,
227 GeometryOut& geometry_out,
228 Strategy const& strategy)
230 return boost::apply_visitor(visitor<GeometryOut, Strategy>(geometry2,
238 template <typename Geometry1, BOOST_VARIANT_ENUM_PARAMS(typename T)>
239 struct intersection<Geometry1, variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
241 template <typename GeometryOut, typename Strategy>
242 struct visitor: static_visitor<bool>
244 Geometry1 const& m_geometry1;
245 GeometryOut& m_geometry_out;
246 Strategy const& m_strategy;
248 visitor(Geometry1 const& geometry1,
249 GeometryOut& geometry_out,
250 Strategy const& strategy)
251 : m_geometry1(geometry1)
252 , m_geometry_out(geometry_out)
253 , m_strategy(strategy)
256 template <typename Geometry2>
257 bool operator()(Geometry2 const& geometry2) const
263 >::apply(m_geometry1, geometry2, m_geometry_out, m_strategy);
267 template <typename GeometryOut, typename Strategy>
269 apply(Geometry1 const& geometry1,
270 variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry2,
271 GeometryOut& geometry_out,
272 Strategy const& strategy)
274 return boost::apply_visitor(visitor<GeometryOut, Strategy>(geometry1,
282 template <BOOST_VARIANT_ENUM_PARAMS(typename T1), BOOST_VARIANT_ENUM_PARAMS(typename T2)>
283 struct intersection<variant<BOOST_VARIANT_ENUM_PARAMS(T1)>, variant<BOOST_VARIANT_ENUM_PARAMS(T2)> >
285 template <typename GeometryOut, typename Strategy>
286 struct visitor: static_visitor<bool>
288 GeometryOut& m_geometry_out;
289 Strategy const& m_strategy;
291 visitor(GeometryOut& geometry_out, Strategy const& strategy)
292 : m_geometry_out(geometry_out)
293 , m_strategy(strategy)
296 template <typename Geometry1, typename Geometry2>
297 bool operator()(Geometry1 const& geometry1,
298 Geometry2 const& geometry2) const
304 >::apply(geometry1, geometry2, m_geometry_out, m_strategy);
308 template <typename GeometryOut, typename Strategy>
310 apply(variant<BOOST_VARIANT_ENUM_PARAMS(T1)> const& geometry1,
311 variant<BOOST_VARIANT_ENUM_PARAMS(T2)> const& geometry2,
312 GeometryOut& geometry_out,
313 Strategy const& strategy)
315 return boost::apply_visitor(visitor<GeometryOut, Strategy>(geometry_out,
317 geometry1, geometry2);
321 } // namespace resolve_variant
325 \brief \brief_calc2{intersection}
326 \ingroup intersection
327 \details \details_calc2{intersection, spatial set theoretic intersection}.
328 \tparam Geometry1 \tparam_geometry
329 \tparam Geometry2 \tparam_geometry
330 \tparam GeometryOut Collection of geometries (e.g. std::vector, std::deque, boost::geometry::multi*) of which
331 the value_type fulfills a \p_l_or_c concept, or it is the output geometry (e.g. for a box)
332 \tparam Strategy \tparam_strategy{Intersection}
333 \param geometry1 \param_geometry
334 \param geometry2 \param_geometry
335 \param geometry_out The output geometry, either a multi_point, multi_polygon,
336 multi_linestring, or a box (for intersection of two boxes)
337 \param strategy \param_strategy{intersection}
339 \qbk{distinguish,with strategy}
340 \qbk{[include reference/algorithms/intersection.qbk]}
346 typename GeometryOut,
349 inline bool intersection(Geometry1 const& geometry1,
350 Geometry2 const& geometry2,
351 GeometryOut& geometry_out,
352 Strategy const& strategy)
354 return resolve_variant::intersection
358 >::apply(geometry1, geometry2, geometry_out, strategy);
363 \brief \brief_calc2{intersection}
364 \ingroup intersection
365 \details \details_calc2{intersection, spatial set theoretic intersection}.
366 \tparam Geometry1 \tparam_geometry
367 \tparam Geometry2 \tparam_geometry
368 \tparam GeometryOut Collection of geometries (e.g. std::vector, std::deque, boost::geometry::multi*) of which
369 the value_type fulfills a \p_l_or_c concept, or it is the output geometry (e.g. for a box)
370 \param geometry1 \param_geometry
371 \param geometry2 \param_geometry
372 \param geometry_out The output geometry, either a multi_point, multi_polygon,
373 multi_linestring, or a box (for intersection of two boxes)
375 \qbk{[include reference/algorithms/intersection.qbk]}
383 inline bool intersection(Geometry1 const& geometry1,
384 Geometry2 const& geometry2,
385 GeometryOut& geometry_out)
387 return resolve_variant::intersection
391 >::apply(geometry1, geometry2, geometry_out, default_strategy());
395 }} // namespace boost::geometry
398 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_INTERSECTION_INTERFACE_HPP