Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-11-02 09:16:01

0001 // Boost.Geometry (aka GGL, Generic Geometry Library)
0002 
0003 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
0004 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
0005 // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
0006 // Copyright (c) 2014 Adam Wulkiewicz, Lodz, Poland.
0007 
0008 // This file was modified by Oracle on 2014.
0009 // Modifications copyright (c) 2014 Oracle and/or its affiliates.
0010 
0011 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
0012 
0013 // Use, modification and distribution is subject to the Boost Software License,
0014 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0015 // http://www.boost.org/LICENSE_1_0.txt)
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 // NOTE: There is no need to translate in other coordinate systems than
0045 // cartesian. But if it was needed then one should translate using
0046 // CS-specific technique, e.g. in spherical/geographic a translation
0047 // vector should contain coordinates being multiplies of 2PI or 360 deg.
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 // Specialization for Areal Geometries in cartesian CS
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 }} // namespace detail::centroid
0113 #endif // DOXYGEN_NO_DETAIL
0114 
0115 }} // namespace boost::geometry
0116 
0117 
0118 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_CENTROID_TRANSLATING_TRANSFORMER_HPP