1 // Boost.Geometry (aka GGL, Generic Geometry Library)
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.
8 // This file was modified by Oracle on 2014.
9 // Modifications copyright (c) 2014 Oracle and/or its affiliates.
11 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
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)
17 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_CENTROID_TRANSLATING_TRANSFORMER_HPP
18 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_CENTROID_TRANSLATING_TRANSFORMER_HPP
23 #include <boost/core/addressof.hpp>
24 #include <boost/core/ref.hpp>
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>
31 #include <boost/geometry/arithmetic/arithmetic.hpp>
33 #include <boost/geometry/iterators/point_iterator.hpp>
36 namespace boost { namespace geometry
39 #ifndef DOXYGEN_NO_DETAIL
40 namespace detail { namespace centroid
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
51 typename tag<Geometry>::type,
54 typename CSTag = typename cs_tag<Geometry>::type>
55 struct translating_transformer
57 typedef typename geometry::point_type<Geometry>::type point_type;
58 typedef boost::reference_wrapper<point_type const> result_type;
60 explicit translating_transformer(Geometry const&) {}
61 explicit translating_transformer(point_type const&) {}
63 result_type apply(point_type const& pt) const
65 return result_type(pt);
68 template <typename ResPt>
69 void apply_reverse(ResPt &) const {}
72 // Specialization for Areal Geometries in cartesian CS
73 template <typename Geometry>
74 struct translating_transformer<Geometry, areal_tag, cartesian_tag>
76 typedef typename geometry::point_type<Geometry>::type point_type;
77 typedef point_type result_type;
79 explicit translating_transformer(Geometry const& geom)
82 geometry::point_iterator<Geometry const>
83 pt_it = geometry::points_begin(geom);
84 if ( pt_it != geometry::points_end(geom) )
86 m_origin = boost::addressof(*pt_it);
90 explicit translating_transformer(point_type const& origin)
91 : m_origin(boost::addressof(origin))
94 result_type apply(point_type const& pt) const
98 geometry::subtract_point(res, *m_origin);
102 template <typename ResPt>
103 void apply_reverse(ResPt & res_pt) const
106 geometry::add_point(res_pt, *m_origin);
109 const point_type * m_origin;
113 }} // namespace detail::centroid
114 #endif // DOXYGEN_NO_DETAIL
116 }} // namespace boost::geometry
119 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_CENTROID_TRANSLATING_TRANSFORMER_HPP