Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:36:45

0001 // Boost.Geometry
0002 
0003 // Copyright (c) 2018-2022 Barend Gehrels, Amsterdam, the Netherlands.
0004 
0005 // This file was modified by Oracle on 2020-2021.
0006 // Modifications copyright (c) 2020-2021 Oracle and/or its affiliates.
0007 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
0008 
0009 // Use, modification and distribution is subject to the Boost Software License,
0010 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0011 // http://www.boost.org/LICENSE_1_0.txt)
0012 
0013 #ifndef BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_BUFFER_POINT_CIRCLE_HPP
0014 #define BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_BUFFER_POINT_CIRCLE_HPP
0015 
0016 #include <cstddef>
0017 
0018 #include <boost/range/value_type.hpp>
0019 
0020 #include <boost/geometry/core/radian_access.hpp>
0021 
0022 #include <boost/geometry/srs/spheroid.hpp>
0023 #include <boost/geometry/strategies/buffer.hpp>
0024 #include <boost/geometry/strategies/geographic/buffer_helper.hpp>
0025 #include <boost/geometry/strategies/geographic/parameters.hpp>
0026 #include <boost/geometry/util/math.hpp>
0027 #include <boost/geometry/util/select_calculation_type.hpp>
0028 
0029 
0030 namespace boost { namespace geometry
0031 {
0032 
0033 namespace strategy { namespace buffer
0034 {
0035 
0036 /*!
0037 \brief Create a circular buffer around a point, on the Earth
0038 \ingroup strategies
0039 \details This strategy can be used as PointStrategy for the buffer algorithm.
0040     It creates a circular buffer around a point, on the Earth. It can be applied
0041     for points and multi_points.
0042 
0043 \qbk{
0044 [heading Example]
0045 [buffer_geographic_point_circle]
0046 [buffer_geographic_point_circle_output]
0047 [heading See also]
0048 \* [link geometry.reference.algorithms.buffer.buffer_7_with_strategies buffer (with strategies)]
0049 \* [link geometry.reference.strategies.strategy_buffer_point_circle point_circle]
0050 \* [link geometry.reference.strategies.strategy_buffer_point_square point_square]
0051 }
0052  */
0053 template
0054 <
0055     typename FormulaPolicy = strategy::andoyer,
0056     typename Spheroid = srs::spheroid<double>,
0057     typename CalculationType = void
0058 >
0059 class geographic_point_circle
0060 {
0061 public :
0062 
0063     //! \brief Constructs the strategy with a spheroid
0064     //! \param spheroid The spheroid to be used
0065     //! \param count Number of points (minimum 3) for the created circle
0066     explicit inline geographic_point_circle(Spheroid const& spheroid,
0067                                             std::size_t count = default_points_per_circle)
0068         : m_spheroid(spheroid)
0069         , m_count(get_point_count_for_circle(count))
0070     {}
0071 
0072     //! \brief Constructs the strategy
0073     //! \param count Number of points (minimum 3) for the created circle
0074     explicit inline geographic_point_circle(std::size_t count = default_points_per_circle)
0075         : m_count(get_point_count_for_circle(count))
0076     {}
0077 
0078 #ifndef DOXYGEN_SHOULD_SKIP_THIS
0079     //! Fills range_out with a circle around point using distance_strategy
0080     template
0081     <
0082         typename Point,
0083         typename DistanceStrategy,
0084         typename RangeOut
0085     >
0086     inline void apply(Point const& point,
0087                       DistanceStrategy const& distance_strategy,
0088                       RangeOut& range_out) const
0089     {
0090         using calc_t = typename select_calculation_type
0091             <
0092                 Point,
0093                 typename boost::range_value<RangeOut>::type,
0094                 CalculationType
0095             >::type;
0096 
0097         using helper = geographic_buffer_helper<FormulaPolicy, calc_t>;
0098 
0099         calc_t const lon_rad = get_as_radian<0>(point);
0100         calc_t const lat_rad = get_as_radian<1>(point);
0101 
0102         calc_t const buffer_distance = distance_strategy.apply(point,
0103             point, strategy::buffer::buffer_side_left);
0104 
0105         calc_t const two_pi = geometry::math::two_pi<calc_t>();
0106         calc_t const pi = geometry::math::pi<calc_t>();
0107 
0108         calc_t const diff = two_pi / calc_t(m_count);
0109         calc_t angle = -pi;
0110 
0111         for (std::size_t i = 0; i < m_count; i++, angle += diff)
0112         {
0113             // If angle is zero, shift angle a tiny bit to avoid spikes.
0114             calc_t const eps = angle == 0 ? 1.0e-10 : 0.0;
0115             helper::append_point(lon_rad, lat_rad, buffer_distance, angle + eps, m_spheroid, range_out);
0116         }
0117 
0118         {
0119             // Close the range
0120             auto const p = range_out.front();
0121             range_out.push_back(p);
0122         }
0123     }
0124 #endif // DOXYGEN_SHOULD_SKIP_THIS
0125 
0126 private :
0127     Spheroid m_spheroid;
0128     std::size_t m_count;
0129 };
0130 
0131 }} // namespace strategy::buffer
0132 
0133 }} // namespace boost::geometry
0134 
0135 #endif // BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_BUFFER_POINT_CIRCLE_HPP