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