solstice-anim

Geometry animation library of the solstice app
git clone git://git.meso-star.com/solstice-anim.git
Log | Files | Refs | README | LICENSE

commit bfcb670e830daabbcd391dd9b1adad72f365b5db
parent 952635db2b5da82f32b5d876ff4fec145ccddba8
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date:   Wed, 12 Oct 2016 15:58:55 +0200

Shared code factorisation.

Diffstat:
Mcmake/CMakeLists.txt | 1+
Msrc/test_sanim_node_transform.c | 81-------------------------------------------------------------------------------
Asrc/test_sanim_utils.c | 114+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/test_sanim_utils.h | 71++++++++++++++++++++++++++++++++++++++++++++++++++---------------------
4 files changed, 165 insertions(+), 102 deletions(-)

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -91,6 +91,7 @@ if(NOT NO_TEST) function(new_test _name) add_executable(${_name} ${SANIM_SOURCE_DIR}/test_sanim_utils.h + ${SANIM_SOURCE_DIR}/test_sanim_utils.c ${SANIM_SOURCE_DIR}/${_name}.c) target_link_libraries(${_name} solstice-anim RSys) add_test(${_name} ${_name}) diff --git a/src/test_sanim_node_transform.c b/src/test_sanim_node_transform.c @@ -18,87 +18,6 @@ #include <rsys/double33.h> -struct my_type { - struct sanim_node node; - double my_data; - /* may be some ref count mechanism */ -}; - -static res_T -my_type_init(struct mem_allocator *allocator, struct my_type* t) { - if (!t) return RES_BAD_ARG; - /* init my stuff */ - t->my_data = 0; - /* init node stuff */ - return sanim_node_initialize(allocator, &t->node); -} - -static res_T -my_type_release(struct my_type* t) { - if (!t) return RES_BAD_ARG; - /* release my stuff */ - /* release node stuff */ - return sanim_node_release(&t->node); -} - -static res_T -my_type_add_child(struct my_type* t, struct my_type* child) { - if (!t || !child) return RES_BAD_ARG; - /* release my stuff */ - /* release node stuff */ - return sanim_node_add_child(&t->node, &child->node); -} - -static res_T -my_type_set_translation(struct my_type* t, const double translation[3]) { - if (!t || !translation) return RES_BAD_ARG; - return sanim_node_set_translation(&t->node, translation); -} - -static res_T -my_type_set_rotations(struct my_type* t, const double rotations[3]) { - if (!t || !rotations) return RES_BAD_ARG; - return sanim_node_set_rotations(&t->node, rotations); -} - -static res_T -my_type_get_world_transform(struct my_type* t, double transform[12]) { - if (!t || !transform) return RES_BAD_ARG; - return sanim_node_get_world_transform(&t->node, transform); -} - -static char -d3_is_zero_eps(const double v[3], const double eps) { - int x; - ASSERT(eps >= 0); - FOR_EACH(x, 0, 3) { - if (fabs(v[x]) > eps) return 0; - } - return 1; -} - -static char -d3_is_zero(const double v[3]) { - int x; - FOR_EACH(x, 0, 3) { - if (v[x]) return 0; - } - return 1; -} - -static char -d33_is_identity_eps(const double v[9], const double eps) { - int i = 0, x, y; - ASSERT(eps >= 0); - FOR_EACH(x, 0, 3) { - FOR_EACH(y, 0, 3) { - if (fabs(v[i] - (x == y ? 1 : 0)) > eps) return 0; - ++i; - } - } - return 1; -} - int main(int argc, char** argv) { diff --git a/src/test_sanim_utils.c b/src/test_sanim_utils.c @@ -0,0 +1,114 @@ +/* Copyright (C) CNRS 2016 +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#include "test_sanim_utils.h" + +#include <rsys/mem_allocator.h> +#include <rsys/logger.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 */ + t->my_data = 0; + /* init node stuff */ + return sanim_node_initialize(allocator, &t->node); +} + +res_T +my_type_release(struct my_type* t) { + if (!t) return RES_BAD_ARG; + /* release my stuff */ + /* release node stuff */ + return sanim_node_release(&t->node); +} + +res_T +my_type_add_child(struct my_type* t, struct my_type* child) { + if (!t || !child) return RES_BAD_ARG; + /* release my stuff */ + /* release node stuff */ + return sanim_node_add_child(&t->node, &child->node); +} + +res_T +my_type_set_translation(struct my_type* t, const double translation[3]) { + if (!t || !translation) return RES_BAD_ARG; + return sanim_node_set_translation(&t->node, translation); +} + +res_T +my_type_set_rotations(struct my_type* t, const double rotations[3]) { + if (!t || !rotations) return RES_BAD_ARG; + return sanim_node_set_rotations(&t->node, rotations); +} + +res_T +my_type_get_world_transform(struct my_type* t, double transform[12]) { + if (!t || !transform) return RES_BAD_ARG; + return sanim_node_get_world_transform(&t->node, transform); +} + +char +d3_is_zero_eps(const double v[3], const double eps) { + int x; + ASSERT(eps >= 0); + FOR_EACH(x, 0, 3) { + if (fabs(v[x]) > eps) return 0; + } + return 1; +} + +char +d3_is_zero(const double v[3]) { + int x; + FOR_EACH(x, 0, 3) { + if (v[x]) return 0; + } + return 1; +} + +char +d33_is_identity_eps(const double v[9], const double eps) { + int i = 0, x, y; + ASSERT(eps >= 0); + FOR_EACH(x, 0, 3) { + FOR_EACH(y, 0, 3) { + if (fabs(v[i] - (x == y ? 1 : 0)) > eps) return 0; + ++i; + } + } + return 1; +} + +void +log_stream(const char* msg, void* ctx) { + ASSERT(msg); + (void) msg, (void) ctx; + printf("%s\n", msg); +} + +void +check_memory_allocator(struct mem_allocator* allocator) { + if (MEM_ALLOCATED_SIZE(allocator)) { + char dump[512]; + MEM_DUMP(allocator, dump, sizeof(dump) / sizeof(char)); + fprintf(stderr, "%s\n", dump); + FATAL("Memory leaks\n"); + } +} + diff --git a/src/test_sanim_utils.h b/src/test_sanim_utils.h @@ -16,26 +16,55 @@ #ifndef TEST_SANIM_UTILS_H #define TEST_SANIM_UTILS_H -#include <rsys/mem_allocator.h> -#include <stdio.h> - -static INLINE void -log_stream(const char* msg, void* ctx) -{ - ASSERT(msg); - (void) msg, (void) ctx; - printf("%s\n", msg); -} - -static INLINE void -check_memory_allocator(struct mem_allocator* allocator) -{ - if (MEM_ALLOCATED_SIZE(allocator)) { - char dump[512]; - MEM_DUMP(allocator, dump, sizeof(dump) / sizeof(char)); - fprintf(stderr, "%s\n", dump); - FATAL("Memory leaks\n"); - } -} +#include "sanim.h" + +#include <rsys/rsys.h> + +struct mem_allocator; + +/******************************************************************************* + * Define a custom type of node based on sanim_node + ******************************************************************************/ +struct my_type { + struct sanim_node node; + double my_data; + /* may be some ref count mechanism */ +}; + +res_T +my_type_init(struct mem_allocator *allocator, struct my_type* t); + +res_T +my_type_release(struct my_type* t); + +res_T +my_type_add_child(struct my_type* t, struct my_type* child); + +res_T +my_type_set_translation(struct my_type* t, const double translation[3]); + +res_T +my_type_set_rotations(struct my_type* t, const double rotations[3]); + +res_T +my_type_get_world_transform(struct my_type* t, double transform[12]); + +/******************************************************************************* +* Utilities +******************************************************************************/ +char +d3_is_zero_eps(const double v[3], const double eps); + +char +d3_is_zero(const double v[3]); + +char +d33_is_identity_eps(const double v[9], const double eps); + +void +log_stream(const char* msg, void* ctx); + +void +check_memory_allocator(struct mem_allocator* allocator); #endif /* TEST_SANIM_UTILS_H */