#include #include #include #include #include using namespace ggl; typedef point_xy point_2di; typedef linestring linestring_2di; typedef linear_ring ring_2di; typedef polygon polygon_2di; typedef box box_2di; typedef segment segment_2di; typedef multi_polygon polygon_set; int main() { using std::cout; using std::endl; // Create two polygons that touch on one edge polygon_2di poly1; { const int coor[][2] = { {0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0} }; assign(poly1, coor); } polygon_2di poly2; { const int coor[][2] = { {1, 0}, {2, 0}, {2, 1}, {1, 1}, {1, 0} }; assign(poly2, coor); } polygon_set ps1; union_inserter(poly1, poly2, std::back_inserter(ps1)); cout << "Union of poly1 and poly2:" << endl; for(polygon_set::const_iterator it = ps1.begin(); it != ps1.end(); ++it) cout << dsv(*it) << endl; // Make a third polygon that *should* equal the union of the // previous two polygons polygon_2di poly3; { const int coor[][2] = { {0, 0}, {2, 0}, {2, 1}, {0, 1}, {0, 0} }; assign(poly3, coor); } polygon_set ps2; ps2.push_back(poly3); // Now test for equality cout << "ps1 equals ps2?" << (equals(ps1, ps2) ? "YES" : "NO") << endl; return 0; }