]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/geometry/strategies/agnostic/buffer_distance_asymmetric.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / geometry / strategies / agnostic / buffer_distance_asymmetric.hpp
CommitLineData
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_ASYMMETRIC_HPP
10#define BOOST_GEOMETRY_STRATEGIES_AGNOSTIC_BUFFER_DISTANCE_ASYMMETRIC_HPP
11
12#include <boost/core/ignore_unused.hpp>
13
14#include <boost/geometry/strategies/buffer.hpp>
15#include <boost/geometry/util/math.hpp>
16
17
18namespace boost { namespace geometry
19{
20
21namespace strategy { namespace buffer
22{
23
24
25/*!
26\brief Let the buffer for linestrings be asymmetric
27\ingroup strategies
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.
33
34\qbk{
35[heading Example]
36[buffer_distance_asymmetric]
37[heading Output]
38[$img/strategies/buffer_distance_asymmetric.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_distance_symmetric distance_symmetric]
42}
43 */
44template<typename NumericType>
45class distance_asymmetric
46{
47public :
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)
53 : m_left(left)
54 , m_right(right)
55 {}
56
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
62 {
63 NumericType result = side == buffer_side_left ? m_left : m_right;
64 return negative() ? math::abs(result) : result;
65 }
66
67 //! Used internally, returns -1 for deflate, 1 for inflate
68 inline int factor() const
69 {
70 return negative() ? -1 : 1;
71 }
72
73 //! Returns true if both distances are negative
74 inline bool negative() const
75 {
76 return m_left < 0 && m_right < 0;
77 }
78
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
83 {
84 boost::ignore_unused(join_strategy, end_strategy);
85
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));
91 }
92
93 //! Returns the distance at which the input is simplified before the buffer process
94 inline NumericType simplify_distance() const
95 {
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;
99 }
100
101#endif // DOXYGEN_SHOULD_SKIP_THIS
102
103private :
104 NumericType m_left;
105 NumericType m_right;
106};
107
108
109}} // namespace strategy::buffer
110
111
112}} // namespace boost::geometry
113
114#endif // BOOST_GEOMETRY_STRATEGIES_AGNOSTIC_BUFFER_DISTANCE_ASYMMETRIC_HPP