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