1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2012-2014 Barend Gehrels, Amsterdam, the Netherlands.
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)
9 #ifndef BOOST_GEOMETRY_STRATEGIES_AGNOSTIC_BUFFER_DISTANCE_ASYMMETRIC_HPP
10 #define BOOST_GEOMETRY_STRATEGIES_AGNOSTIC_BUFFER_DISTANCE_ASYMMETRIC_HPP
12 #include <boost/core/ignore_unused.hpp>
14 #include <boost/geometry/strategies/buffer.hpp>
15 #include <boost/geometry/util/math.hpp>
18 namespace boost { namespace geometry
21 namespace strategy { namespace buffer
26 \brief Let the buffer for linestrings be asymmetric
28 \tparam NumericType \tparam_numeric
29 \details This strategy can be used as DistanceStrategy for the buffer algorithm.
30 It can be applied for (multi)linestrings. It uses a (potentially) different
31 distances for left and for right. This means the (multi)linestrings are
32 interpreted having a direction.
36 [buffer_distance_asymmetric]
38 [$img/strategies/buffer_distance_asymmetric.png]
40 \* [link geometry.reference.algorithms.buffer.buffer_7_with_strategies buffer (with strategies)]
41 \* [link geometry.reference.strategies.strategy_buffer_distance_symmetric distance_symmetric]
44 template<typename NumericType>
45 class distance_asymmetric
48 //! \brief Constructs the strategy, two distances must be specified
49 //! \param left The distance (or radius) of the buffer on the left side
50 //! \param right The distance on the right side
51 distance_asymmetric(NumericType const& left,
52 NumericType const& right)
57 #ifndef DOXYGEN_SHOULD_SKIP_THIS
58 //! Returns the distance-value for the specified side
59 template <typename Point>
60 inline NumericType apply(Point const& , Point const& ,
61 buffer_side_selector side) const
63 NumericType result = side == buffer_side_left ? m_left : m_right;
64 return negative() ? math::abs(result) : result;
67 //! Used internally, returns -1 for deflate, 1 for inflate
68 inline int factor() const
70 return negative() ? -1 : 1;
73 //! Returns true if both distances are negative
74 inline bool negative() const
76 return m_left < 0 && m_right < 0;
79 //! Returns the max distance distance up to the buffer will reach
80 template <typename JoinStrategy, typename EndStrategy>
81 inline NumericType max_distance(JoinStrategy const& join_strategy,
82 EndStrategy const& end_strategy) const
84 boost::ignore_unused(join_strategy, end_strategy);
86 NumericType const left = geometry::math::abs(m_left);
87 NumericType const right = geometry::math::abs(m_right);
88 NumericType const dist = (std::max)(left, right);
89 return (std::max)(join_strategy.max_distance(dist),
90 end_strategy.max_distance(dist));
93 //! Returns the distance at which the input is simplified before the buffer process
94 inline NumericType simplify_distance() const
96 NumericType const left = geometry::math::abs(m_left);
97 NumericType const right = geometry::math::abs(m_right);
98 return (std::min)(left, right) / 1000.0;
101 #endif // DOXYGEN_SHOULD_SKIP_THIS
109 }} // namespace strategy::buffer
112 }} // namespace boost::geometry
114 #endif // BOOST_GEOMETRY_STRATEGIES_AGNOSTIC_BUFFER_DISTANCE_ASYMMETRIC_HPP