File indexing completed on 2025-12-15 09:50:23
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
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 }
0058 #endif
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 }
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
0222
0223
0224
0225
0226
0227
0228
0229
0230
0231
0232
0233
0234
0235
0236
0237
0238
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
0253
0254
0255
0256
0257
0258
0259
0260
0261
0262
0263
0264
0265
0266
0267
0268
0269
0270
0271
0272
0273
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 }}
0290
0291 #endif