Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:35:02

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 <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 // Specialization for Areal Geometries in cartesian CS
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 }} // namespace detail::centroid
0114 #endif // DOXYGEN_NO_DETAIL
0115 
0116 }} // namespace boost::geometry
0117 
0118 
0119 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_CENTROID_TRANSLATING_TRANSFORMER_HPP