Xueqing Sun
Xueqing Sun

Reputation: 31

Why boost::geometry::union_ can't give result for axis-aligned-box?

When the polygon is a axis-aligned-box "POLYGON((0 0,1 0,1 1,0 1))", then union_() won't give a correct result, just empty output. Actually, union_() of any polygon should not be empty.

But if you change the polygon green from axis-aligned-box to "POLYGON((2 1.3,2.4 1.7,2.8 1.8))", then there comes out a meaningful output (not empty).

Is it a bug of boost union_()?

Many thanks

int main()
{
    typedef boost::geometry::model::polygon<boost::geometry::model::d2::point_xy<double> > polygon;

    polygon green, blue;

    boost::geometry::read_wkt(
        "POLYGON((0 0,1 0,1 1,0 1))",
        green);

    boost::geometry::read_wkt(
        "POLYGON((2 1.3,2.4 1.7,2.8 1.8))",
        blue);

    std::deque<polygon> output;
    boost::geometry::union_(green, blue, output);

    int i = 0;
    std::cout << "green && blue:" << std::endl;
    BOOST_FOREACH(polygon const& p, output)
    {
        std::cout << i++ << ": " << boost::geometry::area(p) << std::endl;
    }

    return 0;
}

Upvotes: 1

Views: 245

Answers (1)

Xueqing Sun
Xueqing Sun

Reputation: 31

There is a simmilar question about it. The algoritm requires some preconditions. 1) The polygon has to be clockwise. 2) The polygon has bo be closed, i.e. the last point just coincides the first point.

So to correct the issues in the orignial polygon data, call boost::geometry::correct() to make the data meets the rules. And the algorithm wil accept the polygon and gives the correct result.

Why boost::geometry::intersection does not work correct?

Upvotes: 2

Related Questions