File indexing completed on 2025-01-18 09:35:02
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_CENTROID_TRANSLATING_TRANSFORMER_HPP
0018 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_CENTROID_TRANSLATING_TRANSFORMER_HPP
0019
0020
0021 #include <cstddef>
0022
0023 #include <boost/core/addressof.hpp>
0024 #include <boost/core/ref.hpp>
0025
0026 #include <boost/geometry/core/cs.hpp>
0027 #include <boost/geometry/core/tag_cast.hpp>
0028 #include <boost/geometry/core/tags.hpp>
0029 #include <boost/geometry/core/point_type.hpp>
0030
0031 #include <boost/geometry/arithmetic/arithmetic.hpp>
0032
0033 #include <boost/geometry/iterators/point_iterator.hpp>
0034
0035
0036 namespace boost { namespace geometry
0037 {
0038
0039 #ifndef DOXYGEN_NO_DETAIL
0040 namespace detail { namespace centroid
0041 {
0042
0043
0044
0045
0046
0047
0048 template <typename Geometry,
0049 typename CastedTag = typename tag_cast
0050 <
0051 typename tag<Geometry>::type,
0052 areal_tag
0053 >::type,
0054 typename CSTag = typename cs_tag<Geometry>::type>
0055 struct translating_transformer
0056 {
0057 typedef typename geometry::point_type<Geometry>::type point_type;
0058 typedef boost::reference_wrapper<point_type const> result_type;
0059
0060 explicit translating_transformer(Geometry const&) {}
0061 explicit translating_transformer(point_type const&) {}
0062
0063 result_type apply(point_type const& pt) const
0064 {
0065 return result_type(pt);
0066 }
0067
0068 template <typename ResPt>
0069 void apply_reverse(ResPt &) const {}
0070 };
0071
0072
0073 template <typename Geometry>
0074 struct translating_transformer<Geometry, areal_tag, cartesian_tag>
0075 {
0076 typedef typename geometry::point_type<Geometry>::type point_type;
0077 typedef point_type result_type;
0078
0079 explicit translating_transformer(Geometry const& geom)
0080 : m_origin(NULL)
0081 {
0082 geometry::point_iterator<Geometry const>
0083 pt_it = geometry::points_begin(geom);
0084 if ( pt_it != geometry::points_end(geom) )
0085 {
0086 m_origin = boost::addressof(*pt_it);
0087 }
0088 }
0089
0090 explicit translating_transformer(point_type const& origin)
0091 : m_origin(boost::addressof(origin))
0092 {}
0093
0094 result_type apply(point_type const& pt) const
0095 {
0096 point_type res = pt;
0097 if ( m_origin )
0098 geometry::subtract_point(res, *m_origin);
0099 return res;
0100 }
0101
0102 template <typename ResPt>
0103 void apply_reverse(ResPt & res_pt) const
0104 {
0105 if ( m_origin )
0106 geometry::add_point(res_pt, *m_origin);
0107 }
0108
0109 const point_type * m_origin;
0110 };
0111
0112
0113 }}
0114 #endif
0115
0116 }}
0117
0118
0119 #endif