GPC Polygon Initialization

I am using the GPC Polygon Clipping lib and want to create a polygon programmatically. I see only the code to create one of the file. How can I initialize in my code?

+3
source share
2 answers

Read better from your link, find the doc and read; in particular, the function you gpc_add_contourmost likely need. The gpc_vertex_list line contains a pointer to gpc_vertex-s and the number of vertices, and this is what you should fill. for instance


gpc_polygon p = {0, NULL, NULL}; // "void" polygon
gpc_vertex v[] = { {0.0, 0.0}, {10.0, 0.}, {10.0, 10.10}, {0.0, 10.0} };
gpc_vertex_list vl = {
  4, v
};
//...
gpc_add_contour(&p, &vl, 0);

, , (try-error loops) - ( gpc, , ). . gpc_add_countour & p, , , , vl , . 1, , "" (p) .

0
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);
0

Source: https://habr.com/ru/post/1748672/


All Articles