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_SYMMETRIC_HPP
0010 #define BOOST_GEOMETRY_STRATEGIES_AGNOSTIC_BUFFER_DISTANCE_SYMMETRIC_HPP
0011 
0012 
0013 #include <boost/core/ignore_unused.hpp>
0014 
0015 #include <boost/geometry/strategies/buffer.hpp>
0016 #include <boost/geometry/util/math.hpp>
0017 
0018 
0019 namespace boost { namespace geometry
0020 {
0021 
0022 namespace strategy { namespace buffer
0023 {
0024 
0025 
0026 /*!
0027 \brief Let the buffer algorithm create buffers with same distances
0028 \ingroup strategies
0029 \tparam NumericType \tparam_numeric
0030 \details This strategy can be used as DistanceStrategy for the buffer algorithm.
0031     It can be applied for all geometries. It uses one distance for left and
0032     for right.
0033     If the distance is negative and used with a (multi)polygon or ring, the
0034     geometry will shrink (deflate) instead of expand (inflate).
0035 
0036 \qbk{
0037 [heading Example]
0038 [buffer_distance_symmetric]
0039 [heading Output]
0040 [$img/strategies/buffer_distance_symmetric.png]
0041 [heading See also]
0042 \* [link geometry.reference.algorithms.buffer.buffer_7_with_strategies buffer (with strategies)]
0043 \* [link geometry.reference.strategies.strategy_buffer_distance_asymmetric distance_asymmetric]
0044 }
0045  */
0046 template<typename NumericType>
0047 class distance_symmetric
0048 {
0049 public :
0050     //! \brief Constructs the strategy, a distance must be specified
0051     //! \param distance The distance (or radius) of the buffer
0052     explicit inline distance_symmetric(NumericType const& distance)
0053         : m_distance(distance)
0054     {}
0055 
0056 #ifndef DOXYGEN_SHOULD_SKIP_THIS
0057     //! Returns the distance-value
0058     template <typename Point>
0059     inline NumericType apply(Point const& , Point const& ,
0060                 buffer_side_selector )  const
0061     {
0062         return negative() ? geometry::math::abs(m_distance) : m_distance;
0063     }
0064 
0065     //! Used internally, returns -1 for deflate, 1 for inflate
0066     inline int factor() const
0067     {
0068         return negative() ? -1 : 1;
0069     }
0070 
0071     //! Returns true if distance is negative (aka deflate)
0072     inline bool negative() const
0073     {
0074         return m_distance < 0;
0075     }
0076 
0077     inline bool empty(buffer_side_selector ) const
0078     {
0079         return m_distance == 0;
0080     }
0081 
0082     //! Returns the max distance distance up to the buffer will reach
0083     template <typename JoinStrategy, typename EndStrategy>
0084     inline NumericType max_distance(JoinStrategy const& join_strategy,
0085             EndStrategy const& end_strategy) const
0086     {
0087         boost::ignore_unused(join_strategy, end_strategy);
0088 
0089         NumericType const dist = geometry::math::abs(m_distance);
0090         return (std::max)(join_strategy.max_distance(dist),
0091                           end_strategy.max_distance(dist));
0092     }
0093 
0094 
0095     //! Returns the distance at which the input is simplified before the buffer process
0096     inline NumericType simplify_distance() const
0097     {
0098         return geometry::math::abs(m_distance) / 1000.0;
0099     }
0100 #endif // DOXYGEN_SHOULD_SKIP_THIS
0101 
0102 private :
0103     NumericType m_distance;
0104 };
0105 
0106 
0107 }} // namespace strategy::buffer
0108 
0109 
0110 }} // namespace boost::geometry
0111 
0112 #endif // BOOST_GEOMETRY_STRATEGIES_AGNOSTIC_BUFFER_DISTANCE_SYMMETRIC_HPP