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-2015 Barend Gehrels, Amsterdam, the Netherlands.
0004 
0005 // This file was modified by Oracle on 2015, 2018.
0006 // Modifications copyright (c) 2015, 2018, Oracle and/or its affiliates.
0007 
0008 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
0009 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
0010 
0011 // Use, modification and distribution is subject to the Boost Software License,
0012 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0013 // http://www.boost.org/LICENSE_1_0.txt)
0014 
0015 #ifndef BOOST_GEOMETRY_STRATEGIES_CARTESIAN_BUFFER_POINT_CIRCLE_HPP
0016 #define BOOST_GEOMETRY_STRATEGIES_CARTESIAN_BUFFER_POINT_CIRCLE_HPP
0017 
0018 #include <cstddef>
0019 
0020 #include <boost/range/value_type.hpp>
0021 
0022 #include <boost/geometry/core/access.hpp>
0023 #include <boost/geometry/core/coordinate_type.hpp>
0024 
0025 #include <boost/geometry/strategies/buffer.hpp>
0026 
0027 #include <boost/geometry/util/math.hpp>
0028 #include <boost/geometry/util/select_most_precise.hpp>
0029 
0030 namespace boost { namespace geometry
0031 {
0032 
0033 namespace strategy { namespace buffer
0034 {
0035 
0036 /*!
0037 \brief Create a circular buffer around a point
0038 \ingroup strategies
0039 \details This strategy can be used as PointStrategy for the buffer algorithm.
0040     It creates a circular buffer around a point. It can be applied
0041     for points and multi_points, but also for a linestring (if it is degenerate,
0042     so consisting of only one point) and for polygons (if it is degenerate).
0043     This strategy is only applicable for Cartesian coordinate systems.
0044 
0045 \qbk{
0046 [heading Example]
0047 [buffer_point_circle]
0048 [heading Output]
0049 [$img/strategies/buffer_point_circle.png]
0050 [heading See also]
0051 \* [link geometry.reference.algorithms.buffer.buffer_7_with_strategies buffer (with strategies)]
0052 \* [link geometry.reference.strategies.strategy_buffer_point_square point_square]
0053 \* [link geometry.reference.strategies.strategy_buffer_geographic_point_circle geographic_point_circle]
0054 }
0055  */
0056 class point_circle
0057 {
0058 public :
0059     //! \brief Constructs the strategy
0060     //! \param count Number of points (minimum 3) for the created circle
0061     explicit point_circle(std::size_t count = default_points_per_circle)
0062         : m_count(get_point_count_for_circle(count))
0063     {}
0064 
0065 #ifndef DOXYGEN_SHOULD_SKIP_THIS
0066     //! Fills output_range with a circle around point using distance_strategy
0067     template
0068     <
0069         typename Point,
0070         typename OutputRange,
0071         typename DistanceStrategy
0072     >
0073     inline void apply(Point const& point,
0074                 DistanceStrategy const& distance_strategy,
0075                 OutputRange& output_range) const
0076     {
0077         typedef typename boost::range_value<OutputRange>::type output_point_type;
0078 
0079         typedef typename geometry::select_most_precise
0080             <
0081                 typename geometry::select_most_precise
0082                     <
0083                         typename geometry::coordinate_type<Point>::type,
0084                         typename geometry::coordinate_type<output_point_type>::type
0085                     >::type,
0086                 double
0087             >::type promoted_type;
0088 
0089         promoted_type const buffer_distance = distance_strategy.apply(point, point,
0090                         strategy::buffer::buffer_side_left);
0091 
0092         promoted_type const two_pi = geometry::math::two_pi<promoted_type>();
0093 
0094         promoted_type const diff = two_pi / promoted_type(m_count);
0095         promoted_type a = 0;
0096 
0097         for (std::size_t i = 0; i < m_count; i++, a -= diff)
0098         {
0099             output_point_type p;
0100             set<0>(p, get<0>(point) + buffer_distance * cos(a));
0101             set<1>(p, get<1>(point) + buffer_distance * sin(a));
0102             output_range.push_back(p);
0103         }
0104 
0105         // Close it:
0106         output_range.push_back(output_range.front());
0107     }
0108 #endif // DOXYGEN_SHOULD_SKIP_THIS
0109 
0110 private :
0111     std::size_t m_count;
0112 };
0113 
0114 
0115 }} // namespace strategy::buffer
0116 
0117 }} // namespace boost::geometry
0118 
0119 #endif // BOOST_GEOMETRY_STRATEGIES_CARTESIAN_BUFFER_POINT_CIRCLE_HPP