[buffer] harmonize number of points

This commit is contained in:
Barend Gehrels 2022-11-09 09:39:28 +01:00
parent cf98fb5564
commit 09d135464b
8 changed files with 49 additions and 35 deletions

View File

@ -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 <cstdint>
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

View File

@ -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

View File

@ -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 :

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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>();
calc_t const pi = geometry::math::pi<calc_t>();
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;
};

View File

@ -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<polygon_type, polygon_type>("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<polygon_type, polygon_type>("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<polygon_type, polygon_type>("right_triangle_j3",
right_triangle,
join_round(3), end_flat, distance(1.0), side_strategy, point_strategy,
53.0240);
test_with_custom_strategies<polygon_type, polygon_type>("right_triangle_j4",
right_triangle,
join_round(4), end_flat, distance(1.0), side_strategy, point_strategy,