Chris@102: // Boost.Geometry (aka GGL, Generic Geometry Library) Chris@102: Chris@102: // Copyright (c) 2012-2014 Barend Gehrels, Amsterdam, the Netherlands. Chris@102: Chris@102: // Use, modification and distribution is subject to the Boost Software License, Chris@102: // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at Chris@102: // http://www.boost.org/LICENSE_1_0.txt) Chris@102: Chris@102: #ifndef BOOST_GEOMETRY_STRATEGIES_AGNOSTIC_BUFFER_DISTANCE_SYMMETRIC_HPP Chris@102: #define BOOST_GEOMETRY_STRATEGIES_AGNOSTIC_BUFFER_DISTANCE_SYMMETRIC_HPP Chris@102: Chris@102: Chris@102: #include Chris@102: Chris@102: #include Chris@102: #include Chris@102: Chris@102: Chris@102: namespace boost { namespace geometry Chris@102: { Chris@102: Chris@102: namespace strategy { namespace buffer Chris@102: { Chris@102: Chris@102: Chris@102: /*! Chris@102: \brief Let the buffer algorithm create buffers with same distances Chris@102: \ingroup strategies Chris@102: \tparam NumericType \tparam_numeric Chris@102: \details This strategy can be used as DistanceStrategy for the buffer algorithm. Chris@102: It can be applied for all geometries. It uses one distance for left and Chris@102: for right. Chris@102: If the distance is negative and used with a (multi)polygon or ring, the Chris@102: geometry will shrink (deflate) instead of expand (inflate). Chris@102: Chris@102: \qbk{ Chris@102: [heading Example] Chris@102: [buffer_distance_symmetric] Chris@102: [heading Output] Chris@102: [$img/strategies/buffer_distance_symmetric.png] Chris@102: [heading See also] Chris@102: \* [link geometry.reference.algorithms.buffer.buffer_7_with_strategies buffer (with strategies)] Chris@102: \* [link geometry.reference.strategies.strategy_buffer_distance_asymmetric distance_asymmetric] Chris@102: } Chris@102: */ Chris@102: template Chris@102: class distance_symmetric Chris@102: { Chris@102: public : Chris@102: //! \brief Constructs the strategy, a distance must be specified Chris@102: //! \param distance The distance (or radius) of the buffer Chris@102: explicit inline distance_symmetric(NumericType const& distance) Chris@102: : m_distance(distance) Chris@102: {} Chris@102: Chris@102: #ifndef DOXYGEN_SHOULD_SKIP_THIS Chris@102: //! Returns the distance-value Chris@102: template Chris@102: inline NumericType apply(Point const& , Point const& , Chris@102: buffer_side_selector ) const Chris@102: { Chris@102: return negative() ? geometry::math::abs(m_distance) : m_distance; Chris@102: } Chris@102: Chris@102: //! Used internally, returns -1 for deflate, 1 for inflate Chris@102: inline int factor() const Chris@102: { Chris@102: return negative() ? -1 : 1; Chris@102: } Chris@102: Chris@102: //! Returns true if distance is negative Chris@102: inline bool negative() const Chris@102: { Chris@102: return m_distance < 0; Chris@102: } Chris@102: Chris@102: //! Returns the max distance distance up to the buffer will reach Chris@102: template Chris@102: inline NumericType max_distance(JoinStrategy const& join_strategy, Chris@102: EndStrategy const& end_strategy) const Chris@102: { Chris@102: boost::ignore_unused(join_strategy, end_strategy); Chris@102: Chris@102: NumericType const dist = geometry::math::abs(m_distance); Chris@102: return (std::max)(join_strategy.max_distance(dist), Chris@102: end_strategy.max_distance(dist)); Chris@102: } Chris@102: Chris@102: Chris@102: //! Returns the distance at which the input is simplified before the buffer process Chris@102: inline NumericType simplify_distance() const Chris@102: { Chris@102: return geometry::math::abs(m_distance) / 1000.0; Chris@102: } Chris@102: #endif // DOXYGEN_SHOULD_SKIP_THIS Chris@102: Chris@102: private : Chris@102: NumericType m_distance; Chris@102: }; Chris@102: Chris@102: Chris@102: }} // namespace strategy::buffer Chris@102: Chris@102: Chris@102: }} // namespace boost::geometry Chris@102: Chris@102: #endif // BOOST_GEOMETRY_STRATEGIES_AGNOSTIC_BUFFER_DISTANCE_SYMMETRIC_HPP