123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_CENTROID_TRANSLATING_TRANSFORMER_HPP
- #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_CENTROID_TRANSLATING_TRANSFORMER_HPP
- #include <cstddef>
- #include <boost/core/addressof.hpp>
- #include <boost/core/ref.hpp>
- #include <boost/geometry/core/cs.hpp>
- #include <boost/geometry/core/tag_cast.hpp>
- #include <boost/geometry/core/tags.hpp>
- #include <boost/geometry/core/point_type.hpp>
- #include <boost/geometry/arithmetic/arithmetic.hpp>
- #include <boost/geometry/iterators/point_iterator.hpp>
- namespace boost { namespace geometry
- {
- #ifndef DOXYGEN_NO_DETAIL
- namespace detail { namespace centroid
- {
- template <typename Geometry,
- typename CastedTag = typename tag_cast
- <
- typename tag<Geometry>::type,
- areal_tag
- >::type,
- typename CSTag = typename cs_tag<Geometry>::type>
- struct translating_transformer
- {
- typedef typename geometry::point_type<Geometry>::type point_type;
- typedef boost::reference_wrapper<point_type const> result_type;
- explicit translating_transformer(Geometry const&) {}
- explicit translating_transformer(point_type const&) {}
- result_type apply(point_type const& pt) const
- {
- return result_type(pt);
- }
- template <typename ResPt>
- void apply_reverse(ResPt &) const {}
- };
- template <typename Geometry>
- struct translating_transformer<Geometry, areal_tag, cartesian_tag>
- {
- typedef typename geometry::point_type<Geometry>::type point_type;
- typedef point_type result_type;
- explicit translating_transformer(Geometry const& geom)
- : m_origin(NULL)
- {
- geometry::point_iterator<Geometry const>
- pt_it = geometry::points_begin(geom);
- if ( pt_it != geometry::points_end(geom) )
- {
- m_origin = boost::addressof(*pt_it);
- }
- }
- explicit translating_transformer(point_type const& origin)
- : m_origin(boost::addressof(origin))
- {}
- result_type apply(point_type const& pt) const
- {
- point_type res = pt;
- if ( m_origin )
- geometry::subtract_point(res, *m_origin);
- return res;
- }
- template <typename ResPt>
- void apply_reverse(ResPt & res_pt) const
- {
- if ( m_origin )
- geometry::add_point(res_pt, *m_origin);
- }
- const point_type * m_origin;
- };
- }}
- #endif
- }}
- #endif
|