File indexing completed on 2025-11-02 09:16:01
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
0049 <
0050 typename Geometry,
0051 typename CastedTag = tag_cast_t<tag_t<Geometry>, areal_tag>,
0052 typename CSTag = cs_tag_t<Geometry>
0053 >
0054 struct translating_transformer
0055 {
0056 using point_type = geometry::point_type_t<Geometry>;
0057 using result_type = boost::reference_wrapper<point_type const>;
0058
0059 explicit translating_transformer(Geometry const&) {}
0060 explicit translating_transformer(point_type const&) {}
0061
0062 result_type apply(point_type const& pt) const
0063 {
0064 return result_type(pt);
0065 }
0066
0067 template <typename ResPt>
0068 void apply_reverse(ResPt &) const {}
0069 };
0070
0071
0072 template <typename Geometry>
0073 struct translating_transformer<Geometry, areal_tag, cartesian_tag>
0074 {
0075 using point_type = geometry::point_type_t<Geometry>;
0076 using result_type = point_type;
0077
0078 explicit translating_transformer(Geometry const& geom)
0079 : m_origin(NULL)
0080 {
0081 geometry::point_iterator<Geometry const>
0082 pt_it = geometry::points_begin(geom);
0083 if ( pt_it != geometry::points_end(geom) )
0084 {
0085 m_origin = boost::addressof(*pt_it);
0086 }
0087 }
0088
0089 explicit translating_transformer(point_type const& origin)
0090 : m_origin(boost::addressof(origin))
0091 {}
0092
0093 result_type apply(point_type const& pt) const
0094 {
0095 point_type res = pt;
0096 if ( m_origin )
0097 geometry::subtract_point(res, *m_origin);
0098 return res;
0099 }
0100
0101 template <typename ResPt>
0102 void apply_reverse(ResPt & res_pt) const
0103 {
0104 if ( m_origin )
0105 geometry::add_point(res_pt, *m_origin);
0106 }
0107
0108 const point_type * m_origin;
0109 };
0110
0111
0112 }}
0113 #endif
0114
0115 }}
0116
0117
0118 #endif