I have just submitted a bug report:
https://svn.boost.org/trac/boost/ticket/10642
...but I am wondering if the bug is in my understanding rather than in
Boost.Polygon.
The test case is very simple, so I am appending it to this message. My
question is, should I expect polygon_set_data<int> to scramble such a
simple figure? It almost looks like some (but not all) of the
coordinates are being snapped to multiples of 2. Or something.
Note that doubling all of the coordinates avoids the bug. Assuming it
is a bug (?)
Thanks!
- Pat
#include
#include <iostream>
#include <cstdlib>
namespace bp = boost::polygon;
using namespace bp::operators;
typedef bp::polygon_set_data<int> PolygonSet;
typedef bp::polygon_dataPolygonSet::coordinate_type Polygon;
typedef bp::polygon_traits<Polygon>::point_type Point;
int
main(int argc, char *argv[])
{
// Small figure with a little hole. Area should be 32.
const Point points[] = {
Point(0,0),
Point(6,0),
Point(6,4),
Point(4,6),
Point(0,6),
Point(0,0),
Point(4,4),
Point(5,4)
};
Polygon poly1(&points[0], &points[sizeof(points)/sizeof(points[0])]);
PolygonSet ps1;
ps1 += poly1;
std::cout << "poly1 area == " << area(poly1) << "\n";
// Boost.Polygon says the area of ps1 is 30. That is because its internal
// representation is wrong, as you can confirm by manually
// examining the result of ps1.get() or ps1.get_trapezoids().
std::cout << "ps1 area == " << area(ps1) << "\n";
// Doubling the coordinates avoids the bug.
Polygon poly2(poly1);
scale_up(poly2, 2);
PolygonSet ps2;
ps2 += poly2;
std::cout << "poly2 area == " << area(poly2) << "\n";
std::cout << "ps2 area == " << area(ps2) << "\n";
assert(area(poly2) == area(ps2));
assert(area(poly1) == area(ps1));
}