| 1 | #include <iostream>
|
|---|
| 2 | #include <boost/geometry.hpp>
|
|---|
| 3 | #include <boost/geometry/geometries/adapted/c_array.hpp>
|
|---|
| 4 | BOOST_GEOMETRY_REGISTER_C_ARRAY_CS(cs::cartesian)
|
|---|
| 5 | #include <boost/geometry/geometries/polygon.hpp>
|
|---|
| 6 | #include <boost/geometry/algorithms/union.hpp>
|
|---|
| 7 |
|
|---|
| 8 | typedef float real_t;
|
|---|
| 9 | typedef boost::geometry::model::d2::point_xy<real_t> pnt_t;
|
|---|
| 10 | typedef boost::geometry::model::polygon<pnt_t> polygon_t;
|
|---|
| 11 |
|
|---|
| 12 | void print(std::ostream& os, const std::string& name, const polygon_t& poly) {
|
|---|
| 13 | os << name << "={";
|
|---|
| 14 | bool first = true;
|
|---|
| 15 | for(auto& p : boost::geometry::exterior_ring(poly)) {
|
|---|
| 16 | if(!first) {
|
|---|
| 17 | std::cout << ",";
|
|---|
| 18 | }
|
|---|
| 19 | else {
|
|---|
| 20 | first = false;
|
|---|
| 21 | }
|
|---|
| 22 | os << "{" << p.x() << "," << p.y() << "}";
|
|---|
| 23 | }
|
|---|
| 24 | os << "};" << std::endl;
|
|---|
| 25 | }
|
|---|
| 26 |
|
|---|
| 27 | int main(int argc, char** argv)
|
|---|
| 28 | {
|
|---|
| 29 | std::cout.precision(10);
|
|---|
| 30 |
|
|---|
| 31 | real_t data1[][2] = {{0,0}, {-0.3681253195,0.9297761917}, {2.421203136,2.034152031}, {2.789328575,1.104375958}, {0,0}};
|
|---|
| 32 | real_t data2[][2] = {{2.76143527,1.093332171}, {2.076887131,1.822299719}, {4.263789177,3.875944376}, {4.948337555,3.146976948}, {2.76143527,1.093332171}};
|
|---|
| 33 |
|
|---|
| 34 | polygon_t p1, p2;
|
|---|
| 35 | boost::geometry::append(p1, data1);
|
|---|
| 36 | boost::geometry::append(p2, data2);
|
|---|
| 37 |
|
|---|
| 38 | std::vector<polygon_t> output;
|
|---|
| 39 | boost::geometry::union_(p1, p2, output);
|
|---|
| 40 |
|
|---|
| 41 | print(std::cout, "p1", p1);
|
|---|
| 42 | print(std::cout, "p2", p2);
|
|---|
| 43 | print(std::cout, "i", output.front());
|
|---|
| 44 |
|
|---|
| 45 | return 1;
|
|---|
| 46 | }
|
|---|