Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // Boost.Geometry (aka GGL, Generic Geometry Library)
0002 
0003 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
0004 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
0005 // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
0006 
0007 // This file was modified by Oracle on 2013-2022.
0008 // Modifications copyright (c) 2013-2022 Oracle and/or its affiliates.
0009 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
0010 
0011 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
0012 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
0013 
0014 // Use, modification and distribution is subject to the Boost Software License,
0015 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0016 // http://www.boost.org/LICENSE_1_0.txt)
0017 
0018 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_WITHIN_INTERFACE_HPP
0019 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_WITHIN_INTERFACE_HPP
0020 
0021 
0022 #include <boost/concept_check.hpp>
0023 
0024 #include <boost/geometry/algorithms/not_implemented.hpp>
0025 
0026 #include <boost/geometry/core/tag.hpp>
0027 #include <boost/geometry/core/tag_cast.hpp>
0028 
0029 #include <boost/geometry/geometries/adapted/boost_variant.hpp>
0030 #include <boost/geometry/geometries/concepts/check.hpp>
0031 
0032 #include <boost/geometry/strategies/concepts/within_concept.hpp>
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 #ifndef DOXYGEN_NO_DISPATCH
0042 namespace dispatch
0043 {
0044 
0045 template
0046 <
0047     typename Geometry1,
0048     typename Geometry2,
0049     typename Tag1 = tag_t<Geometry1>,
0050     typename Tag2 = tag_t<Geometry2>
0051 >
0052 struct within
0053     : not_implemented<Tag1, Tag2>
0054 {};
0055 
0056 
0057 } // namespace dispatch
0058 #endif // DOXYGEN_NO_DISPATCH
0059 
0060 
0061 namespace resolve_strategy
0062 {
0063 
0064 template
0065 <
0066     typename Strategy,
0067     bool IsUmbrella = strategies::detail::is_umbrella_strategy<Strategy>::value
0068 >
0069 struct within
0070 {
0071     template <typename Geometry1, typename Geometry2>
0072     static inline bool apply(Geometry1 const& geometry1,
0073                              Geometry2 const& geometry2,
0074                              Strategy const& strategy)
0075     {
0076         concepts::within::check<Geometry1, Geometry2, Strategy>();
0077 
0078         return dispatch::within
0079             <
0080                 Geometry1, Geometry2
0081             >::apply(geometry1, geometry2, strategy);
0082     }
0083 };
0084 
0085 template <typename Strategy>
0086 struct within<Strategy, false>
0087 {
0088     template <typename Geometry1, typename Geometry2>
0089     static inline bool apply(Geometry1 const& geometry1,
0090                              Geometry2 const& geometry2,
0091                              Strategy const& strategy)
0092     {
0093         using strategies::relate::services::strategy_converter;
0094 
0095         return within
0096             <
0097                 decltype(strategy_converter<Strategy>::get(strategy))
0098             >::apply(geometry1, geometry2,
0099                      strategy_converter<Strategy>::get(strategy));
0100     }
0101 };
0102 
0103 template <>
0104 struct within<default_strategy, false>
0105 {
0106     template <typename Geometry1, typename Geometry2>
0107     static inline bool apply(Geometry1 const& geometry1,
0108                              Geometry2 const& geometry2,
0109                              default_strategy)
0110     {
0111         typedef typename strategies::relate::services::default_strategy
0112             <
0113                 Geometry1,
0114                 Geometry2
0115             >::type strategy_type;
0116 
0117         return within
0118             <
0119                 strategy_type
0120             >::apply(geometry1, geometry2, strategy_type());
0121     }
0122 };
0123 
0124 } // namespace resolve_strategy
0125 
0126 
0127 namespace resolve_dynamic
0128 {
0129 
0130 template
0131 <
0132     typename Geometry1, typename Geometry2,
0133     typename Tag1 = geometry::tag_t<Geometry1>,
0134     typename Tag2 = geometry::tag_t<Geometry2>
0135 >
0136 struct within
0137 {
0138     template <typename Strategy>
0139     static inline bool apply(Geometry1 const& geometry1,
0140                              Geometry2 const& geometry2,
0141                              Strategy const& strategy)
0142     {
0143         concepts::check<Geometry1 const>();
0144         concepts::check<Geometry2 const>();
0145         assert_dimension_equal<Geometry1, Geometry2>();
0146 
0147         return resolve_strategy::within
0148             <
0149                 Strategy
0150             >::apply(geometry1, geometry2, strategy);
0151     }
0152 };
0153 
0154 template <typename Geometry1, typename Geometry2, typename Tag2>
0155 struct within<Geometry1, Geometry2, dynamic_geometry_tag, Tag2>
0156 {
0157     template <typename Strategy>
0158     static inline bool apply(Geometry1 const& geometry1,
0159                              Geometry2 const& geometry2,
0160                              Strategy const& strategy)
0161     {
0162         bool result = false;
0163         traits::visit<Geometry1>::apply([&](auto const& g1)
0164         {
0165             result = within
0166                 <
0167                     util::remove_cref_t<decltype(g1)>,
0168                     Geometry2
0169                 >::apply(g1, geometry2, strategy);
0170         }, geometry1);
0171         return result;
0172     }
0173 };
0174 
0175 template <typename Geometry1, typename Geometry2, typename Tag1>
0176 struct within<Geometry1, Geometry2, Tag1, dynamic_geometry_tag>
0177 {
0178     template <typename Strategy>
0179     static inline bool apply(Geometry1 const& geometry1,
0180                              Geometry2 const& geometry2,
0181                              Strategy const& strategy)
0182     {
0183         bool result = false;
0184         traits::visit<Geometry2>::apply([&](auto const& g2)
0185         {
0186             result = within
0187                 <
0188                     Geometry1,
0189                     util::remove_cref_t<decltype(g2)>
0190                 >::apply(geometry1, g2, strategy);
0191         }, geometry2);
0192         return result;
0193     }
0194 };
0195 
0196 template <typename Geometry1, typename Geometry2>
0197 struct within<Geometry1, Geometry2, dynamic_geometry_tag, dynamic_geometry_tag>
0198 {
0199     template <typename Strategy>
0200     static inline bool apply(Geometry1 const& geometry1,
0201                              Geometry2 const& geometry2,
0202                              Strategy const& strategy)
0203     {
0204         bool result = false;
0205         traits::visit<Geometry1, Geometry2>::apply([&](auto const& g1, auto const& g2)
0206         {
0207             result = within
0208                 <
0209                     util::remove_cref_t<decltype(g1)>,
0210                     util::remove_cref_t<decltype(g2)>
0211                 >::apply(g1, g2, strategy);
0212         }, geometry1, geometry2);
0213         return result;
0214     }
0215 };
0216 
0217 }
0218 
0219 
0220 /*!
0221 \brief \brief_check12{is completely inside}
0222 \ingroup within
0223 \details \details_check12{within, is completely inside}.
0224 \tparam Geometry1 \tparam_geometry
0225 \tparam Geometry2 \tparam_geometry
0226 \param geometry1 \param_geometry which might be within the second geometry
0227 \param geometry2 \param_geometry which might contain the first geometry
0228 \return true if geometry1 is completely contained within geometry2,
0229     else false
0230 \note The default strategy is used for within detection
0231 
0232 
0233 \qbk{[include reference/algorithms/within.qbk]}
0234 
0235 \qbk{
0236 [heading Example]
0237 [within]
0238 [within_output]
0239 }
0240  */
0241 template<typename Geometry1, typename Geometry2>
0242 inline bool within(Geometry1 const& geometry1, Geometry2 const& geometry2)
0243 {
0244     return resolve_dynamic::within
0245         <
0246             Geometry1,
0247             Geometry2
0248         >::apply(geometry1, geometry2, default_strategy());
0249 }
0250 
0251 /*!
0252 \brief \brief_check12{is completely inside} \brief_strategy
0253 \ingroup within
0254 \details \details_check12{within, is completely inside}, \brief_strategy. \details_strategy_reasons
0255 \tparam Geometry1 \tparam_geometry
0256 \tparam Geometry2 \tparam_geometry
0257 \param geometry1 \param_geometry which might be within the second geometry
0258 \param geometry2 \param_geometry which might contain the first geometry
0259 \param strategy strategy to be used
0260 \return true if geometry1 is completely contained within geometry2,
0261     else false
0262 
0263 \qbk{distinguish,with strategy}
0264 \qbk{[include reference/algorithms/within.qbk]}
0265 \qbk{
0266 [heading Available Strategies]
0267 \* [link geometry.reference.strategies.strategy_within_winding Winding (coordinate system agnostic)]
0268 \* [link geometry.reference.strategies.strategy_within_franklin Franklin (cartesian)]
0269 \* [link geometry.reference.strategies.strategy_within_crossings_multiply Crossings Multiply (cartesian)]
0270 
0271 [heading Example]
0272 [within_strategy]
0273 [within_strategy_output]
0274 
0275 }
0276 */
0277 template<typename Geometry1, typename Geometry2, typename Strategy>
0278 inline bool within(Geometry1 const& geometry1,
0279                    Geometry2 const& geometry2,
0280                    Strategy const& strategy)
0281 {
0282     return resolve_dynamic::within
0283         <
0284             Geometry1,
0285             Geometry2
0286         >::apply(geometry1, geometry2, strategy);
0287 }
0288 
0289 }} // namespace boost::geometry
0290 
0291 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_WITHIN_INTERFACE_HPP