2010-06-05 150 views

回答

0

从您的链接中读取更好,找到doc页面并阅读;特别是gpc_add_contour函数可能是你需要的。该结构gpc_vertex_list具有指向gpc_vertex-S和顶点的数量,并且是必须填写的内容。像


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

的文档是不是太多明确,但可以推断的使用和测试(尝试错误循环)是你的朋友(我不会安装gpc来做它,所以我的代码可能是错误的)。建议的代码片段应该创建一个正方形。其他几个gpc_add_countour与& p相同,但不同的顶点列表可用于创建更复杂的多边形,当然也可以更改vl以在开始时使用更复杂的多边形。如果要将定义的轮廓作为当前(p)多边形中的“孔”,则第三个参数应为1。

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