]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/include/boost/geometry/strategies/cartesian/buffer_point_square.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / geometry / include / boost / geometry / strategies / cartesian / buffer_point_square.hpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Copyright (c) 2012-2014 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
7 #ifndef BOOST_GEOMETRY_STRATEGIES_CARTESIAN_BUFFER_POINT_SQUARE_HPP
8 #define BOOST_GEOMETRY_STRATEGIES_CARTESIAN_BUFFER_POINT_SQUARE_HPP
9
10 #include <cstddef>
11
12 #include <boost/range.hpp>
13
14 #include <boost/geometry/util/math.hpp>
15
16 #include <boost/geometry/strategies/buffer.hpp>
17
18
19 namespace boost { namespace geometry
20 {
21
22 namespace strategy { namespace buffer
23 {
24
25 /*!
26 \brief Create a squared form buffer around a point
27 \ingroup strategies
28 \details This strategy can be used as PointStrategy for the buffer algorithm.
29 It creates a square from each point, where the point lies in the center.
30 It can be applied for points and multi_points, but also for a linestring (if it is degenerate,
31 so consisting of only one point) and for polygons (if it is degenerate).
32 This strategy is only applicable for Cartesian coordinate systems.
33
34 \qbk{
35 [heading Example]
36 [buffer_point_square]
37 [heading Output]
38 [$img/strategies/buffer_point_square.png]
39 [heading See also]
40 \* [link geometry.reference.algorithms.buffer.buffer_7_with_strategies buffer (with strategies)]
41 \* [link geometry.reference.strategies.strategy_buffer_point_circle point_circle]
42 }
43 */
44 class point_square
45 {
46 template
47 <
48 typename Point,
49 typename DistanceType,
50 typename OutputRange
51 >
52 inline void add_point(Point const& point,
53 DistanceType const& distance,
54 DistanceType const& x,
55 DistanceType const& y,
56 OutputRange& output_range) const
57 {
58 typename boost::range_value<OutputRange>::type p;
59 set<0>(p, get<0>(point) + x * distance);
60 set<1>(p, get<1>(point) + y * distance);
61 output_range.push_back(p);
62 }
63
64 template
65 <
66 typename Point,
67 typename DistanceType,
68 typename OutputRange
69 >
70 inline void add_points(Point const& point,
71 DistanceType const& distance,
72 OutputRange& output_range) const
73 {
74 add_point(point, distance, -1.0, -1.0, output_range);
75 add_point(point, distance, -1.0, +1.0, output_range);
76 add_point(point, distance, +1.0, +1.0, output_range);
77 add_point(point, distance, +1.0, -1.0, output_range);
78
79 // Close it:
80 output_range.push_back(output_range.front());
81 }
82
83 public :
84
85 #ifndef DOXYGEN_SHOULD_SKIP_THIS
86 //! Fills output_range with a square around point using distance_strategy
87 template
88 <
89 typename Point,
90 typename DistanceStrategy,
91 typename OutputRange
92 >
93 inline void apply(Point const& point,
94 DistanceStrategy const& distance_strategy,
95 OutputRange& output_range) const
96 {
97 add_points(point, distance_strategy.apply(point, point,
98 strategy::buffer::buffer_side_left), output_range);
99 }
100 #endif // DOXYGEN_SHOULD_SKIP_THIS
101
102 };
103
104
105 }} // namespace strategy::buffer
106
107 }} // namespace boost::geometry
108
109 #endif // BOOST_GEOMETRY_STRATEGIES_CARTESIAN_BUFFER_POINT_SQUARE_HPP