]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/geometry/strategies/geographic/buffer_point_circle.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / geometry / strategies / geographic / buffer_point_circle.hpp
1 // Boost.Geometry
2
3 // Copyright (c) 2018-2019 Barend Gehrels, Amsterdam, the Netherlands.
4
5 // Use, modification and distribution is subject to the Boost Software License,
6 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
8
9 #ifndef BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_BUFFER_POINT_CIRCLE_HPP
10 #define BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_BUFFER_POINT_CIRCLE_HPP
11
12 #include <cstddef>
13
14 #include <boost/range.hpp>
15
16 #include <boost/geometry/util/math.hpp>
17
18 #include <boost/geometry/strategies/buffer.hpp>
19
20
21 namespace boost { namespace geometry
22 {
23
24 namespace strategy { namespace buffer
25 {
26
27 /*!
28 \brief Create a circular buffer around a point, on the Earth
29 \ingroup strategies
30 \details This strategy can be used as PointStrategy for the buffer algorithm.
31 It creates a circular buffer around a point, on the Earth. It can be applied
32 for points and multi_points.
33
34 \qbk{
35 [heading Example]
36 [buffer_geographic_point_circle]
37 [buffer_geographic_point_circle_output]
38 [heading See also]
39 \* [link geometry.reference.algorithms.buffer.buffer_7_with_strategies buffer (with strategies)]
40 \* [link geometry.reference.strategies.strategy_buffer_point_circle point_circle]
41 \* [link geometry.reference.strategies.strategy_buffer_point_square point_square]
42 }
43 */
44 template
45 <
46 typename FormulaPolicy = strategy::andoyer,
47 typename Spheroid = srs::spheroid<double>,
48 typename CalculationType = void
49 >
50 class geographic_point_circle
51 {
52 public :
53 //! \brief Constructs the strategy
54 //! \param count number of points for the created circle (if count
55 //! is smaller than 3, count is internally set to 3)
56 explicit geographic_point_circle(std::size_t count = 90)
57 : m_count((count < 3u) ? 3u : count)
58 {}
59
60 #ifndef DOXYGEN_SHOULD_SKIP_THIS
61 //! Fills output_range with a circle around point using distance_strategy
62 template
63 <
64 typename Point,
65 typename OutputRange,
66 typename DistanceStrategy
67 >
68 inline void apply(Point const& point,
69 DistanceStrategy const& distance_strategy,
70 OutputRange& output_range) const
71 {
72 typedef typename boost::range_value<OutputRange>::type output_point_type;
73
74 typedef typename select_most_precise
75 <
76 typename geometry::coordinate_type<Point>::type,
77 typename geometry::coordinate_type<output_point_type>::type,
78 CalculationType
79 //double
80 >::type calculation_type;
81
82 calculation_type const buffer_distance = distance_strategy.apply(point, point,
83 strategy::buffer::buffer_side_left);
84
85 typedef typename FormulaPolicy::template direct
86 <
87 calculation_type, true, false, false, false
88 > direct_t;
89
90 calculation_type const two_pi = geometry::math::two_pi<calculation_type>();
91 calculation_type const pi = geometry::math::pi<calculation_type>();
92
93 calculation_type const diff = two_pi / calculation_type(m_count);
94 // TODO: after calculation of some angles is corrected,
95 // we can start at 0.0
96 calculation_type angle = 0.001;
97
98 for (std::size_t i = 0; i < m_count; i++, angle += diff)
99 {
100 if (angle > pi)
101 {
102 angle -= two_pi;
103 }
104
105 typename direct_t::result_type
106 dir_r = direct_t::apply(get_as_radian<0>(point), get_as_radian<1>(point),
107 buffer_distance, angle,
108 m_spheroid);
109 output_point_type p;
110 set_from_radian<0>(p, dir_r.lon2);
111 set_from_radian<1>(p, dir_r.lat2);
112 output_range.push_back(p);
113 }
114
115 {
116 // Close the range
117 const output_point_type p = output_range.front();
118 output_range.push_back(p);
119 }
120 }
121 #endif // DOXYGEN_SHOULD_SKIP_THIS
122
123 private :
124 std::size_t m_count;
125 Spheroid m_spheroid;
126 };
127
128
129 }} // namespace strategy::buffer
130
131 }} // namespace boost::geometry
132
133 #endif // BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_BUFFER_POINT_CIRCLE_HPP