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)
7 #ifndef BOOST_GEOMETRY_STRATEGIES_CARTESIAN_BUFFER_POINT_SQUARE_HPP
8 #define BOOST_GEOMETRY_STRATEGIES_CARTESIAN_BUFFER_POINT_SQUARE_HPP
12 #include <boost/range.hpp>
14 #include <boost/geometry/util/math.hpp>
16 #include <boost/geometry/strategies/buffer.hpp>
19 namespace boost { namespace geometry
22 namespace strategy { namespace buffer
26 \brief Create a squared form buffer around a point
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.
38 [$img/strategies/buffer_point_square.png]
40 \* [link geometry.reference.algorithms.buffer.buffer_7_with_strategies buffer (with strategies)]
41 \* [link geometry.reference.strategies.strategy_buffer_point_circle point_circle]
49 typename DistanceType,
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
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);
67 typename DistanceType,
70 inline void add_points(Point const& point,
71 DistanceType const& distance,
72 OutputRange& output_range) const
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);
80 output_range.push_back(output_range.front());
85 #ifndef DOXYGEN_SHOULD_SKIP_THIS
86 //! Fills output_range with a square around point using distance_strategy
90 typename DistanceStrategy,
93 inline void apply(Point const& point,
94 DistanceStrategy const& distance_strategy,
95 OutputRange& output_range) const
97 add_points(point, distance_strategy.apply(point, point,
98 strategy::buffer::buffer_side_left), output_range);
100 #endif // DOXYGEN_SHOULD_SKIP_THIS
105 }} // namespace strategy::buffer
107 }} // namespace boost::geometry
109 #endif // BOOST_GEOMETRY_STRATEGIES_CARTESIAN_BUFFER_POINT_SQUARE_HPP