Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-15 08:35:05

0001 // Boost.Geometry (aka GGL, Generic Geometry Library)
0002 
0003 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
0004 
0005 // This file was modified by Oracle on 2014-2024.
0006 // Modifications copyright (c) 2014-2024, Oracle and/or its affiliates.
0007 // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
0008 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
0009 
0010 // Use, modification and distribution is subject to the Boost Software License,
0011 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0012 // http://www.boost.org/LICENSE_1_0.txt)
0013 
0014 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_INTERSECTION_INTERFACE_HPP
0015 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_INTERSECTION_INTERFACE_HPP
0016 
0017 
0018 #include <boost/geometry/algorithms/detail/overlay/intersection_insert.hpp>
0019 #include <boost/geometry/algorithms/detail/tupled_output.hpp>
0020 #include <boost/geometry/geometries/adapted/boost_variant.hpp>
0021 #include <boost/geometry/strategies/default_strategy.hpp>
0022 #include <boost/geometry/strategies/detail.hpp>
0023 #include <boost/geometry/strategies/relate/services.hpp>
0024 #include <boost/geometry/util/range.hpp>
0025 #include <boost/geometry/util/type_traits_std.hpp>
0026 
0027 
0028 namespace boost { namespace geometry
0029 {
0030 
0031 
0032 #ifndef DOXYGEN_NO_DISPATCH
0033 namespace dispatch
0034 {
0035 
0036 // By default, all is forwarded to the intersection_insert-dispatcher
0037 template
0038 <
0039     typename Geometry1, typename Geometry2,
0040     typename Tag1 = geometry::tag_t<Geometry1>,
0041     typename Tag2 = geometry::tag_t<Geometry2>,
0042     bool Reverse = reverse_dispatch<Geometry1, Geometry2>::type::value
0043 >
0044 struct intersection
0045 {
0046     template <typename GeometryOut, typename Strategy>
0047     static inline bool apply(Geometry1 const& geometry1,
0048             Geometry2 const& geometry2,
0049             GeometryOut& geometry_out,
0050             Strategy const& strategy)
0051     {
0052         using single_out = typename geometry::detail::output_geometry_value
0053             <
0054                 GeometryOut
0055             >::type;
0056 
0057         intersection_insert
0058             <
0059                 Geometry1, Geometry2, single_out,
0060                 overlay_intersection
0061             >::apply(geometry1, geometry2,
0062                      geometry::detail::output_geometry_back_inserter(geometry_out),
0063                      strategy);
0064 
0065         return true;
0066     }
0067 
0068 };
0069 
0070 
0071 // If reversal is needed, perform it
0072 template
0073 <
0074     typename Geometry1, typename Geometry2,
0075     typename Tag1, typename Tag2
0076 >
0077 struct intersection
0078 <
0079     Geometry1, Geometry2,
0080     Tag1, Tag2,
0081     true
0082 >
0083     : intersection<Geometry2, Geometry1, Tag2, Tag1, false>
0084 {
0085     template <typename GeometryOut, typename Strategy>
0086     static inline bool apply(
0087         Geometry1 const& g1,
0088         Geometry2 const& g2,
0089         GeometryOut& out,
0090         Strategy const& strategy)
0091     {
0092         return intersection
0093             <
0094                 Geometry2, Geometry1,
0095                 Tag2, Tag1,
0096                 false
0097             >::apply(g2, g1, out, strategy);
0098     }
0099 };
0100 
0101 
0102 } // namespace dispatch
0103 #endif // DOXYGEN_NO_DISPATCH
0104 
0105 
0106 namespace resolve_collection
0107 {
0108 
0109 template
0110 <
0111     typename Geometry1, typename Geometry2, typename GeometryOut,
0112     typename Tag1 = geometry::tag_t<Geometry1>,
0113     typename Tag2 = geometry::tag_t<Geometry2>,
0114     typename TagOut = geometry::tag_t<GeometryOut>
0115 >
0116 struct intersection
0117 {
0118     template <typename Strategy>
0119     static bool apply(Geometry1 const& geometry1, Geometry2 const& geometry2,
0120                       GeometryOut & geometry_out, Strategy const& strategy)
0121     {
0122         return dispatch::intersection
0123             <
0124                 Geometry1,
0125                 Geometry2
0126             >::apply(geometry1, geometry2, geometry_out,
0127                      strategy);
0128     }
0129 };
0130 
0131 } // namespace resolve_collection
0132 
0133 
0134 namespace resolve_strategy {
0135 
0136 template
0137 <
0138     typename Strategy,
0139     bool IsUmbrella = strategies::detail::is_umbrella_strategy<Strategy>::value
0140 >
0141 struct intersection
0142 {
0143     template
0144     <
0145         typename Geometry1,
0146         typename Geometry2,
0147         typename GeometryOut
0148     >
0149     static inline bool apply(Geometry1 const& geometry1,
0150                              Geometry2 const& geometry2,
0151                              GeometryOut & geometry_out,
0152                              Strategy const& strategy)
0153     {
0154         return resolve_collection::intersection
0155             <
0156                 Geometry1, Geometry2, GeometryOut
0157             >::apply(geometry1, geometry2, geometry_out, strategy);
0158     }
0159 };
0160 
0161 template <typename Strategy>
0162 struct intersection<Strategy, false>
0163 {
0164     template
0165     <
0166         typename Geometry1,
0167         typename Geometry2,
0168         typename GeometryOut
0169     >
0170     static inline bool apply(Geometry1 const& geometry1,
0171                              Geometry2 const& geometry2,
0172                              GeometryOut & geometry_out,
0173                              Strategy const& strategy)
0174     {
0175         using strategies::relate::services::strategy_converter;
0176         return intersection
0177             <
0178                 decltype(strategy_converter<Strategy>::get(strategy))
0179             >::apply(geometry1, geometry2, geometry_out,
0180                      strategy_converter<Strategy>::get(strategy));
0181     }
0182 };
0183 
0184 template <>
0185 struct intersection<default_strategy, false>
0186 {
0187     template
0188     <
0189         typename Geometry1,
0190         typename Geometry2,
0191         typename GeometryOut
0192     >
0193     static inline bool apply(Geometry1 const& geometry1,
0194                              Geometry2 const& geometry2,
0195                              GeometryOut & geometry_out,
0196                              default_strategy)
0197     {
0198         using strategy_type = typename strategies::relate::services::default_strategy
0199             <
0200                 Geometry1, Geometry2
0201             >::type;
0202 
0203         return intersection
0204             <
0205                 strategy_type
0206             >::apply(geometry1, geometry2, geometry_out, strategy_type());
0207     }
0208 };
0209 
0210 } // resolve_strategy
0211 
0212 
0213 namespace resolve_dynamic
0214 {
0215 
0216 template
0217 <
0218     typename Geometry1, typename Geometry2,
0219     typename Tag1 = geometry::tag_t<Geometry1>,
0220     typename Tag2 = geometry::tag_t<Geometry2>
0221 >
0222 struct intersection
0223 {
0224     template <typename GeometryOut, typename Strategy>
0225     static inline bool apply(Geometry1 const& geometry1, Geometry2 const& geometry2,
0226                              GeometryOut& geometry_out, Strategy const& strategy)
0227     {
0228         concepts::check<Geometry1 const>();
0229         concepts::check<Geometry2 const>();
0230 
0231         return resolve_strategy::intersection
0232             <
0233                 Strategy
0234             >::apply(geometry1, geometry2, geometry_out, strategy);
0235     }
0236 };
0237 
0238 
0239 template <typename DynamicGeometry1, typename Geometry2, typename Tag2>
0240 struct intersection<DynamicGeometry1, Geometry2, dynamic_geometry_tag, Tag2>
0241 {
0242     template <typename GeometryOut, typename Strategy>
0243     static inline bool apply(DynamicGeometry1 const& geometry1, Geometry2 const& geometry2,
0244                              GeometryOut& geometry_out, Strategy const& strategy)
0245     {
0246         bool result = false;
0247         traits::visit<DynamicGeometry1>::apply([&](auto const& g1)
0248         {
0249             result = intersection
0250                 <
0251                     util::remove_cref_t<decltype(g1)>,
0252                     Geometry2
0253                 >::apply(g1, geometry2, geometry_out, strategy);
0254         }, geometry1);
0255         return result;
0256     }
0257 };
0258 
0259 
0260 template <typename Geometry1, typename DynamicGeometry2, typename Tag1>
0261 struct intersection<Geometry1, DynamicGeometry2, Tag1, dynamic_geometry_tag>
0262 {
0263     template <typename GeometryOut, typename Strategy>
0264     static inline bool apply(Geometry1 const& geometry1, DynamicGeometry2 const& geometry2,
0265                              GeometryOut& geometry_out, Strategy const& strategy)
0266     {
0267         bool result = false;
0268         traits::visit<DynamicGeometry2>::apply([&](auto const& g2)
0269         {
0270             result = intersection
0271                 <
0272                     Geometry1,
0273                     util::remove_cref_t<decltype(g2)>
0274                 >::apply(geometry1, g2, geometry_out, strategy);
0275         }, geometry2);
0276         return result;
0277     }
0278 };
0279 
0280 
0281 template <typename DynamicGeometry1, typename DynamicGeometry2>
0282 struct intersection<DynamicGeometry1, DynamicGeometry2, dynamic_geometry_tag, dynamic_geometry_tag>
0283 {
0284     template <typename GeometryOut, typename Strategy>
0285     static inline bool apply(DynamicGeometry1 const& geometry1, DynamicGeometry2 const& geometry2,
0286                              GeometryOut& geometry_out, Strategy const& strategy)
0287     {
0288         bool result = false;
0289         traits::visit<DynamicGeometry1, DynamicGeometry2>::apply([&](auto const& g1, auto const& g2)
0290         {
0291             result = intersection
0292                 <
0293                     util::remove_cref_t<decltype(g1)>,
0294                     util::remove_cref_t<decltype(g2)>
0295                 >::apply(g1, g2, geometry_out, strategy);
0296         }, geometry1, geometry2);
0297         return result;
0298     }
0299 };
0300 
0301 } // namespace resolve_dynamic
0302 
0303 
0304 /*!
0305 \brief \brief_calc2{intersection}
0306 \ingroup intersection
0307 \details \details_calc2{intersection, spatial set theoretic intersection}.
0308 \tparam Geometry1 \tparam_geometry
0309 \tparam Geometry2 \tparam_geometry
0310 \tparam GeometryOut Collection of geometries (e.g. std::vector, std::deque, boost::geometry::multi*) of which
0311     the value_type fulfills a \p_l_or_c concept, or it is the output geometry (e.g. for a box)
0312 \tparam Strategy \tparam_strategy{Intersection}
0313 \param geometry1 \param_geometry
0314 \param geometry2 \param_geometry
0315 \param geometry_out The output geometry, either a multi_point, multi_polygon,
0316     multi_linestring, or a box (for intersection of two boxes)
0317 \param strategy \param_strategy{intersection}
0318 
0319 \qbk{distinguish,with strategy}
0320 \qbk{[include reference/algorithms/intersection.qbk]}
0321 */
0322 template
0323 <
0324     typename Geometry1,
0325     typename Geometry2,
0326     typename GeometryOut,
0327     typename Strategy
0328 >
0329 inline bool intersection(Geometry1 const& geometry1,
0330                          Geometry2 const& geometry2,
0331                          GeometryOut& geometry_out,
0332                          Strategy const& strategy)
0333 {
0334     return resolve_dynamic::intersection
0335         <
0336             Geometry1,
0337             Geometry2
0338         >::apply(geometry1, geometry2, geometry_out, strategy);
0339 }
0340 
0341 
0342 /*!
0343 \brief \brief_calc2{intersection}
0344 \ingroup intersection
0345 \details \details_calc2{intersection, spatial set theoretic intersection}.
0346 \tparam Geometry1 \tparam_geometry
0347 \tparam Geometry2 \tparam_geometry
0348 \tparam GeometryOut Collection of geometries (e.g. std::vector, std::deque, boost::geometry::multi*) of which
0349     the value_type fulfills a \p_l_or_c concept, or it is the output geometry (e.g. for a box)
0350 \param geometry1 \param_geometry
0351 \param geometry2 \param_geometry
0352 \param geometry_out The output geometry, either a multi_point, multi_polygon,
0353     multi_linestring, or a box (for intersection of two boxes)
0354 
0355 \qbk{[include reference/algorithms/intersection.qbk]}
0356 */
0357 template
0358 <
0359     typename Geometry1,
0360     typename Geometry2,
0361     typename GeometryOut
0362 >
0363 inline bool intersection(Geometry1 const& geometry1,
0364                          Geometry2 const& geometry2,
0365                          GeometryOut& geometry_out)
0366 {
0367     return resolve_dynamic::intersection
0368         <
0369             Geometry1,
0370             Geometry2
0371         >::apply(geometry1, geometry2, geometry_out, default_strategy());
0372 }
0373 
0374 
0375 }} // namespace boost::geometry
0376 
0377 
0378 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_INTERSECTION_INTERFACE_HPP