Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:36:41

0001 // Boost.Geometry (aka GGL, Generic Geometry Library)
0002 
0003 // Copyright (c) 2012-2014 Barend Gehrels, Amsterdam, the Netherlands.
0004 
0005 // Use, modification and distribution is subject to the Boost Software License,
0006 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0007 // http://www.boost.org/LICENSE_1_0.txt)
0008 
0009 #ifndef BOOST_GEOMETRY_STRATEGIES_AGNOSTIC_BUFFER_DISTANCE_ASYMMETRIC_HPP
0010 #define BOOST_GEOMETRY_STRATEGIES_AGNOSTIC_BUFFER_DISTANCE_ASYMMETRIC_HPP
0011 
0012 #include <boost/core/ignore_unused.hpp>
0013 
0014 #include <boost/geometry/strategies/buffer.hpp>
0015 #include <boost/geometry/util/math.hpp>
0016 
0017 
0018 namespace boost { namespace geometry
0019 {
0020 
0021 namespace strategy { namespace buffer
0022 {
0023 
0024 
0025 /*!
0026 \brief Let the buffer for linestrings be asymmetric
0027 \ingroup strategies
0028 \tparam NumericType \tparam_numeric
0029 \details This strategy can be used as DistanceStrategy for the buffer algorithm.
0030     It can be applied for (multi)linestrings. It uses a (potentially) different
0031     distances for left and for right. This means the (multi)linestrings are
0032     interpreted having a direction.
0033 
0034 \qbk{
0035 [heading Example]
0036 [buffer_distance_asymmetric]
0037 [heading Output]
0038 [$img/strategies/buffer_distance_asymmetric.png]
0039 [heading See also]
0040 \* [link geometry.reference.algorithms.buffer.buffer_7_with_strategies buffer (with strategies)]
0041 \* [link geometry.reference.strategies.strategy_buffer_distance_symmetric distance_symmetric]
0042 }
0043  */
0044 template<typename NumericType>
0045 class distance_asymmetric
0046 {
0047 public :
0048     //! \brief Constructs the strategy, two distances must be specified
0049     //! \param left The distance (or radius) of the buffer on the left side
0050     //! \param right The distance on the right side
0051     distance_asymmetric(NumericType const& left,
0052                 NumericType const& right)
0053         : m_left(left)
0054         , m_right(right)
0055     {}
0056 
0057 #ifndef DOXYGEN_SHOULD_SKIP_THIS
0058     //! Returns the distance-value for the specified side
0059     template <typename Point>
0060     inline NumericType apply(Point const& , Point const& ,
0061                 buffer_side_selector side)  const
0062     {
0063         NumericType result = side == buffer_side_left ? m_left : m_right;
0064         return negative() ? math::abs(result) : result;
0065     }
0066 
0067     //! Used internally, returns -1 for deflate, 1 for inflate
0068     inline int factor() const
0069     {
0070         return negative() ? -1 : 1;
0071     }
0072 
0073     //! Returns true if both distances are negative
0074     inline bool negative() const
0075     {
0076         return m_left < 0 && m_right < 0;
0077     }
0078 
0079     inline bool empty(buffer_side_selector side) const
0080     {
0081         return side == buffer_side_left ? m_left == 0 : m_right == 0;
0082     }
0083 
0084     //! Returns the max distance distance up to the buffer will reach
0085     template <typename JoinStrategy, typename EndStrategy>
0086     inline NumericType max_distance(JoinStrategy const& join_strategy,
0087             EndStrategy const& end_strategy) const
0088     {
0089         boost::ignore_unused(join_strategy, end_strategy);
0090 
0091         NumericType const left = geometry::math::abs(m_left);
0092         NumericType const right = geometry::math::abs(m_right);
0093         NumericType const dist = (std::max)(left, right);
0094         return (std::max)(join_strategy.max_distance(dist),
0095                           end_strategy.max_distance(dist));
0096     }
0097 
0098     //! Returns the distance at which the input is simplified before the buffer process
0099     inline NumericType simplify_distance() const
0100     {
0101         NumericType const left = geometry::math::abs(m_left);
0102         NumericType const right = geometry::math::abs(m_right);
0103         return (std::min)(left, right) / 1000.0;
0104     }
0105 
0106 #endif // DOXYGEN_SHOULD_SKIP_THIS
0107 
0108 private :
0109     NumericType m_left;
0110     NumericType m_right;
0111 };
0112 
0113 
0114 }} // namespace strategy::buffer
0115 
0116 
0117 }} // namespace boost::geometry
0118 
0119 #endif // BOOST_GEOMETRY_STRATEGIES_AGNOSTIC_BUFFER_DISTANCE_ASYMMETRIC_HPP