123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366 |
- #ifndef BOOST_GEOMETRY_ALGORITHMS_ASSIGN_HPP
- #define BOOST_GEOMETRY_ALGORITHMS_ASSIGN_HPP
- #include <boost/variant/static_visitor.hpp>
- #include <boost/variant/variant_fwd.hpp>
- #include <boost/geometry/algorithms/append.hpp>
- #include <boost/geometry/algorithms/clear.hpp>
- #include <boost/geometry/algorithms/convert.hpp>
- #include <boost/geometry/algorithms/detail/assign_box_corners.hpp>
- #include <boost/geometry/algorithms/detail/assign_indexed_point.hpp>
- #include <boost/geometry/algorithms/detail/assign_values.hpp>
- #include <boost/geometry/core/static_assert.hpp>
- #include <boost/geometry/geometries/concepts/check.hpp>
- namespace boost { namespace geometry
- {
- template <typename Geometry, typename Range>
- inline void assign_points(Geometry& geometry, Range const& range)
- {
- concepts::check<Geometry>();
- clear(geometry);
- geometry::append(geometry, range, -1, 0);
- }
- template <typename Geometry>
- inline void assign_inverse(Geometry& geometry)
- {
- concepts::check<Geometry>();
- dispatch::assign_inverse
- <
- typename tag<Geometry>::type,
- Geometry
- >::apply(geometry);
- }
- template <typename Geometry>
- inline void assign_zero(Geometry& geometry)
- {
- concepts::check<Geometry>();
- dispatch::assign_zero
- <
- typename tag<Geometry>::type,
- Geometry
- >::apply(geometry);
- }
- template <typename Geometry, typename Type>
- inline void assign_values(Geometry& geometry, Type const& c1, Type const& c2)
- {
- concepts::check<Geometry>();
- dispatch::assign
- <
- typename tag<Geometry>::type,
- Geometry,
- geometry::dimension<Geometry>::type::value
- >::apply(geometry, c1, c2);
- }
- template <typename Geometry, typename Type>
- inline void assign_values(Geometry& geometry,
- Type const& c1, Type const& c2, Type const& c3)
- {
- concepts::check<Geometry>();
- dispatch::assign
- <
- typename tag<Geometry>::type,
- Geometry,
- geometry::dimension<Geometry>::type::value
- >::apply(geometry, c1, c2, c3);
- }
- template <typename Geometry, typename Type>
- inline void assign_values(Geometry& geometry,
- Type const& c1, Type const& c2, Type const& c3, Type const& c4)
- {
- concepts::check<Geometry>();
- dispatch::assign
- <
- typename tag<Geometry>::type,
- Geometry,
- geometry::dimension<Geometry>::type::value
- >::apply(geometry, c1, c2, c3, c4);
- }
- namespace resolve_variant
- {
- template <typename Geometry1, typename Geometry2>
- struct assign
- {
- static inline void
- apply(Geometry1& geometry1, Geometry2 const& geometry2)
- {
- concepts::check<Geometry1>();
- concepts::check<Geometry2 const>();
- concepts::check_concepts_and_equal_dimensions<Geometry1, Geometry2 const>();
- static bool const same_point_order
- = point_order<Geometry1>::value == point_order<Geometry2>::value;
- BOOST_GEOMETRY_STATIC_ASSERT(
- same_point_order,
- "Assign is not supported for different point orders.",
- Geometry1, Geometry2);
- static bool const same_closure
- = closure<Geometry1>::value == closure<Geometry2>::value;
- BOOST_GEOMETRY_STATIC_ASSERT(
- same_closure,
- "Assign is not supported for different closures.",
- Geometry1, Geometry2);
- dispatch::convert<Geometry2, Geometry1>::apply(geometry2, geometry1);
- }
- };
- template <BOOST_VARIANT_ENUM_PARAMS(typename T), typename Geometry2>
- struct assign<variant<BOOST_VARIANT_ENUM_PARAMS(T)>, Geometry2>
- {
- struct visitor: static_visitor<void>
- {
- Geometry2 const& m_geometry2;
- visitor(Geometry2 const& geometry2)
- : m_geometry2(geometry2)
- {}
- template <typename Geometry1>
- result_type operator()(Geometry1& geometry1) const
- {
- return assign
- <
- Geometry1,
- Geometry2
- >::apply
- (geometry1, m_geometry2);
- }
- };
- static inline void
- apply(variant<BOOST_VARIANT_ENUM_PARAMS(T)>& geometry1,
- Geometry2 const& geometry2)
- {
- return boost::apply_visitor(visitor(geometry2), geometry1);
- }
- };
- template <typename Geometry1, BOOST_VARIANT_ENUM_PARAMS(typename T)>
- struct assign<Geometry1, variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
- {
- struct visitor: static_visitor<void>
- {
- Geometry1& m_geometry1;
- visitor(Geometry1 const& geometry1)
- : m_geometry1(geometry1)
- {}
- template <typename Geometry2>
- result_type operator()(Geometry2 const& geometry2) const
- {
- return assign
- <
- Geometry1,
- Geometry2
- >::apply
- (m_geometry1, geometry2);
- }
- };
- static inline void
- apply(Geometry1& geometry1,
- variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry2)
- {
- return boost::apply_visitor(visitor(geometry1), geometry2);
- }
- };
- template <BOOST_VARIANT_ENUM_PARAMS(typename T1), BOOST_VARIANT_ENUM_PARAMS(typename T2)>
- struct assign<variant<BOOST_VARIANT_ENUM_PARAMS(T1)>, variant<BOOST_VARIANT_ENUM_PARAMS(T2)> >
- {
- struct visitor: static_visitor<void>
- {
- template <typename Geometry1, typename Geometry2>
- result_type operator()(
- Geometry1& geometry1,
- Geometry2 const& geometry2) const
- {
- return assign
- <
- Geometry1,
- Geometry2
- >::apply
- (geometry1, geometry2);
- }
- };
- static inline void
- apply(variant<BOOST_VARIANT_ENUM_PARAMS(T1)>& geometry1,
- variant<BOOST_VARIANT_ENUM_PARAMS(T2)> const& geometry2)
- {
- return boost::apply_visitor(visitor(), geometry1, geometry2);
- }
- };
- }
- template <typename Geometry1, typename Geometry2>
- inline void assign(Geometry1& geometry1, Geometry2 const& geometry2)
- {
- resolve_variant::assign<Geometry1, Geometry2>::apply(geometry1, geometry2);
- }
- }}
- #endif
|