Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:35:06

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