Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-15 09:50:10

0001 // Boost.Geometry (aka GGL, Generic Geometry Library)
0002 
0003 // Copyright (c) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands.
0004 // Copyright (c) 2008-2014 Bruno Lalande, Paris, France.
0005 // Copyright (c) 2009-2014 Mateusz Loskot, London, UK.
0006 // Copyright (c) 2013-2014 Adam Wulkiewicz, Lodz, Poland.
0007 
0008 // This file was modified by Oracle on 2013-2021.
0009 // Modifications copyright (c) 2013-2021, Oracle and/or its affiliates.
0010 
0011 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
0012 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
0013 
0014 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
0015 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
0016 
0017 // Use, modification and distribution is subject to the Boost Software License,
0018 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0019 // http://www.boost.org/LICENSE_1_0.txt)
0020 
0021 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_INTERFACE_HPP
0022 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_INTERFACE_HPP
0023 
0024 #include <cstddef>
0025 
0026 #include <boost/geometry/algorithms/detail/relate/interface.hpp>
0027 #include <boost/geometry/algorithms/detail/visit.hpp>
0028 #include <boost/geometry/algorithms/dispatch/disjoint.hpp>
0029 
0030 #include <boost/geometry/geometries/adapted/boost_variant.hpp> // For backward compatibility
0031 #include <boost/geometry/geometries/concepts/check.hpp>
0032 
0033 #include <boost/geometry/strategies/default_strategy.hpp>
0034 #include <boost/geometry/strategies/detail.hpp>
0035 #include <boost/geometry/strategies/relate/services.hpp>
0036 
0037 
0038 namespace boost { namespace geometry
0039 {
0040 
0041 namespace resolve_strategy
0042 {
0043 
0044 template
0045 <
0046     typename Strategy,
0047     bool IsUmbrella = strategies::detail::is_umbrella_strategy<Strategy>::value
0048 >
0049 struct disjoint
0050 {
0051     template <typename Geometry1, typename Geometry2>
0052     static inline bool apply(Geometry1 const& geometry1,
0053                              Geometry2 const& geometry2,
0054                              Strategy const& strategy)
0055     {
0056         return dispatch::disjoint
0057                 <
0058                     Geometry1, Geometry2
0059                 >::apply(geometry1, geometry2, strategy);
0060     }
0061 };
0062 
0063 template <typename Strategy>
0064 struct disjoint<Strategy, false>
0065 {
0066     template <typename Geometry1, typename Geometry2>
0067     static inline bool apply(Geometry1 const& geometry1,
0068                              Geometry2 const& geometry2,
0069                              Strategy const& strategy)
0070     {
0071         using strategies::relate::services::strategy_converter;
0072 
0073         return dispatch::disjoint
0074                 <
0075                     Geometry1, Geometry2
0076                 >::apply(geometry1, geometry2,
0077                          strategy_converter<Strategy>::get(strategy));
0078     }
0079 };
0080 
0081 template <>
0082 struct disjoint<default_strategy, false>
0083 {
0084     template <typename Geometry1, typename Geometry2>
0085     static inline bool apply(Geometry1 const& geometry1,
0086                              Geometry2 const& geometry2,
0087                              default_strategy)
0088     {
0089         typedef typename strategies::relate::services::default_strategy
0090             <
0091                 Geometry1, Geometry2
0092             >::type strategy_type;
0093 
0094         return dispatch::disjoint
0095                 <
0096                     Geometry1, Geometry2
0097                 >::apply(geometry1, geometry2, strategy_type());
0098     }
0099 };
0100 
0101 } // namespace resolve_strategy
0102 
0103 
0104 namespace resolve_dynamic {
0105 
0106 template
0107 <
0108     typename Geometry1, typename Geometry2,
0109     bool IsDynamic = util::is_dynamic_geometry<Geometry1>::value
0110                   || util::is_dynamic_geometry<Geometry2>::value,
0111     bool IsCollection = util::is_geometry_collection<Geometry1>::value
0112                      || util::is_geometry_collection<Geometry2>::value
0113 >
0114 struct disjoint
0115 {
0116     template <typename Strategy>
0117     static inline bool apply(Geometry1 const& geometry1, Geometry2 const& geometry2,
0118                              Strategy const& strategy)
0119     {
0120         concepts::check_concepts_and_equal_dimensions
0121             <
0122                 Geometry1 const,
0123                 Geometry2 const
0124             >();
0125 
0126         return resolve_strategy::disjoint
0127             <
0128                 Strategy
0129             >::apply(geometry1, geometry2, strategy);
0130     }
0131 };
0132 
0133 template <typename Geometry1, typename Geometry2>
0134 struct disjoint<Geometry1, Geometry2, true, false>
0135 {
0136     template <typename Strategy>
0137     static inline bool apply(Geometry1 const& geometry1, Geometry2 const& geometry2,
0138                              Strategy const& strategy)
0139     {
0140         bool result = true;
0141         detail::visit([&](auto const& g1, auto const& g2)
0142         {
0143             result = disjoint
0144                 <
0145                     util::remove_cref_t<decltype(g1)>, util::remove_cref_t<decltype(g2)>
0146                 >::apply(g1, g2, strategy);
0147         }, geometry1, geometry2);
0148         return result;
0149     }
0150 };
0151 
0152 // TODO: The complexity is quadratic for two GCs
0153 //   Decrease e.g. with spatial index
0154 template <typename Geometry1, typename Geometry2, bool IsDynamic>
0155 struct disjoint<Geometry1, Geometry2, IsDynamic, true>
0156 {
0157     template <typename Strategy>
0158     static inline bool apply(Geometry1 const& geometry1, Geometry2 const& geometry2,
0159                              Strategy const& strategy)
0160     {
0161         bool result = true;
0162         detail::visit_breadth_first([&](auto const& g1)
0163         {
0164             detail::visit_breadth_first([&](auto const& g2)
0165             {
0166                 result = disjoint
0167                     <
0168                         util::remove_cref_t<decltype(g1)>, util::remove_cref_t<decltype(g2)>
0169                     >::apply(g1, g2, strategy);
0170                 // If any of the combination intersects then the final result is not disjoint
0171                 return result;
0172             }, geometry2);
0173             return result;
0174         }, geometry1);
0175         return result;
0176     }
0177 };
0178 
0179 } // namespace resolve_dynamic
0180 
0181 
0182 /*!
0183 \brief \brief_check2{are disjoint}
0184 \ingroup disjoint
0185 \tparam Geometry1 \tparam_geometry
0186 \tparam Geometry2 \tparam_geometry
0187 \tparam Strategy \tparam_strategy{Disjoint}
0188 \param geometry1 \param_geometry
0189 \param geometry2 \param_geometry
0190 \param strategy \param_strategy{disjoint}
0191 \return \return_check2{are disjoint}
0192 
0193 \qbk{distinguish,with strategy}
0194 \qbk{[include reference/algorithms/disjoint.qbk]}
0195 */
0196 template <typename Geometry1, typename Geometry2, typename Strategy>
0197 inline bool disjoint(Geometry1 const& geometry1,
0198                      Geometry2 const& geometry2,
0199                      Strategy const& strategy)
0200 {
0201     return resolve_dynamic::disjoint
0202             <
0203                 Geometry1, Geometry2
0204             >::apply(geometry1, geometry2, strategy);
0205 }
0206 
0207 
0208 /*!
0209 \brief \brief_check2{are disjoint}
0210 \ingroup disjoint
0211 \tparam Geometry1 \tparam_geometry
0212 \tparam Geometry2 \tparam_geometry
0213 \param geometry1 \param_geometry
0214 \param geometry2 \param_geometry
0215 \return \return_check2{are disjoint}
0216 
0217 \qbk{[include reference/algorithms/disjoint.qbk]}
0218 \qbk{
0219 [heading Examples]
0220 [disjoint]
0221 [disjoint_output]
0222 }
0223 */
0224 template <typename Geometry1, typename Geometry2>
0225 inline bool disjoint(Geometry1 const& geometry1,
0226                      Geometry2 const& geometry2)
0227 {
0228     return resolve_dynamic::disjoint
0229             <
0230                 Geometry1, Geometry2
0231             >::apply(geometry1, geometry2, default_strategy());
0232 }
0233 
0234 
0235 }} // namespace boost::geometry
0236 
0237 
0238 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_INTERFACE_HPP