
HxH wrote:
Help! I wrote this function to load the data point to a boost polygon.
typedef vector<polygon_data<int> > LayoutSet; static void addPolygonData(LayoutSet &sets,int* points,int size){ polygon_data<int> poly_data; vector<point_data<int> > poly_points(size); for(int i=0;i<size;i++) { int x=i*2; int y=x+1;
poly_points[i]=point_data<int>(points[x],points[y]); } poly_data.set(poly_points.begin(),poly_points.end()); sets.push_back(poly_data); } Then I load two sets of points int p1[8]={1200 2400 1200 3600 4000 3600 4000 2400}; int p2[8]={1800 600 1800 4700 3500 4700 3500 600}; LayoutSet group_2; LayoutSet group_1; addPolygonData(group_1,p1,8); addPolygonData(group_1,p2,8); boost::polygon::assign(group_2,group_1[0] & group_1[1]); // Here I do the logic operation & (AND)
vector<point_data<int> > pts; pts.insert(pts.begin(),group_2[0].begin(),group[0].end());
for(size_t i=0;i
Here is the result I get:
6484944,0 3500,600 3500,3600 1800,3600 1800,600 3,1 0,0 6484944,0
It doesn't look correct. It gives me a hard time to fix it. Any suggestions are welcome!!
You are passing 8 into the addPolygonData, but you should pass 4 instead. Inside the loop implemented in addPolygonData you iterate i from 0 to size and multiply i by 2 to index into the array. You are indexing past the end of the array and the polygons you passed to the AND operation contain arbitrary data, which is showing up in the result it seems. Boost.Polygon places no pre-conditions on input polygons. It views input data as a polygon using the positive winding rule and determines the winding based on whichever winding results in a positive area. I don't know what the arbitrary data passed to the AND operation was exactly, but I suspect that the output polygon is actually correct for the given input. I hope that helps! Regards, Luke