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_ASYMMETRIC_HPP Chris@102: #define BOOST_GEOMETRY_STRATEGIES_AGNOSTIC_BUFFER_DISTANCE_ASYMMETRIC_HPP 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 for linestrings be asymmetric 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 (multi)linestrings. It uses a (potentially) different Chris@102: distances for left and for right. This means the (multi)linestrings are Chris@102: interpreted having a direction. Chris@102: Chris@102: \qbk{ Chris@102: [heading Example] Chris@102: [buffer_distance_asymmetric] Chris@102: [heading Output] Chris@102: [$img/strategies/buffer_distance_asymmetric.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_symmetric distance_symmetric] Chris@102: } Chris@102: */ Chris@102: template Chris@102: class distance_asymmetric Chris@102: { Chris@102: public : Chris@102: //! \brief Constructs the strategy, two distances must be specified Chris@102: //! \param left The distance (or radius) of the buffer on the left side Chris@102: //! \param right The distance on the right side Chris@102: distance_asymmetric(NumericType const& left, Chris@102: NumericType const& right) Chris@102: : m_left(left) Chris@102: , m_right(right) Chris@102: {} Chris@102: Chris@102: #ifndef DOXYGEN_SHOULD_SKIP_THIS Chris@102: //! Returns the distance-value for the specified side Chris@102: template Chris@102: inline NumericType apply(Point const& , Point const& , Chris@102: buffer_side_selector side) const Chris@102: { Chris@102: NumericType result = side == buffer_side_left ? m_left : m_right; Chris@102: return negative() ? math::abs(result) : result; 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 both distances are negative Chris@102: inline bool negative() const Chris@102: { Chris@102: return m_left < 0 && m_right < 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 left = geometry::math::abs(m_left); Chris@102: NumericType const right = geometry::math::abs(m_right); Chris@102: NumericType const dist = (std::max)(left, right); Chris@102: return (std::max)(join_strategy.max_distance(dist), Chris@102: end_strategy.max_distance(dist)); 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: NumericType const left = geometry::math::abs(m_left); Chris@102: NumericType const right = geometry::math::abs(m_right); Chris@102: return (std::min)(left, right) / 1000.0; Chris@102: } Chris@102: Chris@102: #endif // DOXYGEN_SHOULD_SKIP_THIS Chris@102: Chris@102: private : Chris@102: NumericType m_left; Chris@102: NumericType m_right; 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_ASYMMETRIC_HPP