commit b71a1495de66feba899a88a76b8a6ed8c9b8f75f
parent 73c5dae8f495a22dba46b74997561fe63e092ce5
Author: vaplv <vaplv@free.fr>
Date: Fri, 3 Oct 2014 15:53:21 +0200
Take into account the the res macros renaming
Diffstat:
3 files changed, 93 insertions(+), 93 deletions(-)
diff --git a/src/polygon.c b/src/polygon.c
@@ -177,16 +177,16 @@ polygon_create(struct mem_allocator* allocator, struct polygon** out_polygon)
{
struct polygon* poly = NULL;
struct mem_allocator* mem_allocator;
- res_T res = R_OK;
+ res_T res = RES_OK;
if(!out_polygon) {
- res = R_BAD_ARG;
+ res = RES_BAD_ARG;
goto error;
}
mem_allocator = allocator ? allocator : &mem_default_allocator;
poly = MEM_CALLOC(mem_allocator, 1, sizeof(struct polygon));
if(!poly) {
- res = R_MEM_ERR;
+ res = RES_MEM_ERR;
goto error;
}
poly->allocator = mem_allocator;
@@ -213,28 +213,28 @@ error:
res_T
polygon_ref_get(struct polygon* polygon)
{
- if(!polygon) return R_BAD_ARG;
+ if(!polygon) return RES_BAD_ARG;
ref_get(&polygon->ref);
- return R_OK;
+ return RES_OK;
}
res_T
polygon_ref_put(struct polygon* polygon)
{
- if(!polygon) return R_BAD_ARG;
+ if(!polygon) return RES_BAD_ARG;
ref_put(&polygon->ref, release_polygon);
- return R_OK;
+ return RES_OK;
}
res_T
polygon_clear(struct polygon* poly)
{
- if(!poly) return R_BAD_ARG;
+ if(!poly) return RES_BAD_ARG;
darray_vertex_node_clear(&poly->pool);
htable_u32_clear(&poly->vertices_concave);
poly->vertices = UINT32_MAX;
poly->nvertices = 0;
- return R_OK;
+ return RES_OK;
}
res_T
@@ -243,10 +243,10 @@ polygon_vertex_add(struct polygon* poly, const float pos[3])
struct vertex_node* nodes;
struct vertex_node* node_free;
uint32_t inode_free;
- res_T res = R_OK;
+ res_T res = RES_OK;
if(!poly || !pos) {
- res = R_BAD_ARG;
+ res = RES_BAD_ARG;
goto error;
}
@@ -275,7 +275,7 @@ polygon_vertex_add(struct polygon* poly, const float pos[3])
/* Alloc a new vertex node */
inode_free = (uint32_t)darray_vertex_node_size_get(&poly->pool);
res = darray_vertex_node_resize(&poly->pool, inode_free + 1);
- if(res != R_OK)
+ if(res != RES_OK)
goto error;
node_free = darray_vertex_node_data_get(&poly->pool) + inode_free;
@@ -303,9 +303,9 @@ error:
res_T
polygon_vertices_count_get(const struct polygon* poly, uint32_t* nvertices)
{
- if(!poly || !nvertices) return R_BAD_ARG;
+ if(!poly || !nvertices) return RES_BAD_ARG;
*nvertices = poly->nvertices;
- return R_OK;
+ return RES_OK;
}
res_T
@@ -314,10 +314,10 @@ polygon_vertex_get
{
const struct vertex_node* node;
if(!poly || !pos || ivertex >= poly->nvertices)
- return R_BAD_ARG;
+ return RES_BAD_ARG;
node = darray_vertex_node_cdata_get(&poly->pool) + ivertex;
f3_set(pos, node->pos);
- return R_OK;
+ return RES_OK;
}
res_T
@@ -329,10 +329,10 @@ polygon_triangulate
struct vertex_node* nodes;
uint32_t ivert, inode;
float normal_convex[3], normal[3];
- res_T res = R_OK;
+ res_T res = RES_OK;
if(!poly || !indices || !nindices) {
- res = R_BAD_ARG;
+ res = RES_BAD_ARG;
goto error;
}
@@ -345,7 +345,7 @@ polygon_triangulate
if(poly->nvertices == 3) { /* Already a triangle */
FOR_EACH(ivert, 0, 3) {
res = darray_u32_push_back(&poly->triangle_ids, &ivert);
- if(res != R_OK)
+ if(res != RES_OK)
goto error;
}
goto exit;
@@ -361,7 +361,7 @@ polygon_triangulate
if(f3_dot(normal_convex, normal) <= 0.f) {
const char dummy = 1;
res = htable_u32_set(&poly->vertices_concave, &inode, &dummy);
- if(res != R_OK)
+ if(res != RES_OK)
goto error;
}
}
@@ -379,9 +379,9 @@ polygon_triangulate
uint32_t inode_prev;
/* Register the {prev.prev, prev, cur} triangle */
- if(R_OK != (res = darray_u32_push_back(&poly->triangle_ids, &iv0))
- || R_OK != (res = darray_u32_push_back(&poly->triangle_ids, &iv1))
- || R_OK != (res = darray_u32_push_back(&poly->triangle_ids, &iv2)))
+ if(RES_OK != (res = darray_u32_push_back(&poly->triangle_ids, &iv0))
+ || RES_OK != (res = darray_u32_push_back(&poly->triangle_ids, &iv1))
+ || RES_OK != (res = darray_u32_push_back(&poly->triangle_ids, &iv2)))
goto error;
/* Cut the ear by removing `prev' from the node list */
diff --git a/src/polygon.h b/src/polygon.h
@@ -27,7 +27,7 @@
#endif
#ifndef NDEBUG
- #define POLYGON(Func) ASSERT(polygon_##Func == R_OK)
+ #define POLYGON(Func) ASSERT(polygon_##Func == RES_OK)
#else
#define POLYGON(Func) polygon_##Func
#endif
diff --git a/src/test_polygon.c b/src/test_polygon.c
@@ -44,9 +44,9 @@ check_triangulation
float e0[3], e1[3], N[3];
float v0[3], v1[3], v2[3];
float len;
- CHECK(polygon_vertex_get(poly, tri[0], v0), R_OK);
- CHECK(polygon_vertex_get(poly, tri[1], v1), R_OK);
- CHECK(polygon_vertex_get(poly, tri[2], v2), R_OK);
+ CHECK(polygon_vertex_get(poly, tri[0], v0), RES_OK);
+ CHECK(polygon_vertex_get(poly, tri[1], v1), RES_OK);
+ CHECK(polygon_vertex_get(poly, tri[2], v2), RES_OK);
/* Compute the triangle area and add it to the overall polygon area */
f3_sub(e0, v1, v0);
f3_sub(e1, v2, v0);
@@ -108,134 +108,134 @@ main(int argc, char** argv)
mem_init_proxy_allocator(&allocator_proxy, &mem_default_allocator);
- CHECK(polygon_create(NULL, NULL), R_BAD_ARG);
- CHECK(polygon_create(&allocator_proxy, NULL), R_BAD_ARG);
- CHECK(polygon_create(NULL, &poly), R_OK);
+ CHECK(polygon_create(NULL, NULL), RES_BAD_ARG);
+ CHECK(polygon_create(&allocator_proxy, NULL), RES_BAD_ARG);
+ CHECK(polygon_create(NULL, &poly), RES_OK);
- CHECK(polygon_ref_get(NULL), R_BAD_ARG);
- CHECK(polygon_ref_get(poly), R_OK);
- CHECK(polygon_ref_put(NULL), R_BAD_ARG);
- CHECK(polygon_ref_put(poly), R_OK);
- CHECK(polygon_ref_put(poly), R_OK);
+ CHECK(polygon_ref_get(NULL), RES_BAD_ARG);
+ CHECK(polygon_ref_get(poly), RES_OK);
+ CHECK(polygon_ref_put(NULL), RES_BAD_ARG);
+ CHECK(polygon_ref_put(poly), RES_OK);
+ CHECK(polygon_ref_put(poly), RES_OK);
- CHECK(polygon_create(&allocator_proxy, &poly), R_OK);
+ CHECK(polygon_create(&allocator_proxy, &poly), RES_OK);
- CHECK(polygon_vertices_count_get(NULL, NULL), R_BAD_ARG);
- CHECK(polygon_vertices_count_get(poly, NULL), R_BAD_ARG);
- CHECK(polygon_vertices_count_get(NULL, &nvertices), R_BAD_ARG);
- CHECK(polygon_vertices_count_get(poly, &nvertices), R_OK);
+ CHECK(polygon_vertices_count_get(NULL, NULL), RES_BAD_ARG);
+ CHECK(polygon_vertices_count_get(poly, NULL), RES_BAD_ARG);
+ CHECK(polygon_vertices_count_get(NULL, &nvertices), RES_BAD_ARG);
+ CHECK(polygon_vertices_count_get(poly, &nvertices), RES_OK);
CHECK(nvertices, 0);
- CHECK(polygon_vertex_add(NULL, NULL), R_BAD_ARG);
- CHECK(polygon_vertex_add(poly, NULL), R_BAD_ARG);
- CHECK(polygon_vertex_add(NULL, vertices + 3), R_BAD_ARG);
- CHECK(polygon_vertex_add(poly, vertices + 3), R_OK);
+ CHECK(polygon_vertex_add(NULL, NULL), RES_BAD_ARG);
+ CHECK(polygon_vertex_add(poly, NULL), RES_BAD_ARG);
+ CHECK(polygon_vertex_add(NULL, vertices + 3), RES_BAD_ARG);
+ CHECK(polygon_vertex_add(poly, vertices + 3), RES_OK);
- CHECK(polygon_vertices_count_get(poly, &nvertices), R_OK);
+ CHECK(polygon_vertices_count_get(poly, &nvertices), RES_OK);
CHECK(nvertices, 1);
/* The last vertex is equal to the new one => skip it */
- CHECK(polygon_vertex_add(poly, vertices + 3), R_OK);
- CHECK(polygon_vertices_count_get(poly, &nvertices), R_OK);
+ CHECK(polygon_vertex_add(poly, vertices + 3), RES_OK);
+ CHECK(polygon_vertices_count_get(poly, &nvertices), RES_OK);
CHECK(nvertices, 1);
- CHECK(polygon_vertex_add(poly, vertices + 6), R_OK);
- CHECK(polygon_vertices_count_get(poly, &nvertices), R_OK);
+ CHECK(polygon_vertex_add(poly, vertices + 6), RES_OK);
+ CHECK(polygon_vertices_count_get(poly, &nvertices), RES_OK);
CHECK(nvertices, 2);
/* The new vertex is aligned with the 2 previous one => replace the last
* vertex by the new one */
- CHECK(polygon_vertex_add(poly, vertices + 15), R_OK);
- CHECK(polygon_vertices_count_get(poly, &nvertices), R_OK);
+ CHECK(polygon_vertex_add(poly, vertices + 15), RES_OK);
+ CHECK(polygon_vertices_count_get(poly, &nvertices), RES_OK);
CHECK(nvertices, 2);
- CHECK(polygon_vertex_get(NULL, UINT32_MAX, NULL), R_BAD_ARG);
- CHECK(polygon_vertex_get(poly, UINT32_MAX, NULL), R_BAD_ARG);
- CHECK(polygon_vertex_get(NULL, 0, NULL), R_BAD_ARG);
- CHECK(polygon_vertex_get(poly, 0, NULL), R_BAD_ARG);
- CHECK(polygon_vertex_get(NULL, UINT32_MAX, pos), R_BAD_ARG);
- CHECK(polygon_vertex_get(poly, UINT32_MAX, pos), R_BAD_ARG);
- CHECK(polygon_vertex_get(NULL, 0, pos), R_BAD_ARG);
- CHECK(polygon_vertex_get(poly, 0, pos), R_OK);
+ CHECK(polygon_vertex_get(NULL, UINT32_MAX, NULL), RES_BAD_ARG);
+ CHECK(polygon_vertex_get(poly, UINT32_MAX, NULL), RES_BAD_ARG);
+ CHECK(polygon_vertex_get(NULL, 0, NULL), RES_BAD_ARG);
+ CHECK(polygon_vertex_get(poly, 0, NULL), RES_BAD_ARG);
+ CHECK(polygon_vertex_get(NULL, UINT32_MAX, pos), RES_BAD_ARG);
+ CHECK(polygon_vertex_get(poly, UINT32_MAX, pos), RES_BAD_ARG);
+ CHECK(polygon_vertex_get(NULL, 0, pos), RES_BAD_ARG);
+ CHECK(polygon_vertex_get(poly, 0, pos), RES_OK);
CHECK(f3_eq_eps(pos, vertices + 3, 1.e-6f), 1);
- CHECK(polygon_vertex_get(poly, 1, pos), R_OK);
+ CHECK(polygon_vertex_get(poly, 1, pos), RES_OK);
CHECK(f3_eq_eps(pos, vertices + 15, 1.e-6f), 1);
- CHECK(polygon_vertex_get(poly, 2, pos), R_BAD_ARG);
+ CHECK(polygon_vertex_get(poly, 2, pos), RES_BAD_ARG);
- CHECK(polygon_clear(NULL), R_BAD_ARG);
- CHECK(polygon_clear(poly), R_OK);
+ CHECK(polygon_clear(NULL), RES_BAD_ARG);
+ CHECK(polygon_clear(poly), RES_OK);
- CHECK(polygon_vertices_count_get(poly, &nvertices), R_OK);
+ CHECK(polygon_vertices_count_get(poly, &nvertices), RES_OK);
CHECK(nvertices, 0);
FOR_EACH(ivertex, 0, sizeof(vertices)/sizeof(float[3]))
- CHECK(polygon_vertex_add(poly, vertices + ivertex * 3), R_OK);
+ CHECK(polygon_vertex_add(poly, vertices + ivertex * 3), RES_OK);
- CHECK(polygon_vertices_count_get(poly, &nvertices), R_OK);
+ CHECK(polygon_vertices_count_get(poly, &nvertices), RES_OK);
CHECK(nvertices, sizeof(vertices)/sizeof(float[3]));
FOR_EACH(ivertex, 0, sizeof(vertices)/sizeof(float[3])) {
- CHECK(polygon_vertex_get(poly, ivertex, pos), R_OK);
+ CHECK(polygon_vertex_get(poly, ivertex, pos), RES_OK);
CHECK(f3_eq_eps(pos, vertices + ivertex*3, 1.e-6f), 1);
}
- CHECK(polygon_triangulate(NULL, NULL, NULL), R_BAD_ARG);
- CHECK(polygon_triangulate(poly, NULL, NULL), R_BAD_ARG);
- CHECK(polygon_triangulate(NULL, &indices, NULL), R_BAD_ARG);
- CHECK(polygon_triangulate(poly, &indices, NULL), R_BAD_ARG);
- CHECK(polygon_triangulate(NULL, NULL, &nindices), R_BAD_ARG);
- CHECK(polygon_triangulate(poly, NULL, &nindices), R_BAD_ARG);
- CHECK(polygon_triangulate(NULL, &indices, &nindices), R_BAD_ARG);
+ CHECK(polygon_triangulate(NULL, NULL, NULL), RES_BAD_ARG);
+ CHECK(polygon_triangulate(poly, NULL, NULL), RES_BAD_ARG);
+ CHECK(polygon_triangulate(NULL, &indices, NULL), RES_BAD_ARG);
+ CHECK(polygon_triangulate(poly, &indices, NULL), RES_BAD_ARG);
+ CHECK(polygon_triangulate(NULL, NULL, &nindices), RES_BAD_ARG);
+ CHECK(polygon_triangulate(poly, NULL, &nindices), RES_BAD_ARG);
+ CHECK(polygon_triangulate(NULL, &indices, &nindices), RES_BAD_ARG);
/* Check full triangulation */
- CHECK(polygon_triangulate(poly, &indices, &nindices), R_OK);
+ CHECK(polygon_triangulate(poly, &indices, &nindices), RES_OK);
CHECK(nindices, 30);
CHECK(eq_eps(check_triangulation
(poly, indices, nindices, 12), 1.f, 1.e-6f), 1);
/* After the triangulation the input polygon may be unchanged */
- CHECK(polygon_vertices_count_get(poly, &nvertices), R_OK);
+ CHECK(polygon_vertices_count_get(poly, &nvertices), RES_OK);
CHECK(nvertices, sizeof(vertices)/sizeof(float[3]));
FOR_EACH(ivertex, 0, sizeof(vertices)/sizeof(float[3])) {
- CHECK(polygon_vertex_get(poly, ivertex, pos), R_OK);
+ CHECK(polygon_vertex_get(poly, ivertex, pos), RES_OK);
CHECK(f3_eq_eps(pos, vertices + ivertex*3, 1.e-6f), 1);
}
/* Check that the input polygon can be retriangulated */
- CHECK(polygon_triangulate(poly, &indices, &nindices), R_OK);
+ CHECK(polygon_triangulate(poly, &indices, &nindices), RES_OK);
CHECK(nindices, 30);
CHECK(eq_eps(check_triangulation
(poly, indices, nindices, 12), 1.f, 1.e-6f), 1);
/* One can triangulate empty polygon */
- CHECK(polygon_clear(poly), R_OK);
- CHECK(polygon_triangulate(poly, &indices, &nindices), R_OK);
+ CHECK(polygon_clear(poly), RES_OK);
+ CHECK(polygon_triangulate(poly, &indices, &nindices), RES_OK);
CHECK(nindices, 0);
/* Check the triangulation of an updated polygon */
- CHECK(polygon_vertex_add(poly, vertices + 0), R_OK);
- CHECK(polygon_vertex_add(poly, vertices + 3), R_OK);
- CHECK(polygon_triangulate(poly, &indices, &nindices), R_OK);
+ CHECK(polygon_vertex_add(poly, vertices + 0), RES_OK);
+ CHECK(polygon_vertex_add(poly, vertices + 3), RES_OK);
+ CHECK(polygon_triangulate(poly, &indices, &nindices), RES_OK);
CHECK(nindices, 0);
- CHECK(polygon_vertex_add(poly, vertices + 6), R_OK);
- CHECK(polygon_triangulate(poly, &indices, &nindices), R_OK);
+ CHECK(polygon_vertex_add(poly, vertices + 6), RES_OK);
+ CHECK(polygon_triangulate(poly, &indices, &nindices), RES_OK);
CHECK(nindices, 3);
CHECK(eq_eps(check_triangulation
(poly, indices, nindices, 3), 0.5f, 1.e-6f), 1);
- CHECK(polygon_vertex_add(poly, vertices + 9), R_OK);
- CHECK(polygon_vertex_add(poly, vertices + 12), R_OK);
- CHECK(polygon_vertex_add(poly, vertices + 15), R_OK);
- CHECK(polygon_vertex_add(poly, vertices + 18), R_OK);
- CHECK(polygon_vertex_add(poly, vertices + 21), R_OK);
- CHECK(polygon_vertex_add(poly, vertices + 21), R_OK);
- CHECK(polygon_triangulate(poly, &indices, &nindices), R_OK);
+ CHECK(polygon_vertex_add(poly, vertices + 9), RES_OK);
+ CHECK(polygon_vertex_add(poly, vertices + 12), RES_OK);
+ CHECK(polygon_vertex_add(poly, vertices + 15), RES_OK);
+ CHECK(polygon_vertex_add(poly, vertices + 18), RES_OK);
+ CHECK(polygon_vertex_add(poly, vertices + 21), RES_OK);
+ CHECK(polygon_vertex_add(poly, vertices + 21), RES_OK);
+ CHECK(polygon_triangulate(poly, &indices, &nindices), RES_OK);
CHECK(nindices, 18);
CHECK(eq_eps(check_triangulation
(poly, indices, nindices, 8), 1.375f, 1.e-6f), 1);
- CHECK(polygon_ref_put(poly), R_OK);
+ CHECK(polygon_ref_put(poly), RES_OK);
if(MEM_ALLOCATED_SIZE(&allocator_proxy)) {
char dump[512];
MEM_DUMP(&allocator_proxy, dump, sizeof(dump)/sizeof(char));