#include #include #include namespace bp = boost::polygon; using namespace bp::operators; typedef bp::polygon_set_data PolygonSet; typedef bp::polygon_data Polygon; typedef bp::polygon_traits::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; // Boost.Polygon says the area is 30. That is because its internal // representation is wrong, as you can confirm by manually // examining the result of get() or get_trapezoids(). std::cout << "poly1 area == " << area(poly1) << "\n"; 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)); }