]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/geometry/algorithms/detail/centroid/translating_transformer.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / geometry / algorithms / detail / centroid / translating_transformer.hpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2
3 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
4 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
5 // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
6 // Copyright (c) 2014 Adam Wulkiewicz, Lodz, Poland.
7
8 // This file was modified by Oracle on 2014.
9 // Modifications copyright (c) 2014 Oracle and/or its affiliates.
10
11 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
12
13 // Use, modification and distribution is subject to the Boost Software License,
14 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
15 // http://www.boost.org/LICENSE_1_0.txt)
16
17 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_CENTROID_TRANSLATING_TRANSFORMER_HPP
18 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_CENTROID_TRANSLATING_TRANSFORMER_HPP
19
20
21 #include <cstddef>
22
23 #include <boost/core/addressof.hpp>
24 #include <boost/core/ref.hpp>
25
26 #include <boost/geometry/core/cs.hpp>
27 #include <boost/geometry/core/tag_cast.hpp>
28 #include <boost/geometry/core/tags.hpp>
29 #include <boost/geometry/core/point_type.hpp>
30
31 #include <boost/geometry/arithmetic/arithmetic.hpp>
32
33 #include <boost/geometry/iterators/point_iterator.hpp>
34
35
36 namespace boost { namespace geometry
37 {
38
39 #ifndef DOXYGEN_NO_DETAIL
40 namespace detail { namespace centroid
41 {
42
43
44 // NOTE: There is no need to translate in other coordinate systems than
45 // cartesian. But if it was needed then one should translate using
46 // CS-specific technique, e.g. in spherical/geographic a translation
47 // vector should contain coordinates being multiplies of 2PI or 360 deg.
48 template <typename Geometry,
49 typename CastedTag = typename tag_cast
50 <
51 typename tag<Geometry>::type,
52 areal_tag
53 >::type,
54 typename CSTag = typename cs_tag<Geometry>::type>
55 struct translating_transformer
56 {
57 typedef typename geometry::point_type<Geometry>::type point_type;
58 typedef boost::reference_wrapper<point_type const> result_type;
59
60 explicit translating_transformer(Geometry const&) {}
61 explicit translating_transformer(point_type const&) {}
62
63 result_type apply(point_type const& pt) const
64 {
65 return result_type(pt);
66 }
67
68 template <typename ResPt>
69 void apply_reverse(ResPt &) const {}
70 };
71
72 // Specialization for Areal Geometries in cartesian CS
73 template <typename Geometry>
74 struct translating_transformer<Geometry, areal_tag, cartesian_tag>
75 {
76 typedef typename geometry::point_type<Geometry>::type point_type;
77 typedef point_type result_type;
78
79 explicit translating_transformer(Geometry const& geom)
80 : m_origin(NULL)
81 {
82 geometry::point_iterator<Geometry const>
83 pt_it = geometry::points_begin(geom);
84 if ( pt_it != geometry::points_end(geom) )
85 {
86 m_origin = boost::addressof(*pt_it);
87 }
88 }
89
90 explicit translating_transformer(point_type const& origin)
91 : m_origin(boost::addressof(origin))
92 {}
93
94 result_type apply(point_type const& pt) const
95 {
96 point_type res = pt;
97 if ( m_origin )
98 geometry::subtract_point(res, *m_origin);
99 return res;
100 }
101
102 template <typename ResPt>
103 void apply_reverse(ResPt & res_pt) const
104 {
105 if ( m_origin )
106 geometry::add_point(res_pt, *m_origin);
107 }
108
109 const point_type * m_origin;
110 };
111
112
113 }} // namespace detail::centroid
114 #endif // DOXYGEN_NO_DETAIL
115
116 }} // namespace boost::geometry
117
118
119 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_CENTROID_TRANSLATING_TRANSFORMER_HPP