Chris@102: // Boost.Geometry (aka GGL, Generic Geometry Library) Chris@102: Chris@102: // Copyright (c) 2012-2015 Barend Gehrels, Amsterdam, the Netherlands. Chris@102: Chris@102: // This file was modified by Oracle on 2015. Chris@102: // Modifications copyright (c) 2015, Oracle and/or its affiliates. Chris@102: Chris@102: // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle 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_CARTESIAN_BUFFER_POINT_CIRCLE_HPP Chris@102: #define BOOST_GEOMETRY_STRATEGIES_CARTESIAN_BUFFER_POINT_CIRCLE_HPP Chris@102: Chris@102: #include Chris@102: Chris@102: #include Chris@102: Chris@102: #include Chris@102: 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: \brief Create a circular buffer around a point Chris@102: \ingroup strategies Chris@102: \details This strategy can be used as PointStrategy for the buffer algorithm. Chris@102: It creates a circular buffer around a point. It can be applied Chris@102: for points and multi_points, but also for a linestring (if it is degenerate, Chris@102: so consisting of only one point) and for polygons (if it is degenerate). Chris@102: This strategy is only applicable for Cartesian coordinate systems. Chris@102: Chris@102: \qbk{ Chris@102: [heading Example] Chris@102: [buffer_point_circle] Chris@102: [heading Output] Chris@102: [$img/strategies/buffer_point_circle.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_point_square point_square] Chris@102: } Chris@102: */ Chris@102: class point_circle Chris@102: { Chris@102: public : Chris@102: //! \brief Constructs the strategy Chris@102: //! \param count number of points for the created circle (if count Chris@102: //! is smaller than 3, count is internally set to 3) Chris@102: explicit point_circle(std::size_t count = 90) Chris@102: : m_count((count < 3u) ? 3u : count) Chris@102: {} Chris@102: Chris@102: #ifndef DOXYGEN_SHOULD_SKIP_THIS Chris@102: //! Fills output_range with a circle around point using distance_strategy Chris@102: template Chris@102: < Chris@102: typename Point, Chris@102: typename OutputRange, Chris@102: typename DistanceStrategy Chris@102: > Chris@102: inline void apply(Point const& point, Chris@102: DistanceStrategy const& distance_strategy, Chris@102: OutputRange& output_range) const Chris@102: { Chris@102: typedef typename boost::range_value::type output_point_type; Chris@102: Chris@102: typedef typename geometry::select_most_precise Chris@102: < Chris@102: typename geometry::select_most_precise Chris@102: < Chris@102: typename geometry::coordinate_type::type, Chris@102: typename geometry::coordinate_type::type Chris@102: >::type, Chris@102: double Chris@102: >::type promoted_type; Chris@102: Chris@102: promoted_type const buffer_distance = distance_strategy.apply(point, point, Chris@102: strategy::buffer::buffer_side_left); Chris@102: Chris@102: promoted_type const two = 2.0; Chris@102: promoted_type const two_pi = two * geometry::math::pi(); Chris@102: Chris@102: promoted_type const diff = two_pi / promoted_type(m_count); Chris@102: promoted_type a = 0; Chris@102: Chris@102: for (std::size_t i = 0; i < m_count; i++, a -= diff) Chris@102: { Chris@102: output_point_type p; Chris@102: set<0>(p, get<0>(point) + buffer_distance * cos(a)); Chris@102: set<1>(p, get<1>(point) + buffer_distance * sin(a)); Chris@102: output_range.push_back(p); Chris@102: } Chris@102: Chris@102: // Close it: Chris@102: output_range.push_back(output_range.front()); Chris@102: } Chris@102: #endif // DOXYGEN_SHOULD_SKIP_THIS Chris@102: Chris@102: private : Chris@102: std::size_t m_count; Chris@102: }; Chris@102: Chris@102: Chris@102: }} // namespace strategy::buffer Chris@102: Chris@102: }} // namespace boost::geometry Chris@102: Chris@102: #endif // BOOST_GEOMETRY_STRATEGIES_CARTESIAN_BUFFER_POINT_CIRCLE_HPP