]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // Boost.Geometry (aka GGL, Generic Geometry Library) |
2 | ||
3 | // Copyright (c) 2012-2015 Barend Gehrels, Amsterdam, the Netherlands. | |
4 | ||
5 | // This file was modified by Oracle on 2015. | |
6 | // Modifications copyright (c) 2015, Oracle and/or its affiliates. | |
7 | ||
8 | // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle | |
9 | ||
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) | |
13 | ||
14 | #ifndef BOOST_GEOMETRY_STRATEGIES_CARTESIAN_BUFFER_POINT_CIRCLE_HPP | |
15 | #define BOOST_GEOMETRY_STRATEGIES_CARTESIAN_BUFFER_POINT_CIRCLE_HPP | |
16 | ||
17 | #include <cstddef> | |
18 | ||
19 | #include <boost/range.hpp> | |
20 | ||
21 | #include <boost/geometry/util/math.hpp> | |
22 | ||
23 | #include <boost/geometry/strategies/buffer.hpp> | |
24 | ||
25 | ||
26 | namespace boost { namespace geometry | |
27 | { | |
28 | ||
29 | namespace strategy { namespace buffer | |
30 | { | |
31 | ||
32 | /*! | |
33 | \brief Create a circular buffer around a point | |
34 | \ingroup strategies | |
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. | |
40 | ||
41 | \qbk{ | |
42 | [heading Example] | |
43 | [buffer_point_circle] | |
44 | [heading Output] | |
45 | [$img/strategies/buffer_point_circle.png] | |
46 | [heading See also] | |
47 | \* [link geometry.reference.algorithms.buffer.buffer_7_with_strategies buffer (with strategies)] | |
48 | \* [link geometry.reference.strategies.strategy_buffer_point_square point_square] | |
49 | } | |
50 | */ | |
51 | class point_circle | |
52 | { | |
53 | public : | |
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) | |
59 | {} | |
60 | ||
61 | #ifndef DOXYGEN_SHOULD_SKIP_THIS | |
62 | //! Fills output_range with a circle around point using distance_strategy | |
63 | template | |
64 | < | |
65 | typename Point, | |
66 | typename OutputRange, | |
67 | typename DistanceStrategy | |
68 | > | |
69 | inline void apply(Point const& point, | |
70 | DistanceStrategy const& distance_strategy, | |
71 | OutputRange& output_range) const | |
72 | { | |
73 | typedef typename boost::range_value<OutputRange>::type output_point_type; | |
74 | ||
75 | typedef typename geometry::select_most_precise | |
76 | < | |
77 | typename geometry::select_most_precise | |
78 | < | |
79 | typename geometry::coordinate_type<Point>::type, | |
80 | typename geometry::coordinate_type<output_point_type>::type | |
81 | >::type, | |
82 | double | |
83 | >::type promoted_type; | |
84 | ||
85 | promoted_type const buffer_distance = distance_strategy.apply(point, point, | |
86 | strategy::buffer::buffer_side_left); | |
87 | ||
88 | promoted_type const two_pi = geometry::math::two_pi<promoted_type>(); | |
89 | ||
90 | promoted_type const diff = two_pi / promoted_type(m_count); | |
91 | promoted_type a = 0; | |
92 | ||
93 | for (std::size_t i = 0; i < m_count; i++, a -= diff) | |
94 | { | |
95 | output_point_type p; | |
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); | |
99 | } | |
100 | ||
101 | // Close it: | |
102 | output_range.push_back(output_range.front()); | |
103 | } | |
104 | #endif // DOXYGEN_SHOULD_SKIP_THIS | |
105 | ||
106 | private : | |
107 | std::size_t m_count; | |
108 | }; | |
109 | ||
110 | ||
111 | }} // namespace strategy::buffer | |
112 | ||
113 | }} // namespace boost::geometry | |
114 | ||
115 | #endif // BOOST_GEOMETRY_STRATEGIES_CARTESIAN_BUFFER_POINT_CIRCLE_HPP |