Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // Boost.Geometry (aka GGL, Generic Geometry Library)
0002 
0003 // Copyright (c) 2012-2014 Barend Gehrels, Amsterdam, the Netherlands.
0004 
0005 // This file was modified by Oracle on 2018.
0006 // Modifications copyright (c) 2018, Oracle and/or its affiliates.
0007 
0008 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
0009 
0010 // Use, modification and distribution is subject to the Boost Software License,
0011 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0012 // http://www.boost.org/LICENSE_1_0.txt)
0013 
0014 #ifndef BOOST_GEOMETRY_STRATEGIES_CARTESIAN_BUFFER_END_FLAT_HPP
0015 #define BOOST_GEOMETRY_STRATEGIES_CARTESIAN_BUFFER_END_FLAT_HPP
0016 
0017 #include <boost/geometry/core/coordinate_type.hpp>
0018 #include <boost/geometry/strategies/buffer.hpp>
0019 #include <boost/geometry/strategies/tags.hpp>
0020 #include <boost/geometry/strategies/side.hpp>
0021 #include <boost/geometry/util/math.hpp>
0022 #include <boost/geometry/util/select_most_precise.hpp>
0023 
0024 namespace boost { namespace geometry
0025 {
0026 
0027 
0028 namespace strategy { namespace buffer
0029 {
0030 
0031 
0032 /*!
0033 \brief Let the buffer create flat ends
0034 \ingroup strategies
0035 \details This strategy can be used as EndStrategy for the buffer algorithm.
0036     It creates a flat end for each linestring-end. It can be applied
0037     for (multi)linestrings. Also it is applicable for spikes in (multi)polygons.
0038     This strategy is only applicable for Cartesian coordinate systems.
0039 
0040 \qbk{
0041 [heading Example]
0042 [buffer_end_flat]
0043 [heading Output]
0044 [$img/strategies/buffer_end_flat.png]
0045 [heading See also]
0046 \* [link geometry.reference.algorithms.buffer.buffer_7_with_strategies buffer (with strategies)]
0047 \* [link geometry.reference.strategies.strategy_buffer_end_round end_round]
0048 }
0049  */
0050 class end_flat
0051 {
0052 
0053 public :
0054 
0055 #ifndef DOXYGEN_SHOULD_SKIP_THIS
0056     //! Fills output_range with a flat end
0057     template <typename Point, typename DistanceStrategy, typename RangeOut>
0058     inline void apply(Point const& penultimate_point,
0059                 Point const& perp_left_point,
0060                 Point const& ultimate_point,
0061                 Point const& perp_right_point,
0062                 buffer_side_selector side,
0063                 DistanceStrategy const& distance,
0064                 RangeOut& range_out) const
0065     {
0066         auto const dist_left = distance.apply(penultimate_point, ultimate_point, buffer_side_left);
0067         auto const dist_right = distance.apply(penultimate_point, ultimate_point, buffer_side_right);
0068 
0069         bool const reversed =
0070                 (side == buffer_side_left && dist_right < 0 && -dist_right > dist_left)
0071             ||  (side == buffer_side_right && dist_left < 0 && -dist_left > dist_right);
0072 
0073         if (reversed)
0074         {
0075             range_out.push_back(perp_right_point);
0076             range_out.push_back(perp_left_point);
0077         }
0078         else
0079         {
0080             range_out.push_back(perp_left_point);
0081             range_out.push_back(perp_right_point);
0082         }
0083         // Don't add the ultimate_point (endpoint of the linestring).
0084         // The buffer might be generated completely at one side.
0085         // In other cases it does no harm but it is useless
0086     }
0087 
0088     template <typename NumericType>
0089     static inline NumericType max_distance(NumericType const& distance)
0090     {
0091         return distance;
0092     }
0093 
0094     //! Returns the piece_type (flat end)
0095     static inline piece_type get_piece_type()
0096     {
0097         return buffered_flat_end;
0098     }
0099 #endif // DOXYGEN_SHOULD_SKIP_THIS
0100 };
0101 
0102 
0103 }} // namespace strategy::buffer
0104 
0105 }} // namespace boost::geometry
0106 
0107 #endif // BOOST_GEOMETRY_STRATEGIES_CARTESIAN_BUFFER_END_FLAT_HPP