GPC多边形初始化 [英] GPC Polygon Initialization

查看:221
本文介绍了GPC多边形初始化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是GPC 多边形裁剪的lib 并希望编程方式创建一个多边形。我只看到code如何创建一个从文件。我该怎么办初始化在我的code?


解决方案

  gpc_polygon主题;
INT W = 100,H = 100,verticesCnt = 30;//设置一个gpc_polygon容器中,用随机顶点填充...
subject.num_contours = 1;
subject.hole = 0;
subject.contour =新gpc_vertex_list; //此处即只是一个单一的多边形
subject.contour->为num_vertices = verticesCnt;
subject.contour->顶点=新gpc_vertex [verticesCnt]
对于(i = 0; I< verticesCnt;我++){
    subject.contour [0] .vertex [I]的.x =随机(重量);
    subject.contour [0] .vertex [I] .Y =随机(H);
}//做的东西用在这里,然后... ...gpc_free_polygon(安培;一级学科);

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?

解决方案

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

这篇关于GPC多边形初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆