commit bab33b837dea821e5bbc662b32e16332d38a5f87
parent cb3b6a670ffe7c605177e2925714fa33f361e864
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Fri, 4 Nov 2016 11:48:26 +0100
Add API calls to copy and recursive_copy nodes.
Make the my_type examples more realistic.
Add tests for the new API and adapt tests.
Diffstat:
7 files changed, 611 insertions(+), 406 deletions(-)
diff --git a/src/sanim.h b/src/sanim.h
@@ -129,6 +129,15 @@ sanim_node_initialize_pivot
const struct sanim_tracking* tracking,
struct sanim_node* node);
+/* simple copy, no recursion
+ * copy content of src into node that must be valid
+ * copy rotations, translation and possible pivot information */
+SANIM_API res_T
+sanim_node_copy_initialize
+ (struct mem_allocator* allocator, /* May be NULL <=> use default allocator */
+ const struct sanim_node* src,
+ struct sanim_node* node);
+
SANIM_API res_T
sanim_node_solve_pivot
(struct sanim_node* node,
@@ -174,13 +183,6 @@ sanim_node_get_child
const size_t idx,
const struct sanim_node** child);
-/* simple copy, no recursion */
-SANIM_API res_T
-sanim_node_copy
- (struct mem_allocator* allocator, /* May be NULL <=> use default allocator */
- const struct sanim_node* src_node,
- struct sanim_node* node);
-
END_DECLS
#endif /* SANIM_H */
diff --git a/src/sanim_node.c b/src/sanim_node.c
@@ -719,7 +719,7 @@ copy_and_normalise_pivot_data
}
/*******************************************************************************
-* Exported ssol_spectrum functions
+* Exported sanim_node functions
******************************************************************************/
res_T
sanim_node_add_child
@@ -810,6 +810,40 @@ error:
}
res_T
+sanim_node_copy_initialize
+ (struct mem_allocator* allocator, /* May be NULL <=> use default allocator */
+ const struct sanim_node* src,
+ struct sanim_node* node)
+{
+ res_T res = RES_OK;
+
+ if (!node || !src) return RES_BAD_ARG;
+ res = sanim_node_initialize(allocator, node);
+ if (res != RES_OK) goto error;
+
+ if (src->data->pivot_data) {
+ node->data->pivot_data
+ = MEM_CALLOC(node->data->allocator, 1, sizeof(struct pivot_data));
+ if (!node->data->pivot_data) {
+ res = RES_MEM_ERR;
+ goto error;
+ }
+ node->data->pivot_data->angleX = src->data->pivot_data->angleX;
+ node->data->pivot_data->angleZ = src->data->pivot_data->angleZ;
+ node->data->pivot_data->pivot = src->data->pivot_data->pivot;
+ node->data->pivot_data->tracking = src->data->pivot_data->tracking;
+ }
+ d3_set(node->data->rotations, src->data->rotations);
+ d3_set(node->data->translation, src->data->translation);
+
+exit:
+ return res;
+error:
+ sanim_node_release(node);
+ goto exit;
+}
+
+res_T
sanim_node_solve_pivot
(struct sanim_node* node,
const double in_dir[3])
@@ -841,6 +875,7 @@ sanim_node_release
MEM_RM(node->data->allocator, node->data->pivot_data);
}
MEM_RM(node->data->allocator, node->data);
+ node->data = NULL;
}
return RES_OK;
}
@@ -911,38 +946,3 @@ sanim_node_get_child
*child = children[idx];
return RES_OK;
}
-
-res_T
-sanim_node_copy
- (struct mem_allocator* allocator, /* May be NULL <=> use default allocator */
- const struct sanim_node* src_node,
- struct sanim_node* node)
-{
- res_T res = RES_OK;
-
- if (!node || !src_node) return RES_BAD_ARG;
- res = sanim_node_initialize(allocator, node);
- if (res != RES_OK) goto error;
-
- if (src_node->data->pivot_data) {
- /* duplicate pivot data */
- struct mem_allocator* alloc = allocator ? allocator : &mem_default_allocator;
- node->data->pivot_data = MEM_CALLOC(alloc, 1, sizeof(struct pivot_data));
- if (!node->data->pivot_data) {
- res = RES_MEM_ERR;
- goto error;
- }
- node->data->pivot_data->angleX = src_node->data->pivot_data->angleX;
- node->data->pivot_data->angleZ = src_node->data->pivot_data->angleZ;
- node->data->pivot_data->pivot = src_node->data->pivot_data->pivot;
- node->data->pivot_data->tracking = src_node->data->pivot_data->tracking;
- }
- d3_set(node->data->rotations, src_node->data->rotations);
- d3_set(node->data->translation, src_node->data->translation);
-
-exit:
- return res;
-error:
- sanim_node_release(node);
- goto exit;
-}
diff --git a/src/test_sanim_node.c b/src/test_sanim_node.c
@@ -22,8 +22,7 @@ int
main(int argc, char** argv)
{
struct mem_allocator allocator;
- struct my_type t1, t2;
- struct my_type* ptr;
+ struct my_type *t1, *t2, *ptr;
struct sanim_pivot pivot;
struct sanim_tracking tracking;
size_t count;
@@ -37,73 +36,82 @@ main(int argc, char** argv)
mem_init_proxy_allocator(&allocator, &mem_default_allocator);
- CHECK(my_type_init(NULL, &t1), RES_OK);
- CHECK(my_type_release(NULL), RES_BAD_ARG);
- CHECK(my_type_release(&t1), RES_OK);
- CHECK(my_type_init(&allocator, &t1), RES_OK);
- CHECK(my_type_init(&allocator, NULL), RES_BAD_ARG);
- CHECK(my_type_init(&allocator, &t2), RES_OK);
- CHECK(my_type_release(&t1), RES_OK);
-
- CHECK(my_type_init_pivot(&allocator, NULL, &tracking, &t1), RES_BAD_ARG);
- CHECK(my_type_init_pivot(&allocator, &pivot, NULL, &t1), RES_BAD_ARG);
- CHECK(my_type_init_pivot(&allocator, &pivot, &tracking, NULL), RES_BAD_ARG);
- CHECK(my_type_init_pivot(&allocator, &pivot, &tracking, &t1), RES_OK);
- CHECK(my_type_release(&t1), RES_OK);
-
- CHECK(my_type_init(&allocator, &t1), RES_OK);
- CHECK(my_type_add_child(NULL, &t1), RES_BAD_ARG);
- CHECK(my_type_add_child(&t1, NULL), RES_BAD_ARG);
- CHECK(my_type_add_child(&t1, &t1), RES_BAD_ARG);
- CHECK(my_type_add_child(&t1, &t2), RES_OK);
- CHECK(my_type_add_child(&t1, &t2), RES_BAD_ARG);
- CHECK(my_type_add_child(&t2, &t1), RES_BAD_ARG);
-
- CHECK(my_type_copy(&allocator, NULL, &t1), RES_BAD_ARG);
- CHECK(my_type_copy(&allocator, &t1, NULL), RES_BAD_ARG);
-
- CHECK(my_type_get_father(&t1, NULL), RES_BAD_ARG);
+ CHECK(my_type_create(NULL, &t1), RES_OK);
+ CHECK(my_type_ref_put(NULL), RES_BAD_ARG);
+ CHECK(my_type_ref_get(NULL), RES_BAD_ARG);
+ CHECK(my_type_ref_get(t1), RES_OK);
+ CHECK(my_type_ref_put(t1), RES_OK);
+ CHECK(my_type_ref_put(t1), RES_OK);
+ CHECK(my_type_create(&allocator, &t1), RES_OK);
+ CHECK(my_type_create(&allocator, NULL), RES_BAD_ARG);
+ CHECK(my_type_create(&allocator, &t2), RES_OK);
+ CHECK(my_type_ref_put(t1), RES_OK);
+
+ CHECK(my_type_pivot_create(&allocator, NULL, &tracking, &t1), RES_BAD_ARG);
+ CHECK(my_type_pivot_create(&allocator, &pivot, NULL, &t1), RES_BAD_ARG);
+ CHECK(my_type_pivot_create(&allocator, &pivot, &tracking, NULL), RES_BAD_ARG);
+ CHECK(my_type_pivot_create(&allocator, &pivot, &tracking, &t1), RES_OK);
+ CHECK(my_type_ref_put(t1), RES_OK);
+
+ CHECK(my_type_create(&allocator, &t1), RES_OK);
+ CHECK(my_type_add_child(NULL, t1), RES_BAD_ARG);
+ CHECK(my_type_add_child(t1, NULL), RES_BAD_ARG);
+ CHECK(my_type_add_child(t1, t1), RES_BAD_ARG);
+ CHECK(my_type_add_child(t1, t2), RES_OK);
+ CHECK(my_type_add_child(t1, t2), RES_BAD_ARG);
+ CHECK(my_type_add_child(t2, t1), RES_BAD_ARG);
+
+ CHECK(my_type_copy_create(NULL, &ptr), RES_BAD_ARG);
+ CHECK(my_type_copy_create(t1, NULL), RES_BAD_ARG);
+
+ CHECK(my_type_get_father(t1, NULL), RES_BAD_ARG);
CHECK(my_type_get_father(NULL, &ptr), RES_BAD_ARG);
- CHECK(my_type_get_children_count(&t1, NULL), RES_BAD_ARG);
+ CHECK(my_type_get_children_count(t1, NULL), RES_BAD_ARG);
CHECK(my_type_get_children_count(NULL, &count), RES_BAD_ARG);
- CHECK(my_type_get_children_count(&t1, &count), RES_OK);
+ CHECK(my_type_get_children_count(t1, &count), RES_OK);
CHECK(count, 1);
CHECK(my_type_get_child(NULL, 0, &ptr), RES_BAD_ARG);
- CHECK(my_type_get_child(&t1, 10, &ptr), RES_BAD_ARG);
- CHECK(my_type_get_child(&t1, 0, NULL), RES_BAD_ARG);
- CHECK(my_type_get_child(&t1, 0, &ptr), RES_OK);
- CHECK(ptr, &t2);
- CHECK(my_type_get_father(&t1, NULL), RES_BAD_ARG);
+ CHECK(my_type_get_child(t1, 10, &ptr), RES_BAD_ARG);
+ CHECK(my_type_get_child(t1, 0, NULL), RES_BAD_ARG);
+ CHECK(my_type_get_child(t1, 0, &ptr), RES_OK);
+ CHECK(ptr, t2);
+ CHECK(my_type_get_father(t1, NULL), RES_BAD_ARG);
CHECK(my_type_get_father(NULL, &ptr), RES_BAD_ARG);
- CHECK(my_type_get_father(&t1, &ptr), RES_OK);
+ CHECK(my_type_get_father(t1, &ptr), RES_OK);
CHECK(ptr, NULL);
- CHECK(my_type_get_father(&t2, &ptr), RES_OK);
- CHECK(ptr, &t1);
+ CHECK(my_type_get_father(t2, &ptr), RES_OK);
+ CHECK(ptr, t1);
CHECK(my_type_set_translation(NULL, transl), RES_BAD_ARG);
- CHECK(my_type_set_translation(&t1, NULL), RES_BAD_ARG);
- CHECK(my_type_set_translation(&t1, transl), RES_OK);
+ CHECK(my_type_set_translation(t1, NULL), RES_BAD_ARG);
+ CHECK(my_type_set_translation(t1, transl), RES_OK);
CHECK(my_type_set_rotations(NULL, rot), RES_BAD_ARG);
- CHECK(my_type_set_rotations(&t1, NULL), RES_BAD_ARG);
- CHECK(my_type_set_rotations(&t1, rot), RES_OK);
+ CHECK(my_type_set_rotations(t1, NULL), RES_BAD_ARG);
+ CHECK(my_type_set_rotations(t1, rot), RES_OK);
CHECK(my_type_get_transform(NULL, transform1), RES_BAD_ARG);
- CHECK(my_type_get_transform(&t1, NULL), RES_BAD_ARG);
- CHECK(my_type_get_transform(&t1, transform1), RES_OK);
-
- CHECK(my_type_release(&t2), RES_OK);
- CHECK(my_type_copy(&allocator, NULL, &t1), RES_BAD_ARG);
- CHECK(my_type_copy(&allocator, &t1, NULL), RES_BAD_ARG);
- CHECK(my_type_copy(&allocator, &t1, &t2), RES_OK);
- CHECK(my_type_release(&t2), RES_OK);
- CHECK(my_type_copy(NULL, &t1, &t2), RES_OK);
- CHECK(my_type_get_transform(&t2, transform2), RES_OK);
+ CHECK(my_type_get_transform(t1, NULL), RES_BAD_ARG);
+ CHECK(my_type_get_transform(t1, transform1), RES_OK);
+
+ CHECK(my_type_copy_create(NULL, &ptr), RES_BAD_ARG);
+ CHECK(my_type_copy_create(t1, NULL), RES_BAD_ARG);
+ //t1->my_data = 1;
+ CHECK(my_type_copy_create(t1, &ptr), RES_OK);
+ CHECK(t1->my_data, ptr->my_data);
+ CHECK(my_type_get_transform(ptr, transform2), RES_OK);
CHECK(d34_eq_eps(transform1, transform2, 0), 1);
+ CHECK(my_type_ref_put(ptr), RES_OK);
+
+ CHECK(my_type_recursive_copy(&allocator, NULL, &ptr), RES_BAD_ARG);
+ CHECK(my_type_recursive_copy(&allocator, t1, NULL), RES_BAD_ARG);
+ CHECK(my_type_recursive_copy(&allocator, t1, &t1), RES_BAD_ARG);
+ CHECK(my_type_recursive_copy(&allocator, t1, &ptr), RES_OK);
/* release memory */
- CHECK(my_type_release(&t1), RES_OK);
- CHECK(my_type_release(&t2), RES_OK);
+ CHECK(my_type_ref_put(t1), RES_OK);
+ CHECK(my_type_ref_put(t2), RES_OK);
+ CHECK(my_type_ref_put(ptr), RES_OK);
check_memory_allocator(&allocator);
mem_shutdown_proxy_allocator(&allocator);
CHECK(mem_allocated_size(), 0);
diff --git a/src/test_sanim_node_pivot.c b/src/test_sanim_node_pivot.c
@@ -22,7 +22,7 @@ int
main(int argc, char** argv)
{
struct mem_allocator allocator;
- struct my_type t1, t2, t3;
+ struct my_type *t1, *t2, *t3;
struct sanim_pivot pivot;
struct sanim_tracking tracking;
double transform[12];
@@ -32,10 +32,6 @@ main(int argc, char** argv)
mem_init_proxy_allocator(&allocator, &mem_default_allocator);
- CHECK(my_type_init_pivot(&allocator, NULL, &tracking, &t1), RES_BAD_ARG);
- CHECK(my_type_init_pivot(&allocator, &pivot, NULL, &t1), RES_BAD_ARG);
- CHECK(my_type_init_pivot(&allocator, &pivot, &tracking, NULL), RES_BAD_ARG);
-
/*
* 1 axis pivots
* (in/out dirs can be off the YZ plane)
@@ -49,41 +45,41 @@ main(int argc, char** argv)
/* ref_normal not in the YZ plane */
d3(pivot.data.pivot1.ref_normal, 1, 0, 1);
- CHECK(my_type_init_pivot(&allocator, &pivot, &tracking, &t1), RES_BAD_ARG);
+ CHECK(my_type_pivot_create(&allocator, &pivot, &tracking, &t1), RES_BAD_ARG);
d3(pivot.data.pivot1.ref_normal, 0, 0, 1);
- CHECK(my_type_init_pivot(&allocator, &pivot, &tracking, &t1), RES_OK);
- CHECK(my_type_release(&t1), RES_OK);
- CHECK(my_type_init_pivot(NULL, &pivot, &tracking, &t1), RES_OK);
- CHECK(my_type_release(&t1), RES_OK);
+ CHECK(my_type_pivot_create(&allocator, &pivot, &tracking, &t1), RES_OK);
+ CHECK(my_type_ref_put(t1), RES_OK);
+ CHECK(my_type_pivot_create(NULL, &pivot, &tracking, &t1), RES_OK);
+ CHECK(my_type_ref_put(t1), RES_OK);
- CHECK(my_type_init(&allocator, &t1), RES_OK);
- CHECK(my_type_init_pivot(&allocator, &pivot, &tracking, &t2), RES_OK);
- CHECK(my_type_init(&allocator, &t3), RES_OK);
+ CHECK(my_type_create(&allocator, &t1), RES_OK);
+ CHECK(my_type_pivot_create(&allocator, &pivot, &tracking, &t2), RES_OK);
+ CHECK(my_type_create(&allocator, &t3), RES_OK);
- CHECK(my_type_add_child(&t1, &t2), RES_OK);
- CHECK(my_type_add_child(&t2, &t3), RES_OK);
+ CHECK(my_type_add_child(t1, t2), RES_OK);
+ CHECK(my_type_add_child(t2, t3), RES_OK);
d3_splat(transl, +1);
d3(rot, 0, 0, PI/2);
- CHECK(my_type_set_translation(&t1, transl), RES_OK);
- CHECK(my_type_set_rotations(&t1, rot), RES_OK);
- CHECK(my_type_set_translation(&t2, transl), RES_OK);
- CHECK(my_type_set_translation(&t3, transl), RES_OK);
+ CHECK(my_type_set_translation(t1, transl), RES_OK);
+ CHECK(my_type_set_rotations(t1, rot), RES_OK);
+ CHECK(my_type_set_translation(t2, transl), RES_OK);
+ CHECK(my_type_set_translation(t3, transl), RES_OK);
d3(in_dir, 0, 0.99, -0.1);
/* rotation axis is Y after positioning: cannot accomodate in_dir */
- CHECK(sanim_node_solve_pivot(&t2.node, in_dir), RES_BAD_ARG);
+ CHECK(my_type_solve_pivot(t2, in_dir), RES_BAD_ARG);
d3(in_dir, 1, 0.2, -1);
- CHECK(sanim_node_solve_pivot(&t2.node, in_dir), RES_OK);
- CHECK(my_type_get_transform(&t3, transform), RES_OK);
+ CHECK(my_type_solve_pivot(t2, in_dir), RES_OK);
+ CHECK(my_type_get_transform(t3, transform), RES_OK);
d33_muld3(n, transform, pivot.data.pivot1.ref_normal);
CHECK(d3_eq_eps(n, d3(tmp, -sqrt(2) / 2, 0, +sqrt(2) / 2), 1e-7), 1);
CHECK(d3_eq_eps(transform + 9, d3(tmp, -sqrt(2), 3, 2), 1e-7), 1);
- CHECK(my_type_release(&t1), RES_OK);
- CHECK(my_type_release(&t2), RES_OK);
- CHECK(my_type_release(&t3), RES_OK);
+ CHECK(my_type_ref_put(t1), RES_OK);
+ CHECK(my_type_ref_put(t2), RES_OK);
+ CHECK(my_type_ref_put(t3), RES_OK);
/* 1 axis tracking with a fixed output dir */
@@ -92,53 +88,53 @@ main(int argc, char** argv)
d3(pivot.data.pivot1.ref_normal, 0, 0, 1);
d3(tracking.data.out_dir.u, 0, 1, 0);
- CHECK(my_type_init(&allocator, &t1), RES_OK);
- CHECK(my_type_init_pivot(&allocator, &pivot, &tracking, &t2), RES_OK);
- CHECK(my_type_init(&allocator, &t3), RES_OK);
+ CHECK(my_type_create(&allocator, &t1), RES_OK);
+ CHECK(my_type_pivot_create(&allocator, &pivot, &tracking, &t2), RES_OK);
+ CHECK(my_type_create(&allocator, &t3), RES_OK);
- CHECK(my_type_add_child(&t1, &t2), RES_OK);
- CHECK(my_type_add_child(&t2, &t3), RES_OK);
+ CHECK(my_type_add_child(t1, t2), RES_OK);
+ CHECK(my_type_add_child(t2, t3), RES_OK);
- CHECK(my_type_set_translation(&t1, transl), RES_OK);
- CHECK(my_type_set_rotations(&t1, rot), RES_OK);
- CHECK(my_type_set_translation(&t2, transl), RES_OK);
- CHECK(my_type_set_translation(&t3, transl), RES_OK);
+ CHECK(my_type_set_translation(t1, transl), RES_OK);
+ CHECK(my_type_set_rotations(t1, rot), RES_OK);
+ CHECK(my_type_set_translation(t2, transl), RES_OK);
+ CHECK(my_type_set_translation(t3, transl), RES_OK);
d3(in_dir, 0, -1, -0.1);
/* rotation axis is Y after positioning: cannot accomodate <in_dir,out_dir> */
- CHECK(sanim_node_solve_pivot(&t2.node, in_dir), RES_BAD_ARG);
+ CHECK(my_type_solve_pivot(t2, in_dir), RES_BAD_ARG);
- CHECK(my_type_release(&t1), RES_OK);
- CHECK(my_type_release(&t2), RES_OK);
- CHECK(my_type_release(&t3), RES_OK);
+ CHECK(my_type_ref_put(t1), RES_OK);
+ CHECK(my_type_ref_put(t2), RES_OK);
+ CHECK(my_type_ref_put(t3), RES_OK);
tracking.policy = TRACKING_OUT_DIR;
pivot.type = PIVOT_SINGLE_AXIS;
d3(pivot.data.pivot1.ref_normal, 0, 0, 1);
d3(tracking.data.out_dir.u, 1, 0, 1);
- CHECK(my_type_init(&allocator, &t1), RES_OK);
- CHECK(my_type_init_pivot(&allocator, &pivot, &tracking, &t2), RES_OK);
- CHECK(my_type_init(&allocator, &t3), RES_OK);
+ CHECK(my_type_create(&allocator, &t1), RES_OK);
+ CHECK(my_type_pivot_create(&allocator, &pivot, &tracking, &t2), RES_OK);
+ CHECK(my_type_create(&allocator, &t3), RES_OK);
- CHECK(my_type_add_child(&t1, &t2), RES_OK);
- CHECK(my_type_add_child(&t2, &t3), RES_OK);
+ CHECK(my_type_add_child(t1, t2), RES_OK);
+ CHECK(my_type_add_child(t2, t3), RES_OK);
- CHECK(my_type_set_translation(&t1, transl), RES_OK);
- CHECK(my_type_set_rotations(&t1, rot), RES_OK);
- CHECK(my_type_set_translation(&t2, transl), RES_OK);
- CHECK(my_type_set_translation(&t3, transl), RES_OK);
+ CHECK(my_type_set_translation(t1, transl), RES_OK);
+ CHECK(my_type_set_rotations(t1, rot), RES_OK);
+ CHECK(my_type_set_translation(t2, transl), RES_OK);
+ CHECK(my_type_set_translation(t3, transl), RES_OK);
d3(in_dir, 1, -0.3, -1);
- CHECK(sanim_node_solve_pivot(&t2.node, in_dir), RES_OK);
- CHECK(my_type_get_transform(&t3, transform), RES_OK);
+ CHECK(my_type_solve_pivot(t2, in_dir), RES_OK);
+ CHECK(my_type_get_transform(t3, transform), RES_OK);
d33_muld3(n, transform, pivot.data.pivot1.ref_normal);
CHECK(d3_eq_eps(pivot.data.pivot1.ref_normal, n, 1e-7), 1);
CHECK(d3_eq_eps(transform + 9, d3(n, -1, 3, 3), 1e-7), 1);
- CHECK(my_type_release(&t1), RES_OK);
- CHECK(my_type_release(&t2), RES_OK);
- CHECK(my_type_release(&t3), RES_OK);
+ CHECK(my_type_ref_put(t1), RES_OK);
+ CHECK(my_type_ref_put(t2), RES_OK);
+ CHECK(my_type_ref_put(t3), RES_OK);
/* 1 axis tracking a target point */
@@ -149,27 +145,27 @@ main(int argc, char** argv)
d3(tracking.data.point.target, 0, 0, 30);
tracking.data.point.target_is_local = 1;
- CHECK(my_type_init(&allocator, &t1), RES_OK);
- CHECK(my_type_init_pivot(&allocator, &pivot, &tracking, &t2), RES_OK);
- CHECK(my_type_init(&allocator, &t3), RES_OK);
+ CHECK(my_type_create(&allocator, &t1), RES_OK);
+ CHECK(my_type_pivot_create(&allocator, &pivot, &tracking, &t2), RES_OK);
+ CHECK(my_type_create(&allocator, &t3), RES_OK);
- CHECK(my_type_add_child(&t1, &t2), RES_OK);
- CHECK(my_type_add_child(&t2, &t3), RES_OK);
+ CHECK(my_type_add_child(t1, t2), RES_OK);
+ CHECK(my_type_add_child(t2, t3), RES_OK);
- CHECK(my_type_set_translation(&t1, transl), RES_OK);
- CHECK(my_type_set_rotations(&t1, rot), RES_OK);
- CHECK(my_type_set_translation(&t2, transl), RES_OK);
- CHECK(my_type_set_translation(&t3, transl), RES_OK);
+ CHECK(my_type_set_translation(t1, transl), RES_OK);
+ CHECK(my_type_set_rotations(t1, rot), RES_OK);
+ CHECK(my_type_set_translation(t2, transl), RES_OK);
+ CHECK(my_type_set_translation(t3, transl), RES_OK);
d3(in_dir, 1, 0.1, 0);
- CHECK(sanim_node_solve_pivot(&t2.node, in_dir), RES_OK);
- CHECK(my_type_get_transform(&t3, transform), RES_OK);
+ CHECK(my_type_solve_pivot(t2, in_dir), RES_OK);
+ CHECK(my_type_get_transform(t3, transform), RES_OK);
d33_muld3(n, transform, pivot.data.pivot1.ref_normal);
CHECK(d3_eq_eps(n, d3(tmp, -sqrt(2) / 2, 0, +sqrt(2) / 2), 1e-7), 1);
- CHECK(my_type_release(&t1), RES_OK);
- CHECK(my_type_release(&t2), RES_OK);
- CHECK(my_type_release(&t3), RES_OK);
+ CHECK(my_type_ref_put(t1), RES_OK);
+ CHECK(my_type_ref_put(t2), RES_OK);
+ CHECK(my_type_ref_put(t3), RES_OK);
tracking.policy = TRACKING_POINT;
pivot.type = PIVOT_SINGLE_AXIS;
@@ -178,27 +174,27 @@ main(int argc, char** argv)
d3(tracking.data.point.target, 0, 10, 30);
tracking.data.point.target_is_local = 1;
- CHECK(my_type_init(&allocator, &t1), RES_OK);
- CHECK(my_type_init_pivot(&allocator, &pivot, &tracking, &t2), RES_OK);
- CHECK(my_type_init(&allocator, &t3), RES_OK);
+ CHECK(my_type_create(&allocator, &t1), RES_OK);
+ CHECK(my_type_pivot_create(&allocator, &pivot, &tracking, &t2), RES_OK);
+ CHECK(my_type_create(&allocator, &t3), RES_OK);
- CHECK(my_type_add_child(&t1, &t2), RES_OK);
- CHECK(my_type_add_child(&t2, &t3), RES_OK);
+ CHECK(my_type_add_child(t1, t2), RES_OK);
+ CHECK(my_type_add_child(t2, t3), RES_OK);
- CHECK(my_type_set_translation(&t1, transl), RES_OK);
- CHECK(my_type_set_rotations(&t1, rot), RES_OK);
- CHECK(my_type_set_translation(&t2, transl), RES_OK);
- CHECK(my_type_set_translation(&t3, transl), RES_OK);
+ CHECK(my_type_set_translation(t1, transl), RES_OK);
+ CHECK(my_type_set_rotations(t1, rot), RES_OK);
+ CHECK(my_type_set_translation(t2, transl), RES_OK);
+ CHECK(my_type_set_translation(t3, transl), RES_OK);
d3(in_dir, 1, 0.1, 0);
- CHECK(sanim_node_solve_pivot(&t2.node, in_dir), RES_OK);
- CHECK(my_type_get_transform(&t3, transform), RES_OK);
+ CHECK(my_type_solve_pivot(t2, in_dir), RES_OK);
+ CHECK(my_type_get_transform(t3, transform), RES_OK);
d33_muld3(n, transform, pivot.data.pivot1.ref_normal);
CHECK(d3_eq_eps(n, d3(tmp, -sqrt(2) / 2, 0, +sqrt(2) / 2), 1e-7), 1);
- CHECK(my_type_release(&t1), RES_OK);
- CHECK(my_type_release(&t2), RES_OK);
- CHECK(my_type_release(&t3), RES_OK);
+ CHECK(my_type_ref_put(t1), RES_OK);
+ CHECK(my_type_ref_put(t2), RES_OK);
+ CHECK(my_type_ref_put(t3), RES_OK);
/* same 1 axis tracking with a non-local target point */
@@ -209,27 +205,27 @@ main(int argc, char** argv)
d3(tracking.data.point.target, -10, 2, 32);
tracking.data.point.target_is_local = 0;
- CHECK(my_type_init(&allocator, &t1), RES_OK);
- CHECK(my_type_init_pivot(&allocator, &pivot, &tracking, &t2), RES_OK);
- CHECK(my_type_init(&allocator, &t3), RES_OK);
+ CHECK(my_type_create(&allocator, &t1), RES_OK);
+ CHECK(my_type_pivot_create(&allocator, &pivot, &tracking, &t2), RES_OK);
+ CHECK(my_type_create(&allocator, &t3), RES_OK);
- CHECK(my_type_add_child(&t1, &t2), RES_OK);
- CHECK(my_type_add_child(&t2, &t3), RES_OK);
+ CHECK(my_type_add_child(t1, t2), RES_OK);
+ CHECK(my_type_add_child(t2, t3), RES_OK);
- CHECK(my_type_set_translation(&t1, transl), RES_OK);
- CHECK(my_type_set_rotations(&t1, rot), RES_OK);
- CHECK(my_type_set_translation(&t2, transl), RES_OK);
- CHECK(my_type_set_translation(&t3, transl), RES_OK);
+ CHECK(my_type_set_translation(t1, transl), RES_OK);
+ CHECK(my_type_set_rotations(t1, rot), RES_OK);
+ CHECK(my_type_set_translation(t2, transl), RES_OK);
+ CHECK(my_type_set_translation(t3, transl), RES_OK);
d3(in_dir, 1, -0.5, 0);
- CHECK(sanim_node_solve_pivot(&t2.node, in_dir), RES_OK);
- CHECK(my_type_get_transform(&t3, transform), RES_OK);
+ CHECK(my_type_solve_pivot(t2, in_dir), RES_OK);
+ CHECK(my_type_get_transform(t3, transform), RES_OK);
d33_muld3(n, transform, pivot.data.pivot1.ref_normal);
CHECK(d3_eq_eps(n, d3(tmp, -sqrt(2) / 2, 0, +sqrt(2) / 2), 1e-7), 1);
- CHECK(my_type_release(&t1), RES_OK);
- CHECK(my_type_release(&t2), RES_OK);
- CHECK(my_type_release(&t3), RES_OK);
+ CHECK(my_type_ref_put(t1), RES_OK);
+ CHECK(my_type_ref_put(t2), RES_OK);
+ CHECK(my_type_ref_put(t3), RES_OK);
tracking.policy = TRACKING_POINT;
pivot.type = PIVOT_SINGLE_AXIS;
@@ -238,28 +234,28 @@ main(int argc, char** argv)
d3(tracking.data.point.target, -12, 2, -10);
tracking.data.point.target_is_local = 0;
- CHECK(my_type_init(&allocator, &t1), RES_OK);
- CHECK(my_type_init_pivot(&allocator, &pivot, &tracking, &t2), RES_OK);
- CHECK(my_type_init(&allocator, &t3), RES_OK);
+ CHECK(my_type_create(&allocator, &t1), RES_OK);
+ CHECK(my_type_pivot_create(&allocator, &pivot, &tracking, &t2), RES_OK);
+ CHECK(my_type_create(&allocator, &t3), RES_OK);
- CHECK(my_type_add_child(&t1, &t2), RES_OK);
- CHECK(my_type_add_child(&t2, &t3), RES_OK);
+ CHECK(my_type_add_child(t1, t2), RES_OK);
+ CHECK(my_type_add_child(t2, t3), RES_OK);
- CHECK(my_type_set_translation(&t1, transl), RES_OK);
- CHECK(my_type_set_rotations(&t1, rot), RES_OK);
- CHECK(my_type_set_translation(&t2, transl), RES_OK);
- CHECK(my_type_set_translation(&t3, transl), RES_OK);
+ CHECK(my_type_set_translation(t1, transl), RES_OK);
+ CHECK(my_type_set_rotations(t1, rot), RES_OK);
+ CHECK(my_type_set_translation(t2, transl), RES_OK);
+ CHECK(my_type_set_translation(t3, transl), RES_OK);
d3(in_dir, 1, 0, -1);
- CHECK(sanim_node_solve_pivot(&t2.node, in_dir), RES_OK);
- CHECK(my_type_get_transform(&t3, transform), RES_OK);
+ CHECK(my_type_solve_pivot(t2, in_dir), RES_OK);
+ CHECK(my_type_get_transform(t3, transform), RES_OK);
d33_muld3(n, transform, pivot.data.pivot1.ref_normal);
CHECK(d3_eq_eps(n, d3(tmp, -1, 0, 0), 1e-7), 1);
CHECK(d3_eq_eps(transform + 9, d3(tmp, -1, 3, 1), 1e-7), 1);
- CHECK(my_type_release(&t1), RES_OK);
- CHECK(my_type_release(&t2), RES_OK);
- CHECK(my_type_release(&t3), RES_OK);
+ CHECK(my_type_ref_put(t1), RES_OK);
+ CHECK(my_type_ref_put(t2), RES_OK);
+ CHECK(my_type_ref_put(t3), RES_OK);
/*
* 2 axis pivots
@@ -273,37 +269,37 @@ main(int argc, char** argv)
pivot.data.pivot2.spacing = 1;
d3(pivot.data.pivot2.ref_point, 0, 0, 1);
- CHECK(my_type_init(&allocator, &t1), RES_OK);
- CHECK(my_type_init_pivot(&allocator, &pivot, &tracking, &t2), RES_OK);
- CHECK(my_type_init(&allocator, &t3), RES_OK);
+ CHECK(my_type_create(&allocator, &t1), RES_OK);
+ CHECK(my_type_pivot_create(&allocator, &pivot, &tracking, &t2), RES_OK);
+ CHECK(my_type_create(&allocator, &t3), RES_OK);
- CHECK(my_type_add_child(&t1, &t2), RES_OK);
- CHECK(my_type_add_child(&t2, &t3), RES_OK);
+ CHECK(my_type_add_child(t1, t2), RES_OK);
+ CHECK(my_type_add_child(t2, t3), RES_OK);
d3_splat(transl, +1);
d3(rot, 0, 0, PI / 2);
- CHECK(my_type_set_translation(&t1, transl), RES_OK);
- CHECK(my_type_set_rotations(&t1, rot), RES_OK);
- CHECK(my_type_set_translation(&t2, transl), RES_OK);
- CHECK(my_type_set_translation(&t3, transl), RES_OK);
+ CHECK(my_type_set_translation(t1, transl), RES_OK);
+ CHECK(my_type_set_rotations(t1, rot), RES_OK);
+ CHECK(my_type_set_translation(t2, transl), RES_OK);
+ CHECK(my_type_set_translation(t3, transl), RES_OK);
d3(in_dir, 1, 0, -1);
- CHECK(sanim_node_solve_pivot(&t2.node, in_dir), RES_OK);
- CHECK(my_type_get_transform(&t3, transform), RES_OK);
+ CHECK(my_type_solve_pivot(t2, in_dir), RES_OK);
+ CHECK(my_type_get_transform(t3, transform), RES_OK);
d33_muld3(n, transform, y_ref_normal);
CHECK(d3_eq_eps(n, d3(tmp, -sqrt(2) / 2, 0, +sqrt(2) / 2), 1e-7), 1);
CHECK(d3_eq_eps(transform + 9, d3(tmp, -1, 3, 2 + sqrt(2)), 1e-7), 1);
d3(in_dir, 0, 1, 0);
- CHECK(sanim_node_solve_pivot(&t2.node, in_dir), RES_OK);
- CHECK(my_type_get_transform(&t3, transform), RES_OK);
+ CHECK(my_type_solve_pivot(t2, in_dir), RES_OK);
+ CHECK(my_type_get_transform(t3, transform), RES_OK);
d33_muld3(n, transform, y_ref_normal);
CHECK(d3_eq_eps(n, d3(tmp, 0, -1, 0), 1e-7), 1);
CHECK(d3_eq_eps(transform + 9, d3(tmp, -1, 0, 3), 1e-7), 1);
- CHECK(my_type_release(&t1), RES_OK);
- CHECK(my_type_release(&t2), RES_OK);
- CHECK(my_type_release(&t3), RES_OK);
+ CHECK(my_type_ref_put(t1), RES_OK);
+ CHECK(my_type_ref_put(t2), RES_OK);
+ CHECK(my_type_ref_put(t3), RES_OK);
/* 2 axis tracking sun */
@@ -311,37 +307,37 @@ main(int argc, char** argv)
pivot.type = PIVOT_TWO_AXIS;
pivot.data.pivot2.spacing = 1;
- CHECK(my_type_init(&allocator, &t1), RES_OK);
- CHECK(my_type_init_pivot(&allocator, &pivot, &tracking, &t2), RES_OK);
- CHECK(my_type_init(&allocator, &t3), RES_OK);
+ CHECK(my_type_create(&allocator, &t1), RES_OK);
+ CHECK(my_type_pivot_create(&allocator, &pivot, &tracking, &t2), RES_OK);
+ CHECK(my_type_create(&allocator, &t3), RES_OK);
- CHECK(my_type_add_child(&t1, &t2), RES_OK);
- CHECK(my_type_add_child(&t2, &t3), RES_OK);
+ CHECK(my_type_add_child(t1, t2), RES_OK);
+ CHECK(my_type_add_child(t2, t3), RES_OK);
d3_splat(transl, +1);
d3(rot, 0, 0, PI / 2);
- CHECK(my_type_set_translation(&t1, transl), RES_OK);
- CHECK(my_type_set_rotations(&t1, rot), RES_OK);
- CHECK(my_type_set_translation(&t2, transl), RES_OK);
- CHECK(my_type_set_translation(&t3, transl), RES_OK);
+ CHECK(my_type_set_translation(t1, transl), RES_OK);
+ CHECK(my_type_set_rotations(t1, rot), RES_OK);
+ CHECK(my_type_set_translation(t2, transl), RES_OK);
+ CHECK(my_type_set_translation(t3, transl), RES_OK);
d3(in_dir, 1, 0, -1);
- CHECK(sanim_node_solve_pivot(&t2.node, in_dir), RES_OK);
- CHECK(my_type_get_transform(&t3, transform), RES_OK);
+ CHECK(my_type_solve_pivot(t2, in_dir), RES_OK);
+ CHECK(my_type_get_transform(t3, transform), RES_OK);
d33_muld3(n, transform, y_ref_normal);
CHECK(d3_eq_eps(n, d3(tmp, -sqrt(2) / 2, 0, +sqrt(2) / 2), 1e-7), 1);
CHECK(d3_eq_eps(transform + 9, d3(tmp, -1, 3, 2 + sqrt(2)), 1e-7), 1);
d3(in_dir, 0, 1, 0);
- CHECK(sanim_node_solve_pivot(&t2.node, in_dir), RES_OK);
- CHECK(my_type_get_transform(&t3, transform), RES_OK);
+ CHECK(my_type_solve_pivot(t2, in_dir), RES_OK);
+ CHECK(my_type_get_transform(t3, transform), RES_OK);
d33_muld3(n, transform, y_ref_normal);
CHECK(d3_eq_eps(n, d3(tmp, 0, -1, 0), 1e-7), 1);
CHECK(d3_eq_eps(transform + 9, d3(tmp, -1, 0, 3), 1e-7), 1);
- CHECK(my_type_release(&t1), RES_OK);
- CHECK(my_type_release(&t2), RES_OK);
- CHECK(my_type_release(&t3), RES_OK);
+ CHECK(my_type_ref_put(t1), RES_OK);
+ CHECK(my_type_ref_put(t2), RES_OK);
+ CHECK(my_type_ref_put(t3), RES_OK);
/* 2 axis tracking with a fixed output dir */
@@ -350,35 +346,35 @@ main(int argc, char** argv)
pivot.data.pivot2.spacing = 1;
d3(tracking.data.out_dir.u, 0, 1, 0);
- CHECK(my_type_init(&allocator, &t1), RES_OK);
- CHECK(my_type_init_pivot(&allocator, &pivot, &tracking, &t2), RES_OK);
- CHECK(my_type_init(&allocator, &t3), RES_OK);
+ CHECK(my_type_create(&allocator, &t1), RES_OK);
+ CHECK(my_type_pivot_create(&allocator, &pivot, &tracking, &t2), RES_OK);
+ CHECK(my_type_create(&allocator, &t3), RES_OK);
- CHECK(my_type_add_child(&t1, &t2), RES_OK);
- CHECK(my_type_add_child(&t2, &t3), RES_OK);
+ CHECK(my_type_add_child(t1, t2), RES_OK);
+ CHECK(my_type_add_child(t2, t3), RES_OK);
- CHECK(my_type_set_translation(&t1, transl), RES_OK);
- CHECK(my_type_set_rotations(&t1, rot), RES_OK);
- CHECK(my_type_set_translation(&t2, transl), RES_OK);
- CHECK(my_type_set_translation(&t3, transl), RES_OK);
+ CHECK(my_type_set_translation(t1, transl), RES_OK);
+ CHECK(my_type_set_rotations(t1, rot), RES_OK);
+ CHECK(my_type_set_translation(t2, transl), RES_OK);
+ CHECK(my_type_set_translation(t3, transl), RES_OK);
d3(in_dir, 0, 0, -1);
- CHECK(sanim_node_solve_pivot(&t2.node, in_dir), RES_OK);
- CHECK(my_type_get_transform(&t3, transform), RES_OK);
+ CHECK(my_type_solve_pivot(t2, in_dir), RES_OK);
+ CHECK(my_type_get_transform(t3, transform), RES_OK);
d33_muld3(n, transform, y_ref_normal);
CHECK(d3_eq_eps(n, d3(tmp, 0, sqrt(2) / 2, sqrt(2) / 2), 1e-7), 1);
CHECK(d3_eq_eps(transform + 9, d3(tmp, 1, 3, 2 + sqrt(2)), 1e-7), 1);
d3(in_dir, -1, 0, 0);
- CHECK(sanim_node_solve_pivot(&t2.node, in_dir), RES_OK);
- CHECK(my_type_get_transform(&t3, transform), RES_OK);
+ CHECK(my_type_solve_pivot(t2, in_dir), RES_OK);
+ CHECK(my_type_get_transform(t3, transform), RES_OK);
d33_muld3(n, transform, y_ref_normal);
CHECK(d3_eq_eps(n, d3(tmp, sqrt(2) / 2, sqrt(2) / 2, 0), 1e-7), 1);
CHECK(d3_eq_eps(transform + 9, d3(tmp, 3 * sqrt(2) / 2, 2 + sqrt(2) / 2, 3), 1e-7), 1);
- CHECK(my_type_release(&t1), RES_OK);
- CHECK(my_type_release(&t2), RES_OK);
- CHECK(my_type_release(&t3), RES_OK);
+ CHECK(my_type_ref_put(t1), RES_OK);
+ CHECK(my_type_ref_put(t2), RES_OK);
+ CHECK(my_type_ref_put(t3), RES_OK);
/* 2 axis tracking a target point */
@@ -389,28 +385,28 @@ main(int argc, char** argv)
d3(tracking.data.point.target, 30, 0, 0);
tracking.data.point.target_is_local = 1;
- CHECK(my_type_init(&allocator, &t1), RES_OK);
- CHECK(my_type_init_pivot(&allocator, &pivot, &tracking, &t2), RES_OK);
- CHECK(my_type_init(&allocator, &t3), RES_OK);
+ CHECK(my_type_create(&allocator, &t1), RES_OK);
+ CHECK(my_type_pivot_create(&allocator, &pivot, &tracking, &t2), RES_OK);
+ CHECK(my_type_create(&allocator, &t3), RES_OK);
- CHECK(my_type_add_child(&t1, &t2), RES_OK);
- CHECK(my_type_add_child(&t2, &t3), RES_OK);
+ CHECK(my_type_add_child(t1, t2), RES_OK);
+ CHECK(my_type_add_child(t2, t3), RES_OK);
- CHECK(my_type_set_translation(&t1, transl), RES_OK);
- CHECK(my_type_set_rotations(&t1, rot), RES_OK);
- CHECK(my_type_set_translation(&t2, transl), RES_OK);
- CHECK(my_type_set_translation(&t3, transl), RES_OK);
+ CHECK(my_type_set_translation(t1, transl), RES_OK);
+ CHECK(my_type_set_rotations(t1, rot), RES_OK);
+ CHECK(my_type_set_translation(t2, transl), RES_OK);
+ CHECK(my_type_set_translation(t3, transl), RES_OK);
d3(in_dir, -1, 0, 0);
- CHECK(sanim_node_solve_pivot(&t2.node, in_dir), RES_OK);
- CHECK(my_type_get_transform(&t3, transform), RES_OK);
+ CHECK(my_type_solve_pivot(t2, in_dir), RES_OK);
+ CHECK(my_type_get_transform(t3, transform), RES_OK);
d33_muld3(n, transform, y_ref_normal);
CHECK(d3_eq_eps(n, d3(tmp, sqrt(2) / 2, sqrt(2) / 2, 0), 1e-7), 1);
CHECK(d3_eq_eps(transform + 9, d3(tmp, sqrt(2), 2, 3), 1e-7), 1);
- CHECK(my_type_release(&t1), RES_OK);
- CHECK(my_type_release(&t2), RES_OK);
- CHECK(my_type_release(&t3), RES_OK);
+ CHECK(my_type_ref_put(t1), RES_OK);
+ CHECK(my_type_ref_put(t2), RES_OK);
+ CHECK(my_type_ref_put(t3), RES_OK);
tracking.policy = TRACKING_POINT;
pivot.type = PIVOT_TWO_AXIS;
@@ -419,28 +415,28 @@ main(int argc, char** argv)
d3(tracking.data.point.target, 30, -11, 0);
tracking.data.point.target_is_local = 1;
- CHECK(my_type_init(&allocator, &t1), RES_OK);
- CHECK(my_type_init_pivot(&allocator, &pivot, &tracking, &t2), RES_OK);
- CHECK(my_type_init(&allocator, &t3), RES_OK);
+ CHECK(my_type_create(&allocator, &t1), RES_OK);
+ CHECK(my_type_pivot_create(&allocator, &pivot, &tracking, &t2), RES_OK);
+ CHECK(my_type_create(&allocator, &t3), RES_OK);
- CHECK(my_type_add_child(&t1, &t2), RES_OK);
- CHECK(my_type_add_child(&t2, &t3), RES_OK);
+ CHECK(my_type_add_child(t1, t2), RES_OK);
+ CHECK(my_type_add_child(t2, t3), RES_OK);
- CHECK(my_type_set_translation(&t1, transl), RES_OK);
- CHECK(my_type_set_rotations(&t1, rot), RES_OK);
- CHECK(my_type_set_translation(&t2, transl), RES_OK);
- CHECK(my_type_set_translation(&t3, transl), RES_OK);
+ CHECK(my_type_set_translation(t1, transl), RES_OK);
+ CHECK(my_type_set_rotations(t1, rot), RES_OK);
+ CHECK(my_type_set_translation(t2, transl), RES_OK);
+ CHECK(my_type_set_translation(t3, transl), RES_OK);
d3(in_dir, -1, 0, 0);
- CHECK(sanim_node_solve_pivot(&t2.node, in_dir), RES_OK);
- CHECK(my_type_get_transform(&t3, transform), RES_OK);
+ CHECK(my_type_solve_pivot(t2, in_dir), RES_OK);
+ CHECK(my_type_get_transform(t3, transform), RES_OK);
d33_muld3(n, transform, y_ref_normal);
CHECK(d3_eq_eps(n, d3(tmp, sqrt(2) / 2, sqrt(2) / 2, 0), 1e-7), 1);
CHECK(d3_eq_eps(transform + 9, d3(tmp, 1 + sqrt(2), 3, 3), 1e-7), 1);
- CHECK(my_type_release(&t1), RES_OK);
- CHECK(my_type_release(&t2), RES_OK);
- CHECK(my_type_release(&t3), RES_OK);
+ CHECK(my_type_ref_put(t1), RES_OK);
+ CHECK(my_type_ref_put(t2), RES_OK);
+ CHECK(my_type_ref_put(t3), RES_OK);
tracking.policy = TRACKING_POINT;
pivot.type = PIVOT_TWO_AXIS;
@@ -449,28 +445,28 @@ main(int argc, char** argv)
d3(tracking.data.point.target, 0, 30, 10);
tracking.data.point.target_is_local = 1;
- CHECK(my_type_init(&allocator, &t1), RES_OK);
- CHECK(my_type_init_pivot(&allocator, &pivot, &tracking, &t2), RES_OK);
- CHECK(my_type_init(&allocator, &t3), RES_OK);
+ CHECK(my_type_create(&allocator, &t1), RES_OK);
+ CHECK(my_type_pivot_create(&allocator, &pivot, &tracking, &t2), RES_OK);
+ CHECK(my_type_create(&allocator, &t3), RES_OK);
- CHECK(my_type_add_child(&t1, &t2), RES_OK);
- CHECK(my_type_add_child(&t2, &t3), RES_OK);
+ CHECK(my_type_add_child(t1, t2), RES_OK);
+ CHECK(my_type_add_child(t2, t3), RES_OK);
- CHECK(my_type_set_translation(&t1, transl), RES_OK);
- CHECK(my_type_set_rotations(&t1, rot), RES_OK);
- CHECK(my_type_set_translation(&t2, transl), RES_OK);
- CHECK(my_type_set_translation(&t3, transl), RES_OK);
+ CHECK(my_type_set_translation(t1, transl), RES_OK);
+ CHECK(my_type_set_rotations(t1, rot), RES_OK);
+ CHECK(my_type_set_translation(t2, transl), RES_OK);
+ CHECK(my_type_set_translation(t3, transl), RES_OK);
d3(in_dir, 0, 0, -1);
- CHECK(sanim_node_solve_pivot(&t2.node, in_dir), RES_OK);
- CHECK(my_type_get_transform(&t3, transform), RES_OK);
+ CHECK(my_type_solve_pivot(t2, in_dir), RES_OK);
+ CHECK(my_type_get_transform(t3, transform), RES_OK);
d33_muld3(n, transform, y_ref_normal);
CHECK(d3_eq_eps(n, d3(tmp, -sqrt(2) / 2, 0, +sqrt(2) / 2), 1e-7), 1);
CHECK(d3_eq_eps(transform + 9, d3(tmp, -1, 3, 2 + sqrt(2)), 1e-7), 1);
- CHECK(my_type_release(&t1), RES_OK);
- CHECK(my_type_release(&t2), RES_OK);
- CHECK(my_type_release(&t3), RES_OK);
+ CHECK(my_type_ref_put(t1), RES_OK);
+ CHECK(my_type_ref_put(t2), RES_OK);
+ CHECK(my_type_ref_put(t3), RES_OK);
tracking.policy = TRACKING_POINT;
pivot.type = PIVOT_TWO_AXIS;
@@ -479,28 +475,28 @@ main(int argc, char** argv)
d3(tracking.data.point.target, 0, 30, 12);
tracking.data.point.target_is_local = 0;
- CHECK(my_type_init(&allocator, &t1), RES_OK);
- CHECK(my_type_init_pivot(&allocator, &pivot, &tracking, &t2), RES_OK);
- CHECK(my_type_init(&allocator, &t3), RES_OK);
+ CHECK(my_type_create(&allocator, &t1), RES_OK);
+ CHECK(my_type_pivot_create(&allocator, &pivot, &tracking, &t2), RES_OK);
+ CHECK(my_type_create(&allocator, &t3), RES_OK);
- CHECK(my_type_add_child(&t1, &t2), RES_OK);
- CHECK(my_type_add_child(&t2, &t3), RES_OK);
+ CHECK(my_type_add_child(t1, t2), RES_OK);
+ CHECK(my_type_add_child(t2, t3), RES_OK);
- CHECK(my_type_set_translation(&t1, transl), RES_OK);
- CHECK(my_type_set_rotations(&t1, rot), RES_OK);
- CHECK(my_type_set_translation(&t2, transl), RES_OK);
- CHECK(my_type_set_translation(&t3, transl), RES_OK);
+ CHECK(my_type_set_translation(t1, transl), RES_OK);
+ CHECK(my_type_set_rotations(t1, rot), RES_OK);
+ CHECK(my_type_set_translation(t2, transl), RES_OK);
+ CHECK(my_type_set_translation(t3, transl), RES_OK);
d3(in_dir, 0, 0, -1);
- CHECK(sanim_node_solve_pivot(&t2.node, in_dir), RES_OK);
- CHECK(my_type_get_transform(&t3, transform), RES_OK);
+ CHECK(my_type_solve_pivot(t2, in_dir), RES_OK);
+ CHECK(my_type_get_transform(t3, transform), RES_OK);
d33_muld3(n, transform, y_ref_normal);
CHECK(d3_eq_eps(n, d3(tmp, 0, sqrt(2) / 2, sqrt(2) / 2), 1e-7), 1);
CHECK(d3_eq_eps(transform + 9, d3(tmp, 1, 3, 2 + sqrt(2)), 1e-7), 1);
- CHECK(my_type_release(&t1), RES_OK);
- CHECK(my_type_release(&t2), RES_OK);
- CHECK(my_type_release(&t3), RES_OK);
+ CHECK(my_type_ref_put(t1), RES_OK);
+ CHECK(my_type_ref_put(t2), RES_OK);
+ CHECK(my_type_ref_put(t3), RES_OK);
tracking.policy = TRACKING_POINT;
pivot.type = PIVOT_TWO_AXIS;
@@ -509,29 +505,29 @@ main(int argc, char** argv)
d3(tracking.data.point.target, 10, 12, 15);
tracking.data.point.target_is_local = 0;
- CHECK(my_type_init(&allocator, &t1), RES_OK);
- CHECK(my_type_init_pivot(&allocator, &pivot, &tracking, &t2), RES_OK);
- CHECK(my_type_init(&allocator, &t3), RES_OK);
+ CHECK(my_type_create(&allocator, &t1), RES_OK);
+ CHECK(my_type_pivot_create(&allocator, &pivot, &tracking, &t2), RES_OK);
+ CHECK(my_type_create(&allocator, &t3), RES_OK);
- CHECK(my_type_add_child(&t1, &t2), RES_OK);
- CHECK(my_type_add_child(&t2, &t3), RES_OK);
+ CHECK(my_type_add_child(t1, t2), RES_OK);
+ CHECK(my_type_add_child(t2, t3), RES_OK);
- CHECK(my_type_set_translation(&t1, transl), RES_OK);
- CHECK(my_type_set_rotations(&t1, rot), RES_OK);
- CHECK(my_type_set_translation(&t2, transl), RES_OK);
- CHECK(my_type_set_translation(&t3, transl), RES_OK);
+ CHECK(my_type_set_translation(t1, transl), RES_OK);
+ CHECK(my_type_set_rotations(t1, rot), RES_OK);
+ CHECK(my_type_set_translation(t2, transl), RES_OK);
+ CHECK(my_type_set_translation(t3, transl), RES_OK);
d3(in_dir, 0, 0, -1);
- CHECK(sanim_node_solve_pivot(&t2.node, in_dir), RES_OK);
- CHECK(my_type_get_transform(&t3, transform), RES_OK);
+ CHECK(my_type_solve_pivot(t2, in_dir), RES_OK);
+ CHECK(my_type_get_transform(t3, transform), RES_OK);
d33_muld3(n, transform, y_ref_normal);
CHECK(d3_eq_eps(n, d3(tmp, 0, sqrt(2) / 2, sqrt(2) / 2), 1e-7), 1);
CHECK(d3_eq_eps(transform + 9, d3(tmp, 1, 3, 2 + sqrt(2)), 1e-7), 1);
/* release memory */
- CHECK(my_type_release(&t1), RES_OK);
- CHECK(my_type_release(&t2), RES_OK);
- CHECK(my_type_release(&t3), RES_OK);
+ CHECK(my_type_ref_put(t1), RES_OK);
+ CHECK(my_type_ref_put(t2), RES_OK);
+ CHECK(my_type_ref_put(t3), RES_OK);
check_memory_allocator(&allocator);
mem_shutdown_proxy_allocator(&allocator);
CHECK(mem_allocated_size(), 0);
diff --git a/src/test_sanim_node_transform.c b/src/test_sanim_node_transform.c
@@ -22,7 +22,7 @@ int
main(int argc, char** argv)
{
struct mem_allocator allocator;
- struct my_type t1, t2, t3, t;
+ struct my_type *t1, *t2, *t3, *t, *ptr;
double transl[3], rot[3];
double transform[12], transform_[12];
(void) argc, (void) argv;
@@ -30,99 +30,109 @@ main(int argc, char** argv)
mem_init_proxy_allocator(&allocator, &mem_default_allocator);
/* test a typical use in my_type */
- CHECK(my_type_init(&allocator, &t1), RES_OK);
- CHECK(my_type_init(&allocator, &t2), RES_OK);
+ CHECK(my_type_create(&allocator, &t1), RES_OK);
+ CHECK(my_type_create(&allocator, &t2), RES_OK);
- CHECK(my_type_add_child(&t1, &t2), RES_OK);
+ CHECK(my_type_add_child(t1, t2), RES_OK);
d3_splat(transl, +1);
- CHECK(my_type_set_translation(&t1, transl), RES_OK);
+ CHECK(my_type_set_translation(t1, transl), RES_OK);
d3_splat(transl, -1);
- CHECK(my_type_set_translation(&t2, transl), RES_OK);
+ CHECK(my_type_set_translation(t2, transl), RES_OK);
- CHECK(my_type_get_transform(&t2, transform), RES_OK);
+ CHECK(my_type_get_transform(t2, transform), RES_OK);
CHECK(d33_is_identity(transform), 1);
CHECK(d3_is_zero(transform + 9), 1);
d3(rot, PI, 0, 0);
CHECK(my_type_set_rotations(NULL, rot), RES_BAD_ARG);
- CHECK(my_type_set_rotations(&t1, NULL), RES_BAD_ARG);
- CHECK(my_type_set_rotations(&t1, rot), RES_OK);
- CHECK(my_type_set_rotations(&t2, rot), RES_OK);
+ CHECK(my_type_set_rotations(t1, NULL), RES_BAD_ARG);
+ CHECK(my_type_set_rotations(t1, rot), RES_OK);
+ CHECK(my_type_set_rotations(t2, rot), RES_OK);
d3(transl, 0, +1, 0);
- CHECK(my_type_set_translation(&t1, transl), RES_OK);
- CHECK(my_type_set_translation(&t2, transl), RES_OK);
+ CHECK(my_type_set_translation(t1, transl), RES_OK);
+ CHECK(my_type_set_translation(t2, transl), RES_OK);
- CHECK(my_type_get_transform(&t2, transform), RES_OK);
+ CHECK(my_type_get_transform(t2, transform), RES_OK);
CHECK(d33_is_identity_eps(transform, 1e-7), 1);
CHECK(d3_is_zero_eps(transform + 9, 1e-7), 1);
/* check translation & 1 rotation in a single node VS in 2 chained nodes */
d3(rot, 0.17, 0, 0);
d3(transl, 0.3, 2, -1);
- CHECK(my_type_init(&allocator, &t), RES_OK);
- CHECK(my_type_set_translation(&t, transl), RES_OK);
- CHECK(my_type_set_rotations(&t, rot), RES_OK);
- CHECK(my_type_get_transform(&t, transform), RES_OK);
- CHECK(my_type_init(&allocator, &t3), RES_OK);
- CHECK(my_type_add_child(&t2, &t3), RES_OK);
+ CHECK(my_type_create(&allocator, &t), RES_OK);
+ CHECK(my_type_set_translation(t, transl), RES_OK);
+ CHECK(my_type_set_rotations(t, rot), RES_OK);
+ CHECK(my_type_get_transform(t, transform), RES_OK);
+ CHECK(my_type_create(&allocator, &t3), RES_OK);
+ CHECK(my_type_add_child(t2, t3), RES_OK);
d3(rot, 0, 0, 0);
- CHECK(my_type_set_translation(&t1, transl), RES_OK);
- CHECK(my_type_set_rotations(&t1, rot), RES_OK);
+ CHECK(my_type_set_translation(t1, transl), RES_OK);
+ CHECK(my_type_set_rotations(t1, rot), RES_OK);
d3(transl, 0, 0, 0);
d3(rot, 0.17, 0, 0);
- CHECK(my_type_set_translation(&t2, transl), RES_OK);
- CHECK(my_type_set_rotations(&t2, rot), RES_OK);
- CHECK(my_type_get_transform(&t2, transform_), RES_OK);
+ CHECK(my_type_set_translation(t2, transl), RES_OK);
+ CHECK(my_type_set_rotations(t2, rot), RES_OK);
+ CHECK(my_type_get_transform(t2, transform_), RES_OK);
CHECK(d33_eq_eps(transform, transform_, 1e-7), 1);
CHECK(d3_eq_eps(transform + 9, transform_ + 9, 1e-7), 1);
/* check translation & 2 rotations in a single node VS in 2 chained nodes */
d3(rot, 0.17, -0.52, 0);
d3(transl, 0.3, 2, -1);
- CHECK(my_type_set_translation(&t, transl), RES_OK);
- CHECK(my_type_set_rotations(&t, rot), RES_OK);
- CHECK(my_type_get_transform(&t, transform), RES_OK);
+ CHECK(my_type_set_translation(t, transl), RES_OK);
+ CHECK(my_type_set_rotations(t, rot), RES_OK);
+ CHECK(my_type_get_transform(t, transform), RES_OK);
d3(rot, 0, 0, 0);
- CHECK(my_type_set_translation(&t1, transl), RES_OK);
- CHECK(my_type_set_rotations(&t1, rot), RES_OK);
+ CHECK(my_type_set_translation(t1, transl), RES_OK);
+ CHECK(my_type_set_rotations(t1, rot), RES_OK);
d3(transl, 0, 0, 0);
d3(rot, 0.17, 0, 0);
- CHECK(my_type_set_translation(&t2, transl), RES_OK);
- CHECK(my_type_set_rotations(&t2, rot), RES_OK);
+ CHECK(my_type_set_translation(t2, transl), RES_OK);
+ CHECK(my_type_set_rotations(t2, rot), RES_OK);
d3(rot, 0, -0.52, 0);
- CHECK(my_type_set_translation(&t3, transl), RES_OK);
- CHECK(my_type_set_rotations(&t3, rot), RES_OK);
- CHECK(my_type_get_transform(&t3, transform_), RES_OK);
+ CHECK(my_type_set_translation(t3, transl), RES_OK);
+ CHECK(my_type_set_rotations(t3, rot), RES_OK);
+ CHECK(my_type_get_transform(t3, transform_), RES_OK);
CHECK(d33_eq_eps(transform, transform_, 1e-7), 1);
CHECK(d3_eq_eps(transform + 9, transform_ + 9, 1e-7), 1);
/* check 1 node with 3 rotations VS 3 chained nodes with 1 rotation each */
d3(rot, 0.17, -0.52, 0.31);
d3(transl, 0.3, 2, -1);
- CHECK(my_type_set_translation(&t, transl), RES_OK);
- CHECK(my_type_set_rotations(&t, rot), RES_OK);
- CHECK(my_type_get_transform(&t, transform), RES_OK);
+ CHECK(my_type_set_translation(t, transl), RES_OK);
+ CHECK(my_type_set_rotations(t, rot), RES_OK);
+ CHECK(my_type_get_transform(t, transform), RES_OK);
d3(rot, 0.17, 0, 0);
- CHECK(my_type_set_translation(&t1, transl), RES_OK);
- CHECK(my_type_set_rotations(&t1, rot), RES_OK);
+ CHECK(my_type_set_translation(t1, transl), RES_OK);
+ CHECK(my_type_set_rotations(t1, rot), RES_OK);
d3(transl, 0, 0, 0);
d3(rot, 0, -0.52, 0);
- CHECK(my_type_set_translation(&t2, transl), RES_OK);
- CHECK(my_type_set_rotations(&t2, rot), RES_OK);
+ CHECK(my_type_set_translation(t2, transl), RES_OK);
+ CHECK(my_type_set_rotations(t2, rot), RES_OK);
d3(rot, 0, 0, 0.31);
- CHECK(my_type_set_translation(&t3, transl), RES_OK);
- CHECK(my_type_set_rotations(&t3, rot), RES_OK);
- CHECK(my_type_get_transform(&t3, transform_), RES_OK);
+ CHECK(my_type_set_translation(t3, transl), RES_OK);
+ CHECK(my_type_set_rotations(t3, rot), RES_OK);
+ CHECK(my_type_get_transform(t3, transform_), RES_OK);
+ CHECK(d33_eq_eps(transform, transform_, 1e-7), 1);
+ CHECK(d3_eq_eps(transform + 9, transform_ + 9, 1e-7), 1);
+
+ /* check 3 chained nodes with 1 rotation each VS a copy */
+ CHECK(my_type_ref_put(t), RES_OK);
+ CHECK(my_type_recursive_copy(&allocator, t1, &t), RES_OK);
+ CHECK(my_type_get_transform(t3, transform), RES_OK);
+ CHECK(my_type_get_child(t, 0, &ptr), RES_OK);
+ CHECK(my_type_get_child(ptr, 0, &ptr), RES_OK);
+ CHECK(my_type_get_transform(ptr, transform_), RES_OK);
CHECK(d33_eq_eps(transform, transform_, 1e-7), 1);
CHECK(d3_eq_eps(transform + 9, transform_ + 9, 1e-7), 1);
/* release memory */
- CHECK(my_type_release(&t1), RES_OK);
- CHECK(my_type_release(&t2), RES_OK);
- CHECK(my_type_release(&t3), RES_OK);
- CHECK(my_type_release(&t), RES_OK);
+ CHECK(my_type_ref_put(t1), RES_OK);
+ CHECK(my_type_ref_put(t2), RES_OK);
+ CHECK(my_type_ref_put(t3), RES_OK);
+ CHECK(my_type_ref_put(t), RES_OK);
check_memory_allocator(&allocator);
mem_shutdown_proxy_allocator(&allocator);
diff --git a/src/test_sanim_utils.c b/src/test_sanim_utils.c
@@ -15,45 +15,115 @@
#include "test_sanim_utils.h"
+#include <rsys/rsys.h>
#include <rsys/mem_allocator.h>
#include <rsys/logger.h>
+#include <rsys/dynamic_array.h>
+
+/* Define the darray_tmp data structure */
+#define DARRAY_NAME tmp
+#define DARRAY_DATA struct my_type*
+#include <rsys/dynamic_array.h>
#include <stdio.h>
res_T
-my_type_init(struct mem_allocator *allocator, struct my_type* t) {
- if (!t) return RES_BAD_ARG;
- /* init my stuff */
+my_type_create(struct mem_allocator *allocator, struct my_type** out)
+{
+ res_T res = RES_OK;
+ struct my_type* t;
+ struct mem_allocator* alloc;
+ if (!out) return RES_BAD_ARG;
+ alloc = allocator ? allocator : &mem_default_allocator;
+ t = MEM_CALLOC(alloc, 1, sizeof(struct my_type));
+ if (!t) {
+ res = RES_MEM_ERR;
+ goto error;
+ }
+
t->my_data = 0;
- /* init node stuff */
- return sanim_node_initialize(allocator, &t->node);
+ t->allocator = alloc;
+ ref_init(&t->ref);
+
+ res = sanim_node_initialize(alloc, &t->node);
+ if (res != RES_OK) return res;
+
+exit:
+ if (out) *out = t;
+ return res;
+error:
+ if (t) {
+ my_type_ref_put(t);
+ t = NULL;
+ }
+ goto exit;
}
res_T
-my_type_init_pivot
+my_type_pivot_create
(struct mem_allocator *allocator,
const struct sanim_pivot* pivot,
const struct sanim_tracking* tracking,
- struct my_type* t)
+ struct my_type** out)
{
- if (!t) return RES_BAD_ARG;
- /* init my stuff */
+ res_T res = RES_OK;
+ struct my_type* t;
+ struct mem_allocator* alloc;
+ if (!out) return RES_BAD_ARG;
+ alloc = allocator ? allocator : &mem_default_allocator;
+ t = MEM_CALLOC(alloc, 1, sizeof(struct my_type));
+ if (!t) {
+ res = RES_MEM_ERR;
+ goto error;
+ }
+
t->my_data = 0;
- /* init node stuff */
- return sanim_node_initialize_pivot(allocator, pivot, tracking, &t->node);
+ t->allocator = alloc;
+ ref_init(&t->ref);
+
+ res = sanim_node_initialize_pivot(alloc, pivot, tracking, &t->node);
+ if (res != RES_OK) goto error;
+
+exit:
+ if (out) *out = t;
+ return res;
+error:
+ if (t) {
+ my_type_ref_put(t);
+ t = NULL;
+ }
+ goto exit;
}
res_T
-my_type_copy
- (struct mem_allocator *allocator,
- const struct my_type* src,
- struct my_type* t)
+my_type_copy_create
+ (const struct my_type* src,
+ struct my_type** dst)
{
- if (!t||! src) return RES_BAD_ARG;
- /* init my stuff */
+ struct my_type* t;
+ res_T res = RES_OK;
+ if (!dst || ! src) return RES_BAD_ARG;
+ ASSERT(src->allocator);
+ t = MEM_CALLOC(src->allocator, 1, sizeof(struct my_type));
+ if (!t) {
+ res = RES_MEM_ERR;
+ goto error;
+ }
+ t->allocator = src->allocator;
+ ref_init(&t->ref);
+ res = sanim_node_copy_initialize(src->allocator, &src->node, &t->node);
+ if (res != RES_OK)
+ goto error;
t->my_data = src->my_data;
- /* init node stuff */
- return sanim_node_copy(allocator, &src->node, &t->node);
+exit:
+ *dst = t;
+ return res;
+error:
+ if (t) {
+ my_type_ref_put(t);
+ t = NULL;
+ }
+ goto exit;
}
res_T
@@ -93,20 +163,118 @@ my_type_get_child
return RES_OK;
}
+static res_T
+my_type_recursive_copy_
+ (struct mem_allocator *alloc,
+ const struct my_type* src,
+ struct darray_tmp* tmp,
+ struct my_type** dst)
+{
+ struct my_type* root;
+ size_t i, sz;
+ res_T res = RES_OK;
+
+ ASSERT(alloc && src && tmp && dst);
+ res = my_type_copy_create(src, &root);
+ if (res != RES_OK) goto error;
+ darray_tmp_push_back(tmp, &root);
+ if (res != RES_OK) goto error;
+ CHECK(my_type_get_children_count(src, &sz), RES_OK);
+ for (i = 0; i < sz; i++) {
+ struct my_type* child;
+ struct my_type* node;
+ CHECK(my_type_get_child(src, i, &child), RES_OK);
+ res = my_type_recursive_copy_(alloc, child, tmp, &node);
+ if (res != RES_OK) goto error;
+ my_type_add_child(root, node);
+ my_type_ref_put(node); /* node has is referenced by root */
+ }
+exit:
+ *dst = root;
+ return res;
+error:
+ root = NULL;
+ goto exit;
+}
+
res_T
-my_type_release(struct my_type* t) {
+my_type_recursive_copy
+(struct mem_allocator *allocator,
+ const struct my_type* src,
+ struct my_type** dst)
+{
+ struct darray_tmp tmp;
+ struct mem_allocator* alloc;
+ res_T res = RES_OK;
+
+ if (!dst || !src) return RES_BAD_ARG;
+ if (*dst == src) return RES_BAD_ARG;
+ alloc = allocator ? allocator : &mem_default_allocator;
+ darray_tmp_init(alloc, &tmp);
+ res = my_type_recursive_copy_(alloc, src, &tmp, dst);
+ if (res != RES_OK) goto error;
+ (*dst)->my_data = 0;
+ (*dst)->allocator = alloc;
+ ref_init(&(*dst)->ref);
+exit:
+ darray_tmp_release(&tmp);
+ return res;
+error:
+ {
+ struct my_type* const* children;
+ size_t i, sz;
+ sz = darray_tmp_size_get(&tmp);
+ children = darray_tmp_cdata_get(&tmp);
+ for (i = 0; i < sz; i++) {
+ struct my_type* node = children[i];
+ my_type_ref_put(node);
+ }
+ *dst = NULL;
+ goto exit;
+ }
+}
+
+static void
+my_type_release(ref_T* ref)
+{
+ size_t i, sz;
+ struct my_type* t = CONTAINER_OF(ref, struct my_type, ref);
+ if (t->node.data) {
+ CHECK(my_type_get_children_count(t, &sz), RES_OK);
+ for (i = 0; i < sz; i++) {
+ struct my_type* node;
+ CHECK(my_type_get_child(t, i, &node), RES_OK);
+ my_type_ref_put(node);
+ }
+ }
+ SANIM(node_release(&t->node));
+ MEM_RM(t->allocator, t);
+}
+
+res_T
+my_type_ref_get(struct my_type* t)
+{
if (!t) return RES_BAD_ARG;
- /* release my stuff */
- /* release node stuff */
- return sanim_node_release(&t->node);
+ ref_get(&t->ref);
+ return RES_OK;
+}
+
+res_T
+my_type_ref_put(struct my_type* t)
+{
+ if (!t) return RES_BAD_ARG;
+ ref_put(&t->ref, my_type_release);
+ return RES_OK;
}
res_T
my_type_add_child(struct my_type* t, struct my_type* child) {
+ res_T res = RES_OK;
if (!t || !child) return RES_BAD_ARG;
- /* release my stuff */
- /* release node stuff */
- return sanim_node_add_child(&t->node, &child->node);
+ res = sanim_node_add_child(&t->node, &child->node);
+ if (res != RES_OK) return res;
+ my_type_ref_get(child);
+ return RES_OK;
}
res_T
@@ -127,6 +295,11 @@ my_type_get_transform(struct my_type* t, double transform[12]) {
return sanim_node_get_transform(&t->node, transform);
}
+res_T
+my_type_solve_pivot(struct my_type* t, const double in_dir[3]) {
+ return sanim_node_solve_pivot(&t->node, in_dir);
+}
+
char
d3_is_zero_eps(const double v[3], const double eps) {
int x;
diff --git a/src/test_sanim_utils.h b/src/test_sanim_utils.h
@@ -19,6 +19,7 @@
#include "sanim.h"
#include <rsys/rsys.h>
+#include <rsys/ref_count.h>
struct mem_allocator;
@@ -28,27 +29,33 @@ struct mem_allocator;
struct my_type {
struct sanim_node node;
double my_data;
- /* may be some ref count mechanism */
+ struct mem_allocator *allocator;
+ ref_T ref;
};
res_T
-my_type_init(struct mem_allocator *allocator, struct my_type* t);
+my_type_create(struct mem_allocator *allocator, struct my_type** t);
res_T
-my_type_init_pivot
+my_type_pivot_create
(struct mem_allocator *allocator,
const struct sanim_pivot* pivot,
const struct sanim_tracking* tracking,
- struct my_type* t);
+ struct my_type** t);
+/* create a new node and copy content of src into it
+ * non-recursive copy (father/child links are not set)
+ * copy my_data, rotations, translation and possible pivot information */
res_T
-my_type_copy
- (struct mem_allocator *allocator,
- const struct my_type* src,
- struct my_type* t);
+my_type_copy_create
+ (const struct my_type* src,
+ struct my_type** dst);
res_T
-my_type_release(struct my_type* t);
+my_type_ref_get(struct my_type* t);
+
+res_T
+my_type_ref_put(struct my_type* t);
res_T
my_type_add_child(struct my_type* t, struct my_type* child);
@@ -63,6 +70,9 @@ res_T
my_type_get_transform(struct my_type* t, double transform[12]);
res_T
+my_type_solve_pivot(struct my_type* t, const double in_dir[3]);
+
+res_T
my_type_get_father
(const struct my_type* t,
const struct my_type** father);
@@ -76,6 +86,12 @@ my_type_get_child
const size_t idx,
const struct my_type** child);
+res_T
+my_type_recursive_copy
+ (struct mem_allocator *allocator,
+ const struct my_type* src,
+ struct my_type** dst);
+
/*******************************************************************************
* Utilities
******************************************************************************/