I am using the GPC Polygon Clipping lib and want to create a polygon programatically. I only see code for how to create one from a file. How can I do the initialization in my code?
A:
ShinTakezou
2010-06-05 17:09:08
A:
gpc_polygon subject;
int w = 100, h = 100, verticesCnt = 30;
//setup a gpc_polygon container and fill it with random vertices ...
subject.num_contours = 1;
subject.hole = 0;
subject.contour = new gpc_vertex_list; //ie just a single polygon here
subject.contour->num_vertices = verticesCnt;
subject.contour->vertex = new gpc_vertex [verticesCnt];
for (i = 0; i < verticesCnt; i++){
subject.contour[0].vertex[i].x = random(w);
subject.contour[0].vertex[i].y = random(h);
}
//do stuff with it here, then ...
gpc_free_polygon(&subject);
Angus Johnson
2010-06-06 05:03:25