commit bcbc33e5e86cde4eb0bd47bdfdf90ee5b7df2be8
parent d58ec87faf10344d7979bfcbb92b4b9508bb4bd0
Author: vaplv <vaplv@free.fr>
Date: Sat, 5 Jul 2014 15:56:09 +0200
Add and test the smooth group getter
Diffstat:
3 files changed, 47 insertions(+), 16 deletions(-)
diff --git a/src/obj.c b/src/obj.c
@@ -19,12 +19,6 @@ struct named_group {
size_t nfaces; /* Faces count in the group */
};
-struct smooth_group {
- char is_enabled;
- size_t iface; /* Index toward the first face */
- size_t nfaces; /* Faces count in the group */
-};
-
static INLINE void
named_group_init(struct mem_allocator* allocator, struct named_group* grp)
{
@@ -80,7 +74,7 @@ named_group_copy_and_release(struct named_group* dst, struct named_group* src)
/* Generate the darray_smooth_group data structure */
#define DARRAY_NAME smooth_group
-#define DARRAY_DATA struct smooth_group
+#define DARRAY_DATA struct obj_smooth_group
#include <rsys/dynamic_array.h>
/* Generate the darray_mtllib data structure */
@@ -175,7 +169,7 @@ flush_usemtl(struct obj* obj)
static FINLINE void
flush_smooth_group(struct obj* obj)
{
- struct smooth_group* grp;
+ struct obj_smooth_group* grp;
size_t nfaces, ngrps;
ASSERT(obj);
if(0 == (nfaces = darray_face_size_get(&obj->faces)))
@@ -183,8 +177,8 @@ flush_smooth_group(struct obj* obj)
if(0 == (ngrps = darray_smooth_group_size_get(&obj->smooth_groups)))
return;
grp = darray_smooth_group_data_get(&obj->smooth_groups) + (ngrps - 1);
- ASSERT(grp->iface < nfaces);
- grp->nfaces = nfaces - grp->iface;
+ ASSERT(grp->face_id < nfaces);
+ grp->faces_count = nfaces - grp->face_id;
}
static enum obj_result
@@ -329,7 +323,7 @@ static enum obj_result
parse_smooth_group(struct obj* obj, char** word_tk)
{
char* word;
- struct smooth_group grp;
+ struct obj_smooth_group grp;
enum obj_result res;
size_t i;
ASSERT(obj && word_tk);
@@ -338,17 +332,17 @@ parse_smooth_group(struct obj* obj, char** word_tk)
word = strtok_r(NULL, " ", word_tk);
if(!strcmp(word, "off")) {
- grp.is_enabled = 0;
+ grp.is_smoothed = 0;
} else if(!strcmp(word, "on")) {
- grp.is_enabled = 1;
+ grp.is_smoothed = 1;
} else {
res = string_to_size_t(word, &i);
if(res != OBJ_OK)
return res;
- grp.is_enabled = i != 0;
+ grp.is_smoothed = i != 0;
}
- grp.iface = darray_face_size_get(&obj->faces);
- grp.nfaces = 0;
+ grp.face_id = darray_face_size_get(&obj->faces);
+ grp.faces_count = 0;
if(darray_smooth_group_push_back(&obj->smooth_groups, &grp))
return OBJ_MEMORY_ERROR;
@@ -666,3 +660,15 @@ obj_group_get(const struct obj* obj, const size_t igroup, struct obj_group* grp)
return OBJ_OK;
}
+enum obj_result
+obj_smooth_group_get
+ (const struct obj* obj,
+ const size_t ismooth_group,
+ struct obj_smooth_group* group)
+{
+ if(!obj || !group
+ || ismooth_group>= darray_smooth_group_size_get(&obj->smooth_groups))
+ return OBJ_BAD_ARGUMENT;
+ *group = darray_smooth_group_cdata_get(&obj->smooth_groups)[ismooth_group];
+ return OBJ_OK;
+}
diff --git a/src/obj.h b/src/obj.h
@@ -48,6 +48,12 @@ struct obj_group {
size_t faces_count;
};
+struct obj_smooth_group {
+ char is_smoothed;
+ size_t face_id; /* Index of the first smooth group face */
+ size_t faces_count;
+};
+
struct obj;
struct mem_allocator;
@@ -88,6 +94,12 @@ obj_group_get
const size_t group_id,
struct obj_group* group);
+OBJ_API enum obj_result
+obj_smooth_group_get
+ (const struct obj* obj,
+ const size_t smooth_group_id,
+ struct obj_smooth_group* smooth_group);
+
END_DECLS
#endif /* OBJ_H */
diff --git a/src/test_obj.c b/src/test_obj.c
@@ -91,6 +91,7 @@ test_squares(struct obj* obj)
struct obj_desc desc;
struct obj_face face;
struct obj_group group;
+ struct obj_smooth_group sgroup;
FILE* file;
NCHECK(obj, NULL);
@@ -133,6 +134,18 @@ test_squares(struct obj* obj)
CHECK(strcmp(group.name, "all"), 0);
CHECK(group.face_id, 0);
CHECK(group.faces_count, 2);
+
+ CHECK(obj_smooth_group_get(NULL, OBJ_ID_NONE, NULL), OBJ_BAD_ARGUMENT);
+ CHECK(obj_smooth_group_get(obj, OBJ_ID_NONE, NULL), OBJ_BAD_ARGUMENT);
+ CHECK(obj_smooth_group_get(NULL, 0, NULL), OBJ_BAD_ARGUMENT);
+ CHECK(obj_smooth_group_get(obj, 0, NULL), OBJ_BAD_ARGUMENT);
+ CHECK(obj_smooth_group_get(NULL, OBJ_ID_NONE, &sgroup), OBJ_BAD_ARGUMENT);
+ CHECK(obj_smooth_group_get(obj, OBJ_ID_NONE, &sgroup), OBJ_BAD_ARGUMENT);
+ CHECK(obj_smooth_group_get(NULL, 0, &sgroup), OBJ_BAD_ARGUMENT);
+ CHECK(obj_smooth_group_get(obj, 0, &sgroup), OBJ_OK);
+ CHECK(sgroup.is_smoothed, 1);
+ CHECK(sgroup.face_id, 0);
+ CHECK(sgroup.faces_count, 2);
}
static void