|
Geometry : |
Subject: [ggl] Unioning many polygons
From: John Swensen (jpswensen)
Date: 2011-10-08 16:21:57
I am finally getting back to my iphone game that will use Boost.Geometry. I have all the splitting and mirroring of polygons working, but am having trouble unioning polygons back together. I don't quite get why the results of the boost::geometry::union_ operation are placed in a vector.
I would like to do something like the following
// Split the polygon along the line
std::vector<polygon_2d> splits = splitPolygon (line, a);
std::vector<polygon_2d> mirrors;
// Mirror every polygon
BOOST_FOREACH(polygon_2d poly, splits)
{
polygon_2d tmp = mirrorPolygon (line, poly);
mirrors.push_back(tmp);
}
// Union all the split polygons and their mirrors together
std::vector<polygon_2d> unionPoly;
BOOST_FOREACH(polygon_2d poly, splits)
{
boost::geometry::union_ (unionPoly, poly, unionPoly);
}
BOOST_FOREACH(polygon_2d poly, mirrors)
{
boost::geometry::union_ (unionPoly, poly, unionPoly);
}
Of course this doesn't work because union_ takes polygon_2d in my case, not a std::vector<polygon_2d> as its first argument.
What is the correct way of unioning a bunch of polygons together?
John
Geometry list run by mateusz at loskot.net