annotate DEPENDENCIES/generic/include/boost/geometry/strategies/cartesian/buffer_point_circle.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents f46d142149f5
children
rev   line source
Chris@102 1 // Boost.Geometry (aka GGL, Generic Geometry Library)
Chris@102 2
Chris@102 3 // Copyright (c) 2012-2015 Barend Gehrels, Amsterdam, the Netherlands.
Chris@102 4
Chris@102 5 // This file was modified by Oracle on 2015.
Chris@102 6 // Modifications copyright (c) 2015, Oracle and/or its affiliates.
Chris@102 7
Chris@102 8 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
Chris@102 9
Chris@102 10 // Use, modification and distribution is subject to the Boost Software License,
Chris@102 11 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
Chris@102 12 // http://www.boost.org/LICENSE_1_0.txt)
Chris@102 13
Chris@102 14 #ifndef BOOST_GEOMETRY_STRATEGIES_CARTESIAN_BUFFER_POINT_CIRCLE_HPP
Chris@102 15 #define BOOST_GEOMETRY_STRATEGIES_CARTESIAN_BUFFER_POINT_CIRCLE_HPP
Chris@102 16
Chris@102 17 #include <cstddef>
Chris@102 18
Chris@102 19 #include <boost/range.hpp>
Chris@102 20
Chris@102 21 #include <boost/geometry/util/math.hpp>
Chris@102 22
Chris@102 23 #include <boost/geometry/strategies/buffer.hpp>
Chris@102 24
Chris@102 25
Chris@102 26 namespace boost { namespace geometry
Chris@102 27 {
Chris@102 28
Chris@102 29 namespace strategy { namespace buffer
Chris@102 30 {
Chris@102 31
Chris@102 32 /*!
Chris@102 33 \brief Create a circular buffer around a point
Chris@102 34 \ingroup strategies
Chris@102 35 \details This strategy can be used as PointStrategy for the buffer algorithm.
Chris@102 36 It creates a circular buffer around a point. It can be applied
Chris@102 37 for points and multi_points, but also for a linestring (if it is degenerate,
Chris@102 38 so consisting of only one point) and for polygons (if it is degenerate).
Chris@102 39 This strategy is only applicable for Cartesian coordinate systems.
Chris@102 40
Chris@102 41 \qbk{
Chris@102 42 [heading Example]
Chris@102 43 [buffer_point_circle]
Chris@102 44 [heading Output]
Chris@102 45 [$img/strategies/buffer_point_circle.png]
Chris@102 46 [heading See also]
Chris@102 47 \* [link geometry.reference.algorithms.buffer.buffer_7_with_strategies buffer (with strategies)]
Chris@102 48 \* [link geometry.reference.strategies.strategy_buffer_point_square point_square]
Chris@102 49 }
Chris@102 50 */
Chris@102 51 class point_circle
Chris@102 52 {
Chris@102 53 public :
Chris@102 54 //! \brief Constructs the strategy
Chris@102 55 //! \param count number of points for the created circle (if count
Chris@102 56 //! is smaller than 3, count is internally set to 3)
Chris@102 57 explicit point_circle(std::size_t count = 90)
Chris@102 58 : m_count((count < 3u) ? 3u : count)
Chris@102 59 {}
Chris@102 60
Chris@102 61 #ifndef DOXYGEN_SHOULD_SKIP_THIS
Chris@102 62 //! Fills output_range with a circle around point using distance_strategy
Chris@102 63 template
Chris@102 64 <
Chris@102 65 typename Point,
Chris@102 66 typename OutputRange,
Chris@102 67 typename DistanceStrategy
Chris@102 68 >
Chris@102 69 inline void apply(Point const& point,
Chris@102 70 DistanceStrategy const& distance_strategy,
Chris@102 71 OutputRange& output_range) const
Chris@102 72 {
Chris@102 73 typedef typename boost::range_value<OutputRange>::type output_point_type;
Chris@102 74
Chris@102 75 typedef typename geometry::select_most_precise
Chris@102 76 <
Chris@102 77 typename geometry::select_most_precise
Chris@102 78 <
Chris@102 79 typename geometry::coordinate_type<Point>::type,
Chris@102 80 typename geometry::coordinate_type<output_point_type>::type
Chris@102 81 >::type,
Chris@102 82 double
Chris@102 83 >::type promoted_type;
Chris@102 84
Chris@102 85 promoted_type const buffer_distance = distance_strategy.apply(point, point,
Chris@102 86 strategy::buffer::buffer_side_left);
Chris@102 87
Chris@102 88 promoted_type const two = 2.0;
Chris@102 89 promoted_type const two_pi = two * geometry::math::pi<promoted_type>();
Chris@102 90
Chris@102 91 promoted_type const diff = two_pi / promoted_type(m_count);
Chris@102 92 promoted_type a = 0;
Chris@102 93
Chris@102 94 for (std::size_t i = 0; i < m_count; i++, a -= diff)
Chris@102 95 {
Chris@102 96 output_point_type p;
Chris@102 97 set<0>(p, get<0>(point) + buffer_distance * cos(a));
Chris@102 98 set<1>(p, get<1>(point) + buffer_distance * sin(a));
Chris@102 99 output_range.push_back(p);
Chris@102 100 }
Chris@102 101
Chris@102 102 // Close it:
Chris@102 103 output_range.push_back(output_range.front());
Chris@102 104 }
Chris@102 105 #endif // DOXYGEN_SHOULD_SKIP_THIS
Chris@102 106
Chris@102 107 private :
Chris@102 108 std::size_t m_count;
Chris@102 109 };
Chris@102 110
Chris@102 111
Chris@102 112 }} // namespace strategy::buffer
Chris@102 113
Chris@102 114 }} // namespace boost::geometry
Chris@102 115
Chris@102 116 #endif // BOOST_GEOMETRY_STRATEGIES_CARTESIAN_BUFFER_POINT_CIRCLE_HPP