1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2012-2015 Barend Gehrels, Amsterdam, the Netherlands.
5 // This file was modified by Oracle on 2015.
6 // Modifications copyright (c) 2015, Oracle and/or its affiliates.
8 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
10 // Use, modification and distribution is subject to the Boost Software License,
11 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
12 // http://www.boost.org/LICENSE_1_0.txt)
14 #ifndef BOOST_GEOMETRY_STRATEGIES_CARTESIAN_BUFFER_POINT_CIRCLE_HPP
15 #define BOOST_GEOMETRY_STRATEGIES_CARTESIAN_BUFFER_POINT_CIRCLE_HPP
19 #include <boost/range.hpp>
21 #include <boost/geometry/util/math.hpp>
23 #include <boost/geometry/strategies/buffer.hpp>
26 namespace boost { namespace geometry
29 namespace strategy { namespace buffer
33 \brief Create a circular buffer around a point
35 \details This strategy can be used as PointStrategy for the buffer algorithm.
36 It creates a circular buffer around a point. It can be applied
37 for points and multi_points, but also for a linestring (if it is degenerate,
38 so consisting of only one point) and for polygons (if it is degenerate).
39 This strategy is only applicable for Cartesian coordinate systems.
45 [$img/strategies/buffer_point_circle.png]
47 \* [link geometry.reference.algorithms.buffer.buffer_7_with_strategies buffer (with strategies)]
48 \* [link geometry.reference.strategies.strategy_buffer_point_square point_square]
54 //! \brief Constructs the strategy
55 //! \param count number of points for the created circle (if count
56 //! is smaller than 3, count is internally set to 3)
57 explicit point_circle(std::size_t count = 90)
58 : m_count((count < 3u) ? 3u : count)
61 #ifndef DOXYGEN_SHOULD_SKIP_THIS
62 //! Fills output_range with a circle around point using distance_strategy
67 typename DistanceStrategy
69 inline void apply(Point const& point,
70 DistanceStrategy const& distance_strategy,
71 OutputRange& output_range) const
73 typedef typename boost::range_value<OutputRange>::type output_point_type;
75 typedef typename geometry::select_most_precise
77 typename geometry::select_most_precise
79 typename geometry::coordinate_type<Point>::type,
80 typename geometry::coordinate_type<output_point_type>::type
83 >::type promoted_type;
85 promoted_type const buffer_distance = distance_strategy.apply(point, point,
86 strategy::buffer::buffer_side_left);
88 promoted_type const two_pi = geometry::math::two_pi<promoted_type>();
90 promoted_type const diff = two_pi / promoted_type(m_count);
93 for (std::size_t i = 0; i < m_count; i++, a -= diff)
96 set<0>(p, get<0>(point) + buffer_distance * cos(a));
97 set<1>(p, get<1>(point) + buffer_distance * sin(a));
98 output_range.push_back(p);
102 output_range.push_back(output_range.front());
104 #endif // DOXYGEN_SHOULD_SKIP_THIS
111 }} // namespace strategy::buffer
113 }} // namespace boost::geometry
115 #endif // BOOST_GEOMETRY_STRATEGIES_CARTESIAN_BUFFER_POINT_CIRCLE_HPP