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.
6 // Modifications copyright (c) 2014, 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 // TODO: those headers probably may be removed
19 #include <boost/geometry/core/coordinate_dimension.hpp>
20 #include <boost/geometry/algorithms/intersects.hpp>
22 #include <boost/geometry/algorithms/detail/overlay/intersection_insert.hpp>
23 #include <boost/geometry/policies/robustness/get_rescale_policy.hpp>
26 namespace boost { namespace geometry
30 #ifndef DOXYGEN_NO_DISPATCH
34 // By default, all is forwarded to the intersection_insert-dispatcher
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
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)
51 typedef typename boost::range_value<GeometryOut>::type OneOut;
55 Geometry1, Geometry2, OneOut,
57 >::apply(geometry1, geometry2, robust_policy, range::back_inserter(geometry_out), strategy);
65 // If reversal is needed, perform it
68 typename Geometry1, typename Geometry2,
69 typename Tag1, typename Tag2
77 : intersection<Geometry2, Geometry1, Tag2, Tag1, false>
79 template <typename RobustPolicy, typename GeometryOut, typename Strategy>
80 static inline bool apply(
83 RobustPolicy const& robust_policy,
85 Strategy const& strategy)
91 >::apply(g2, g1, robust_policy, out, strategy);
96 } // namespace dispatch
97 #endif // DOXYGEN_NO_DISPATCH
100 namespace resolve_variant
103 template <typename Geometry1, typename Geometry2>
106 template <typename GeometryOut>
109 const Geometry1& geometry1,
110 const Geometry2& geometry2,
111 GeometryOut& geometry_out)
113 concepts::check<Geometry1 const>();
114 concepts::check<Geometry2 const>();
116 typedef typename geometry::rescale_overlay_policy_type
120 >::type rescale_policy_type;
122 rescale_policy_type robust_policy
123 = geometry::get_rescale_policy<rescale_policy_type>(geometry1,
126 typedef intersection_strategies
128 typename cs_tag<Geometry1>::type,
131 typename geometry::point_type<Geometry1>::type,
135 return dispatch::intersection
139 >::apply(geometry1, geometry2, robust_policy, geometry_out, strategy());
144 template <BOOST_VARIANT_ENUM_PARAMS(typename T), typename Geometry2>
145 struct intersection<variant<BOOST_VARIANT_ENUM_PARAMS(T)>, Geometry2>
147 template <typename GeometryOut>
148 struct visitor: static_visitor<bool>
150 Geometry2 const& m_geometry2;
151 GeometryOut& m_geometry_out;
153 visitor(Geometry2 const& geometry2,
154 GeometryOut& geometry_out)
155 : m_geometry2(geometry2)
156 , m_geometry_out(geometry_out)
159 template <typename Geometry1>
160 result_type operator()(Geometry1 const& geometry1) const
170 (geometry1, m_geometry2, m_geometry_out);
174 template <typename GeometryOut>
176 apply(variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry1,
177 Geometry2 const& geometry2,
178 GeometryOut& geometry_out)
180 return boost::apply_visitor(visitor<GeometryOut>(geometry2, geometry_out), geometry1);
185 template <typename Geometry1, BOOST_VARIANT_ENUM_PARAMS(typename T)>
186 struct intersection<Geometry1, variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
188 template <typename GeometryOut>
189 struct visitor: static_visitor<bool>
191 Geometry1 const& m_geometry1;
192 GeometryOut& m_geometry_out;
194 visitor(Geometry1 const& geometry1,
195 GeometryOut& geometry_out)
196 : m_geometry1(geometry1)
197 , m_geometry_out(geometry_out)
200 template <typename Geometry2>
201 result_type operator()(Geometry2 const& geometry2) const
211 (m_geometry1, geometry2, m_geometry_out);
215 template <typename GeometryOut>
217 apply(Geometry1 const& geometry1,
218 const variant<BOOST_VARIANT_ENUM_PARAMS(T)>& geometry2,
219 GeometryOut& geometry_out)
221 return boost::apply_visitor(visitor<GeometryOut>(geometry1, geometry_out), geometry2);
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)> >
229 template <typename GeometryOut>
230 struct visitor: static_visitor<bool>
232 GeometryOut& m_geometry_out;
234 visitor(GeometryOut& geometry_out)
235 : m_geometry_out(geometry_out)
238 template <typename Geometry1, typename Geometry2>
239 result_type operator()(Geometry1 const& geometry1,
240 Geometry2 const& geometry2) const
250 (geometry1, geometry2, m_geometry_out);
254 template <typename GeometryOut>
256 apply(const variant<BOOST_VARIANT_ENUM_PARAMS(T1)>& geometry1,
257 const variant<BOOST_VARIANT_ENUM_PARAMS(T2)>& geometry2,
258 GeometryOut& geometry_out)
260 return boost::apply_visitor(visitor<GeometryOut>(geometry_out), geometry1, geometry2);
264 } // namespace resolve_variant
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)
280 \qbk{[include reference/algorithms/intersection.qbk]}
288 inline bool intersection(Geometry1 const& geometry1,
289 Geometry2 const& geometry2,
290 GeometryOut& geometry_out)
292 return resolve_variant::intersection
300 (geometry1, geometry2, geometry_out);
304 }} // namespace boost::geometry
307 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_INTERSECTION_INTERFACE_HPP