buffer_point_circle.hpp 4.1 KB

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