Boost logo

Boost Users :

Subject: [Boost-users] [Boost.Polygon] Bug in polygon_set_data, or are my expectations wrong?
From: Patrick J. LoPresti (lopresti_at_[hidden])
Date: 2014-10-09 15:11:37


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 <boost/polygon/polygon.hpp>

#include <iostream>
#include <cstdlib>

namespace bp = boost::polygon;
using namespace bp::operators;

typedef bp::polygon_set_data<int> PolygonSet;
typedef bp::polygon_data<PolygonSet::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));
}


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net