Buffer (with strategies) Has a Unmentioned Hiden Requirement for Input Polygon
- Dominant language
- C++
- Stars
- 517
- Forks
- 232
- PR merge metrics
- No merged PRs in 30d
Description
Dear Boost Geometry Developers,
First, I’d like to thank you for all the hard work you’ve put into Boost—it’s been invaluable to the community!
I’m new to Boost Geometry and encountered an issue while trying to buffer a polygon. I was following the documentation (https://beta.boost.org/doc/libs/1_82_0/libs/geometry/doc/html/geometry/reference/algorithms/buffer/buffer_7_with_strategies.html), and surprisingly, the example polygon worked as expected, but the polygon I created didn’t.
After some debugging and searching, I realized that the polygons in this related issue (https://github.com/boostorg/geometry/issues/1372) are defined as `using Polygon = bg::model::polygon`. However, the documentation defines the polygon type as `typedef boost::geometry::model::polygon polygon`, which doesn’t specify the orientation of the vertices.
To resolve the issue, I changed the polygon definition to `using polygon = boost::geometry::model::polygon`, ensuring the polygon is defined as counter-clockwise. Alternatively, adjusting the vertex order of my input polygon to counter-clockwise also solved the problem.
It would be very helpful if the buffer function could support both clockwise and counter-clockwise ordered polygons, or if this behavior could be clarified in the documentation. It would greatly assist newcomers like myself.
Here’s my (non-working under 1.87 and 1.82) version of the code for reference:
```
#include
#include
#include
#include
#include
namespace bg = boost::geometry;
int main()
{
using coordinate_type = double;
using point = boost::geometry::model::d2::point_xy;
using polygon = boost::geometry::model::polygon;
// Declare strategies
const double buffer_distance = 1.0;
const int points_per_circle = 16;
boost::geometry::strategy::buffer::distance_symmetric distance_strategy(buffer_distance);
boost::geometry::strategy::buffer::join_round join_strategy(points_per_circle);
boost::geometry::strategy::buffer::end_round end_strategy(points_per_circle);
boost::geometry::strategy::buffer::point_circle circle_strategy(points_per_circle);
boost::geometry::strategy::buffer::side_straight side_strategy;
// Declare output
boost::geometry::model::multi_polygon result;
// Declare a polygon
polygon poly;
boost::geometry::read_wkt("POLYGON((77.1028 50.357,50 50,26.8513 7.1746,77.1028 50.357))", poly);
std::cout << "Poly: " << boost::geometry::wkt(poly) << std::endl;
// Create the buffer of a polygon
boost::geometry::buffer(poly, result,
distance_strategy, side_strategy,
join_strategy, end_strategy, circle_strategy);
std::cout << "Result: " << boost::geometry::wkt(result) << std::endl;
return 0;
}
```
The result is:
```
Poly: POLYGON((77.1028 50.357,50 50,26.8513 7.1746,77.1028 50.357))
Result: MULTIPOLYGON()
```
Contributor guide
Assessment
This issue has not been assessed yet.