diff --git a/include/boost/geometry/strategies/buffer.hpp b/include/boost/geometry/strategies/buffer.hpp index 923009862..b03c9bc62 100644 --- a/include/boost/geometry/strategies/buffer.hpp +++ b/include/boost/geometry/strategies/buffer.hpp @@ -6,8 +6,10 @@ // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) -#ifndef BOOST_GEOMETRY_STRATEGIES_CARTESIAN_BUFFER_HPP -#define BOOST_GEOMETRY_STRATEGIES_CARTESIAN_BUFFER_HPP +#ifndef BOOST_GEOMETRY_STRATEGIES_BUFFER_HPP +#define BOOST_GEOMETRY_STRATEGIES_BUFFER_HPP + +#include namespace boost { namespace geometry { @@ -55,6 +57,27 @@ namespace strategy { namespace buffer */ enum buffer_side_selector { buffer_side_left, buffer_side_right }; +// Default number of points in a circle +constexpr std::size_t default_points_per_circle = 90u; + +inline std::size_t get_point_count_for_join(std::size_t count) +{ + std::size_t const min_count = 4u; + return count > min_count ? count : min_count; +} + +inline std::size_t get_point_count_for_end(std::size_t count) +{ + std::size_t const min_count = 4u; + return count > min_count ? count : min_count; +} + +inline std::size_t get_point_count_for_circle(std::size_t count) +{ + std::size_t const min_count = 3u; + return count > min_count ? count : min_count; +} + /*! \brief Enumerates types of pieces (parts of buffer) around geometries \ingroup enum @@ -101,4 +124,4 @@ enum result_code }} // namespace boost::geometry -#endif // BOOST_GEOMETRY_STRATEGIES_CARTESIAN_BUFFER_HPP +#endif // BOOST_GEOMETRY_STRATEGIES_BUFFER_HPP diff --git a/include/boost/geometry/strategies/cartesian/buffer_end_round.hpp b/include/boost/geometry/strategies/cartesian/buffer_end_round.hpp index abf055a67..6cee14bca 100644 --- a/include/boost/geometry/strategies/cartesian/buffer_end_round.hpp +++ b/include/boost/geometry/strategies/cartesian/buffer_end_round.hpp @@ -98,10 +98,9 @@ private : public : //! \brief Constructs the strategy - //! \param points_per_circle points which would be used for a full circle - //! (if points_per_circle is smaller than 4, it is internally set to 4) - explicit inline end_round(std::size_t points_per_circle = 90) - : m_points_per_circle((points_per_circle < 4u) ? 4u : points_per_circle) + //! \param points_per_circle Number of points (minimum 4) that would be used for a full circle + explicit inline end_round(std::size_t points_per_circle = default_points_per_circle) + : m_points_per_circle(get_point_count_for_end(points_per_circle)) {} #ifndef DOXYGEN_SHOULD_SKIP_THIS diff --git a/include/boost/geometry/strategies/cartesian/buffer_join_round.hpp b/include/boost/geometry/strategies/cartesian/buffer_join_round.hpp index 309fedd56..c5918300b 100644 --- a/include/boost/geometry/strategies/cartesian/buffer_join_round.hpp +++ b/include/boost/geometry/strategies/cartesian/buffer_join_round.hpp @@ -58,9 +58,9 @@ class join_round public : //! \brief Constructs the strategy - //! \param points_per_circle points which would be used for a full circle - explicit inline join_round(std::size_t points_per_circle = 90) - : m_points_per_circle(points_per_circle) + //! \param points_per_circle Number of points (minimum 4) that would be used for a full circle + explicit inline join_round(std::size_t points_per_circle = default_points_per_circle) + : m_points_per_circle(get_point_count_for_join(points_per_circle)) {} private : diff --git a/include/boost/geometry/strategies/cartesian/buffer_point_circle.hpp b/include/boost/geometry/strategies/cartesian/buffer_point_circle.hpp index c341e3ca3..b6fc0707b 100644 --- a/include/boost/geometry/strategies/cartesian/buffer_point_circle.hpp +++ b/include/boost/geometry/strategies/cartesian/buffer_point_circle.hpp @@ -57,10 +57,9 @@ class point_circle { public : //! \brief Constructs the strategy - //! \param count number of points for the created circle (if count - //! is smaller than 3, count is internally set to 3) - explicit point_circle(std::size_t count = 90) - : m_count((count < 3u) ? 3u : count) + //! \param count Number of points (minimum 3) for the created circle + explicit point_circle(std::size_t count = default_points_per_circle) + : m_count(get_point_count_for_circle(count)) {} #ifndef DOXYGEN_SHOULD_SKIP_THIS diff --git a/include/boost/geometry/strategies/geographic/buffer_end_round.hpp b/include/boost/geometry/strategies/geographic/buffer_end_round.hpp index bb8730e25..07b8f55db 100644 --- a/include/boost/geometry/strategies/geographic/buffer_end_round.hpp +++ b/include/boost/geometry/strategies/geographic/buffer_end_round.hpp @@ -38,10 +38,9 @@ class geographic_end_round public : //! \brief Constructs the strategy - //! \param points_per_circle Number of points which would be used for a full circle - //! (if points_per_circle is smaller than 4, it is internally set to 4) - explicit inline geographic_end_round(std::size_t points_per_circle = 90) - : m_points_per_circle((points_per_circle < 4u) ? 4u : points_per_circle) + //! \param points_per_circle Number of points (minimum 4) that would be used for a full circle + explicit inline geographic_end_round(std::size_t points_per_circle = default_points_per_circle) + : m_points_per_circle(get_point_count_for_end(points_per_circle)) {} #ifndef DOXYGEN_SHOULD_SKIP_THIS diff --git a/include/boost/geometry/strategies/geographic/buffer_join_round.hpp b/include/boost/geometry/strategies/geographic/buffer_join_round.hpp index 87ae8db97..aec45367b 100644 --- a/include/boost/geometry/strategies/geographic/buffer_join_round.hpp +++ b/include/boost/geometry/strategies/geographic/buffer_join_round.hpp @@ -38,10 +38,9 @@ class geographic_join_round public : //! \brief Constructs the strategy - //! \param points_per_circle Number of points which would be used for a full circle - //! (if points_per_circle is smaller than 4, it is internally set to 4) - explicit inline geographic_join_round(std::size_t points_per_circle = 90) - : m_points_per_circle((points_per_circle < 4u) ? 4u : points_per_circle) + //! \param points_per_circle Number of points (minimum 4) that would be used for a full circle + explicit inline geographic_join_round(std::size_t points_per_circle = default_points_per_circle) + : m_points_per_circle(get_point_count_for_join(points_per_circle)) {} #ifndef DOXYGEN_SHOULD_SKIP_THIS diff --git a/include/boost/geometry/strategies/geographic/buffer_point_circle.hpp b/include/boost/geometry/strategies/geographic/buffer_point_circle.hpp index 619ca2b1a..137ce5d7e 100644 --- a/include/boost/geometry/strategies/geographic/buffer_point_circle.hpp +++ b/include/boost/geometry/strategies/geographic/buffer_point_circle.hpp @@ -61,10 +61,9 @@ class geographic_point_circle public : //! \brief Constructs the strategy - //! \param points_per_circle Number of points for a full circle - //! (if points_per_circle is smaller than 3, it is internally set to 3) - explicit geographic_point_circle(std::size_t points_per_circle = 90) - : m_points_per_circle((points_per_circle < 3u) ? 3u : points_per_circle) + //! \param count Number of points (minimum 3) for the created circle + explicit geographic_point_circle(std::size_t count = default_points_per_circle) + : m_count(get_point_count_for_circle(count)) {} #ifndef DOXYGEN_SHOULD_SKIP_THIS @@ -97,10 +96,10 @@ public : calc_t const two_pi = geometry::math::two_pi(); calc_t const pi = geometry::math::pi(); - calc_t const diff = two_pi / calc_t(m_points_per_circle); + calc_t const diff = two_pi / calc_t(m_count); calc_t angle = -pi; - for (std::size_t i = 0; i < m_points_per_circle; i++, angle += diff) + for (std::size_t i = 0; i < m_count; i++, angle += diff) { // If angle is zero, shift angle a tiny bit to avoid spikes. calc_t const eps = angle == 0 ? 1.0e-10 : 0.0; @@ -116,7 +115,7 @@ public : #endif // DOXYGEN_SHOULD_SKIP_THIS private : - std::size_t m_points_per_circle; + std::size_t m_count; Spheroid m_spheroid; }; diff --git a/test/algorithms/buffer/buffer_polygon.cpp b/test/algorithms/buffer/buffer_polygon.cpp index 89a4fb218..9a671016a 100644 --- a/test/algorithms/buffer/buffer_polygon.cpp +++ b/test/algorithms/buffer/buffer_polygon.cpp @@ -715,11 +715,11 @@ void test_all() sharp_triangle, join_round(12), end_flat, distance(1.0), side_strategy, point_strategy, 29.1604); - // Test very various number of points (min is 3) + // Test very various number of points (min is 4) test_with_custom_strategies("sharp_triangle_j2", sharp_triangle, join_round(2), end_flat, distance(1.0), side_strategy, point_strategy, - 27.2399); + 28.6161); test_with_custom_strategies("sharp_triangle_j5", sharp_triangle, join_round(5), end_flat, distance(1.0), side_strategy, point_strategy, @@ -758,10 +758,6 @@ void test_all() // Right triangles, testing both points around sharp corner as well as points // around right corners in join_round strategy - test_with_custom_strategies("right_triangle_j3", - right_triangle, - join_round(3), end_flat, distance(1.0), side_strategy, point_strategy, - 53.0240); test_with_custom_strategies("right_triangle_j4", right_triangle, join_round(4), end_flat, distance(1.0), side_strategy, point_strategy,