]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // Boost.Geometry (aka GGL, Generic Geometry Library) |
2 | ||
3 | // Copyright (c) 2012-2014 Barend Gehrels, Amsterdam, the Netherlands. | |
4 | ||
5 | // Use, modification and distribution is subject to the Boost Software License, | |
6 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at | |
7 | // http://www.boost.org/LICENSE_1_0.txt) | |
8 | ||
9 | #ifndef BOOST_GEOMETRY_STRATEGIES_AGNOSTIC_BUFFER_DISTANCE_SYMMETRIC_HPP | |
10 | #define BOOST_GEOMETRY_STRATEGIES_AGNOSTIC_BUFFER_DISTANCE_SYMMETRIC_HPP | |
11 | ||
12 | ||
13 | #include <boost/core/ignore_unused.hpp> | |
14 | ||
15 | #include <boost/geometry/strategies/buffer.hpp> | |
16 | #include <boost/geometry/util/math.hpp> | |
17 | ||
18 | ||
19 | namespace boost { namespace geometry | |
20 | { | |
21 | ||
22 | namespace strategy { namespace buffer | |
23 | { | |
24 | ||
25 | ||
26 | /*! | |
27 | \brief Let the buffer algorithm create buffers with same distances | |
28 | \ingroup strategies | |
29 | \tparam NumericType \tparam_numeric | |
30 | \details This strategy can be used as DistanceStrategy for the buffer algorithm. | |
31 | It can be applied for all geometries. It uses one distance for left and | |
32 | for right. | |
33 | If the distance is negative and used with a (multi)polygon or ring, the | |
34 | geometry will shrink (deflate) instead of expand (inflate). | |
35 | ||
36 | \qbk{ | |
37 | [heading Example] | |
38 | [buffer_distance_symmetric] | |
39 | [heading Output] | |
40 | [$img/strategies/buffer_distance_symmetric.png] | |
41 | [heading See also] | |
42 | \* [link geometry.reference.algorithms.buffer.buffer_7_with_strategies buffer (with strategies)] | |
43 | \* [link geometry.reference.strategies.strategy_buffer_distance_asymmetric distance_asymmetric] | |
44 | } | |
45 | */ | |
46 | template<typename NumericType> | |
47 | class distance_symmetric | |
48 | { | |
49 | public : | |
50 | //! \brief Constructs the strategy, a distance must be specified | |
51 | //! \param distance The distance (or radius) of the buffer | |
52 | explicit inline distance_symmetric(NumericType const& distance) | |
53 | : m_distance(distance) | |
54 | {} | |
55 | ||
56 | #ifndef DOXYGEN_SHOULD_SKIP_THIS | |
57 | //! Returns the distance-value | |
58 | template <typename Point> | |
59 | inline NumericType apply(Point const& , Point const& , | |
60 | buffer_side_selector ) const | |
61 | { | |
62 | return negative() ? geometry::math::abs(m_distance) : m_distance; | |
63 | } | |
64 | ||
65 | //! Used internally, returns -1 for deflate, 1 for inflate | |
66 | inline int factor() const | |
67 | { | |
68 | return negative() ? -1 : 1; | |
69 | } | |
70 | ||
b32b8144 | 71 | //! Returns true if distance is negative (aka deflate) |
7c673cae FG |
72 | inline bool negative() const |
73 | { | |
74 | return m_distance < 0; | |
75 | } | |
76 | ||
77 | //! Returns the max distance distance up to the buffer will reach | |
78 | template <typename JoinStrategy, typename EndStrategy> | |
79 | inline NumericType max_distance(JoinStrategy const& join_strategy, | |
80 | EndStrategy const& end_strategy) const | |
81 | { | |
82 | boost::ignore_unused(join_strategy, end_strategy); | |
83 | ||
84 | NumericType const dist = geometry::math::abs(m_distance); | |
85 | return (std::max)(join_strategy.max_distance(dist), | |
86 | end_strategy.max_distance(dist)); | |
87 | } | |
88 | ||
89 | ||
90 | //! Returns the distance at which the input is simplified before the buffer process | |
91 | inline NumericType simplify_distance() const | |
92 | { | |
93 | return geometry::math::abs(m_distance) / 1000.0; | |
94 | } | |
95 | #endif // DOXYGEN_SHOULD_SKIP_THIS | |
96 | ||
97 | private : | |
98 | NumericType m_distance; | |
99 | }; | |
100 | ||
101 | ||
102 | }} // namespace strategy::buffer | |
103 | ||
104 | ||
105 | }} // namespace boost::geometry | |
106 | ||
107 | #endif // BOOST_GEOMETRY_STRATEGIES_AGNOSTIC_BUFFER_DISTANCE_SYMMETRIC_HPP |