commit c245dc6d19d6dcf3bfd032c9a8c48c9548b75add
parent 0b3025a561923505db17901430ade2df00976a67
Author: vaplv <vaplv@free.fr>
Date: Sun, 21 Sep 2014 18:47:40 +0200
Restore the polygon state at the end of triangulate function
Diffstat:
1 file changed, 14 insertions(+), 3 deletions(-)
diff --git a/src/polygon.c b/src/polygon.c
@@ -296,14 +296,15 @@ error:
enum polygon_result
polygon_triangulate
(struct polygon* poly,
- const uint32_t** vertex_indices)
+ const uint32_t** indices,
+ uint32_t* nindices)
{
struct vertex_node* nodes;
uint32_t ivert, inode;
float normal_convex[3], normal[3];
enum polygon_result res = POLYGON_OK;
- if(!poly || !vertex_indices) {
+ if(!poly || !indices || !nindices) {
res = POLYGON_BAD_ARGUMENT;
goto error;
}
@@ -376,7 +377,17 @@ polygon_triangulate
}
exit:
- /* TODO restore the linked list */
+ if(indices && nindices) {
+ *nindices = (uint32_t)darray_u32_size_get(&poly->triangle_ids);
+ *indices = *nindices ? darray_u32_cdata_get(&poly->triangle_ids) : NULL;
+ }
+ if(poly && poly->nvertices) { /* Restore the linked list */
+ poly->vertices = 0;
+ FOR_EACH(inode, 1, poly->nvertices) {
+ nodes[inode].prev = inode == 0 ? poly->nvertices - 1 : inode - 1;
+ nodes[inode].next = inode == poly->nvertices - 1 ? 0 : inode + 1;
+ }
+ }
return res;
error:
if(poly)