buffer_distance_symmetric.hpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2012-2014 Barend Gehrels, Amsterdam, the Netherlands.
  3. // Use, modification and distribution is subject to the Boost Software License,
  4. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. #ifndef BOOST_GEOMETRY_STRATEGIES_AGNOSTIC_BUFFER_DISTANCE_SYMMETRIC_HPP
  7. #define BOOST_GEOMETRY_STRATEGIES_AGNOSTIC_BUFFER_DISTANCE_SYMMETRIC_HPP
  8. #include <boost/core/ignore_unused.hpp>
  9. #include <boost/geometry/strategies/buffer.hpp>
  10. #include <boost/geometry/util/math.hpp>
  11. namespace boost { namespace geometry
  12. {
  13. namespace strategy { namespace buffer
  14. {
  15. /*!
  16. \brief Let the buffer algorithm create buffers with same distances
  17. \ingroup strategies
  18. \tparam NumericType \tparam_numeric
  19. \details This strategy can be used as DistanceStrategy for the buffer algorithm.
  20. It can be applied for all geometries. It uses one distance for left and
  21. for right.
  22. If the distance is negative and used with a (multi)polygon or ring, the
  23. geometry will shrink (deflate) instead of expand (inflate).
  24. \qbk{
  25. [heading Example]
  26. [buffer_distance_symmetric]
  27. [heading Output]
  28. [$img/strategies/buffer_distance_symmetric.png]
  29. [heading See also]
  30. \* [link geometry.reference.algorithms.buffer.buffer_7_with_strategies buffer (with strategies)]
  31. \* [link geometry.reference.strategies.strategy_buffer_distance_asymmetric distance_asymmetric]
  32. }
  33. */
  34. template<typename NumericType>
  35. class distance_symmetric
  36. {
  37. public :
  38. //! \brief Constructs the strategy, a distance must be specified
  39. //! \param distance The distance (or radius) of the buffer
  40. explicit inline distance_symmetric(NumericType const& distance)
  41. : m_distance(distance)
  42. {}
  43. #ifndef DOXYGEN_SHOULD_SKIP_THIS
  44. //! Returns the distance-value
  45. template <typename Point>
  46. inline NumericType apply(Point const& , Point const& ,
  47. buffer_side_selector ) const
  48. {
  49. return negative() ? geometry::math::abs(m_distance) : m_distance;
  50. }
  51. //! Used internally, returns -1 for deflate, 1 for inflate
  52. inline int factor() const
  53. {
  54. return negative() ? -1 : 1;
  55. }
  56. //! Returns true if distance is negative (aka deflate)
  57. inline bool negative() const
  58. {
  59. return m_distance < 0;
  60. }
  61. //! Returns the max distance distance up to the buffer will reach
  62. template <typename JoinStrategy, typename EndStrategy>
  63. inline NumericType max_distance(JoinStrategy const& join_strategy,
  64. EndStrategy const& end_strategy) const
  65. {
  66. boost::ignore_unused(join_strategy, end_strategy);
  67. NumericType const dist = geometry::math::abs(m_distance);
  68. return (std::max)(join_strategy.max_distance(dist),
  69. end_strategy.max_distance(dist));
  70. }
  71. //! Returns the distance at which the input is simplified before the buffer process
  72. inline NumericType simplify_distance() const
  73. {
  74. return geometry::math::abs(m_distance) / 1000.0;
  75. }
  76. #endif // DOXYGEN_SHOULD_SKIP_THIS
  77. private :
  78. NumericType m_distance;
  79. };
  80. }} // namespace strategy::buffer
  81. }} // namespace boost::geometry
  82. #endif // BOOST_GEOMETRY_STRATEGIES_AGNOSTIC_BUFFER_DISTANCE_SYMMETRIC_HPP