| 1 |
|
|---|
| 2 | #include "stdafx.h"
|
|---|
| 3 | #include <vector>
|
|---|
| 4 | #include <boost/polygon/polygon.hpp>
|
|---|
| 5 | using namespace boost::polygon::operators;
|
|---|
| 6 |
|
|---|
| 7 | #define POLYGON_45
|
|---|
| 8 |
|
|---|
| 9 | #ifdef POLYGON_45
|
|---|
| 10 | int points_A_1[] =
|
|---|
| 11 | { // 45 degree polygon
|
|---|
| 12 | -92810838,3618230,
|
|---|
| 13 | -94606872,1822196,
|
|---|
| 14 | -94999302,2214626,
|
|---|
| 15 | -93203268,4010660};
|
|---|
| 16 | int points_A_1_size =4;
|
|---|
| 17 |
|
|---|
| 18 | #else
|
|---|
| 19 | int points_A_1[] =
|
|---|
| 20 | { // arbitrary polygon
|
|---|
| 21 | -92810838,3618230,
|
|---|
| 22 | -94606872,1822196,
|
|---|
| 23 | -94999302,2214625, // 2214626 -> 2214625, near 45 degree edge
|
|---|
| 24 | -93203268,4010660};
|
|---|
| 25 | int points_A_1_size =4;
|
|---|
| 26 |
|
|---|
| 27 | #endif
|
|---|
| 28 |
|
|---|
| 29 | int points_B_1[] =
|
|---|
| 30 | {
|
|---|
| 31 | -94739968,1676908,
|
|---|
| 32 | -94606618,1822450,
|
|---|
| 33 | -94999048,2214880,
|
|---|
| 34 | -95165164,2033778};
|
|---|
| 35 | int points_B_1_size =4;
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 | int
|
|---|
| 39 | main(int argc, char **argv)
|
|---|
| 40 | {
|
|---|
| 41 | typedef boost::polygon::polygon_data<double> Polygon;
|
|---|
| 42 | typedef boost::polygon::point_data<double> Point;
|
|---|
| 43 | typedef boost::polygon::polygon_set_data<double> PolygonSet;
|
|---|
| 44 |
|
|---|
| 45 | std::vector<Point> points;
|
|---|
| 46 |
|
|---|
| 47 | int count = points_A_1_size;
|
|---|
| 48 | for (int i = 0; i < count; ++i) {
|
|---|
| 49 | points.push_back(boost::polygon::construct<Point>(points_A_1[2 * i], points_A_1[2 * i+1]));
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 | Polygon A;
|
|---|
| 53 | A.set(points.begin(), points.end());
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 | points.clear();
|
|---|
| 57 | count = points_B_1_size;
|
|---|
| 58 | for (int i = 0; i < count; ++i) {
|
|---|
| 59 | points.push_back(boost::polygon::construct<Point>(points_B_1[2 * i], points_B_1[2 * i+1]));
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 | Polygon B;
|
|---|
| 63 | B.set(points.begin(), points.end());
|
|---|
| 64 |
|
|---|
| 65 | PolygonSet ps1, ps2, ps3;
|
|---|
| 66 |
|
|---|
| 67 | ps1 += A;
|
|---|
| 68 | ps2 += B;
|
|---|
| 69 | assign(ps3, ps1 + ps2);
|
|---|
| 70 |
|
|---|
| 71 | std::vector<Polygon> polygons;
|
|---|
| 72 | ps3.get(polygons);
|
|---|
| 73 | return 0;
|
|---|
| 74 | }
|
|---|