File indexing completed on 2025-09-18 08:43:00
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 #ifndef BOOST_GEOMETRY_ALGORITHMS_ASSIGN_HPP
0022 #define BOOST_GEOMETRY_ALGORITHMS_ASSIGN_HPP
0023
0024 #include <boost/variant/static_visitor.hpp>
0025 #include <boost/variant/variant_fwd.hpp>
0026
0027 #include <boost/geometry/algorithms/append.hpp>
0028 #include <boost/geometry/algorithms/clear.hpp>
0029 #include <boost/geometry/algorithms/convert.hpp>
0030
0031 #include <boost/geometry/algorithms/detail/assign_box_corners.hpp>
0032 #include <boost/geometry/algorithms/detail/assign_indexed_point.hpp>
0033 #include <boost/geometry/algorithms/detail/assign_values.hpp>
0034
0035 #include <boost/geometry/core/static_assert.hpp>
0036
0037 #include <boost/geometry/geometries/concepts/check.hpp>
0038
0039 namespace boost { namespace geometry
0040 {
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061 template <typename Geometry, typename Range>
0062 inline void assign_points(Geometry& geometry, Range const& range)
0063 {
0064 concepts::check<Geometry>();
0065
0066 clear(geometry);
0067 geometry::append(geometry, range, -1, 0);
0068 }
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088 template <typename Geometry>
0089 inline void assign_inverse(Geometry& geometry)
0090 {
0091 concepts::check<Geometry>();
0092
0093 dispatch::assign_inverse
0094 <
0095 tag_t<Geometry>,
0096 Geometry
0097 >::apply(geometry);
0098 }
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108 template <typename Geometry>
0109 inline void assign_zero(Geometry& geometry)
0110 {
0111 concepts::check<Geometry>();
0112
0113 dispatch::assign_zero
0114 <
0115 tag_t<Geometry>,
0116 Geometry
0117 >::apply(geometry);
0118 }
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138 template <typename Geometry, typename Type>
0139 inline void assign_values(Geometry& geometry, Type const& c1, Type const& c2)
0140 {
0141 concepts::check<Geometry>();
0142
0143 dispatch::assign
0144 <
0145 tag_t<Geometry>,
0146 Geometry,
0147 geometry::dimension<Geometry>::value
0148 >::apply(geometry, c1, c2);
0149 }
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170 template <typename Geometry, typename Type>
0171 inline void assign_values(Geometry& geometry,
0172 Type const& c1, Type const& c2, Type const& c3)
0173 {
0174 concepts::check<Geometry>();
0175
0176 dispatch::assign
0177 <
0178 tag_t<Geometry>,
0179 Geometry,
0180 geometry::dimension<Geometry>::value
0181 >::apply(geometry, c1, c2, c3);
0182 }
0183
0184
0185
0186
0187
0188
0189
0190
0191
0192
0193
0194
0195
0196
0197 template <typename Geometry, typename Type>
0198 inline void assign_values(Geometry& geometry,
0199 Type const& c1, Type const& c2, Type const& c3, Type const& c4)
0200 {
0201 concepts::check<Geometry>();
0202
0203 dispatch::assign
0204 <
0205 tag_t<Geometry>,
0206 Geometry,
0207 geometry::dimension<Geometry>::value
0208 >::apply(geometry, c1, c2, c3, c4);
0209 }
0210
0211
0212
0213 namespace resolve_variant
0214 {
0215
0216 template <typename Geometry1, typename Geometry2>
0217 struct assign
0218 {
0219 static inline void
0220 apply(Geometry1& geometry1, Geometry2 const& geometry2)
0221 {
0222 concepts::check<Geometry1>();
0223 concepts::check<Geometry2 const>();
0224 concepts::check_concepts_and_equal_dimensions<Geometry1, Geometry2 const>();
0225
0226 static bool const same_point_order
0227 = point_order<Geometry1>::value == point_order<Geometry2>::value;
0228 BOOST_GEOMETRY_STATIC_ASSERT(
0229 same_point_order,
0230 "Assign is not supported for different point orders.",
0231 Geometry1, Geometry2);
0232 static bool const same_closure
0233 = closure<Geometry1>::value == closure<Geometry2>::value;
0234 BOOST_GEOMETRY_STATIC_ASSERT(
0235 same_closure,
0236 "Assign is not supported for different closures.",
0237 Geometry1, Geometry2);
0238
0239 dispatch::convert<Geometry2, Geometry1>::apply(geometry2, geometry1);
0240 }
0241 };
0242
0243
0244 template <BOOST_VARIANT_ENUM_PARAMS(typename T), typename Geometry2>
0245 struct assign<variant<BOOST_VARIANT_ENUM_PARAMS(T)>, Geometry2>
0246 {
0247 struct visitor: static_visitor<void>
0248 {
0249 Geometry2 const& m_geometry2;
0250
0251 visitor(Geometry2 const& geometry2)
0252 : m_geometry2(geometry2)
0253 {}
0254
0255 template <typename Geometry1>
0256 result_type operator()(Geometry1& geometry1) const
0257 {
0258 return assign
0259 <
0260 Geometry1,
0261 Geometry2
0262 >::apply
0263 (geometry1, m_geometry2);
0264 }
0265 };
0266
0267 static inline void
0268 apply(variant<BOOST_VARIANT_ENUM_PARAMS(T)>& geometry1,
0269 Geometry2 const& geometry2)
0270 {
0271 return boost::apply_visitor(visitor(geometry2), geometry1);
0272 }
0273 };
0274
0275
0276 template <typename Geometry1, BOOST_VARIANT_ENUM_PARAMS(typename T)>
0277 struct assign<Geometry1, variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
0278 {
0279 struct visitor: static_visitor<void>
0280 {
0281 Geometry1& m_geometry1;
0282
0283 visitor(Geometry1 const& geometry1)
0284 : m_geometry1(geometry1)
0285 {}
0286
0287 template <typename Geometry2>
0288 result_type operator()(Geometry2 const& geometry2) const
0289 {
0290 return assign
0291 <
0292 Geometry1,
0293 Geometry2
0294 >::apply
0295 (m_geometry1, geometry2);
0296 }
0297 };
0298
0299 static inline void
0300 apply(Geometry1& geometry1,
0301 variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry2)
0302 {
0303 return boost::apply_visitor(visitor(geometry1), geometry2);
0304 }
0305 };
0306
0307
0308 template <BOOST_VARIANT_ENUM_PARAMS(typename T1), BOOST_VARIANT_ENUM_PARAMS(typename T2)>
0309 struct assign<variant<BOOST_VARIANT_ENUM_PARAMS(T1)>, variant<BOOST_VARIANT_ENUM_PARAMS(T2)> >
0310 {
0311 struct visitor: static_visitor<void>
0312 {
0313 template <typename Geometry1, typename Geometry2>
0314 result_type operator()(
0315 Geometry1& geometry1,
0316 Geometry2 const& geometry2) const
0317 {
0318 return assign
0319 <
0320 Geometry1,
0321 Geometry2
0322 >::apply
0323 (geometry1, geometry2);
0324 }
0325 };
0326
0327 static inline void
0328 apply(variant<BOOST_VARIANT_ENUM_PARAMS(T1)>& geometry1,
0329 variant<BOOST_VARIANT_ENUM_PARAMS(T2)> const& geometry2)
0330 {
0331 return boost::apply_visitor(visitor(), geometry1, geometry2);
0332 }
0333 };
0334
0335 }
0336
0337
0338
0339
0340
0341
0342
0343
0344
0345
0346
0347
0348
0349
0350
0351
0352
0353
0354
0355
0356 template <typename Geometry1, typename Geometry2>
0357 inline void assign(Geometry1& geometry1, Geometry2 const& geometry2)
0358 {
0359 resolve_variant::assign<Geometry1, Geometry2>::apply(geometry1, geometry2);
0360 }
0361
0362
0363 }}
0364
0365
0366
0367 #endif