rsys

Basic data structures and low-level features
git clone git://git.meso-star.fr/rsys.git
Log | Files | Refs | README | LICENSE

commit 1d3766083e45ee2a9551310adb3eb626d8201dda
parent 4649c018eece391c72410f47d7307ba5fdf39673
Author: vaplv <vaplv@free.fr>
Date:   Tue,  5 Jul 2016 16:54:29 +0200

Add and test the double<22|33|44> data types

Make the float<22|33|44> tests generic to the real type and use them to
test the double<22|33|44> data types.

Diffstat:
Mcmake/CMakeLists.txt | 12+++++++++---
Asrc/double22.h | 25+++++++++++++++++++++++++
Asrc/double33.h | 25+++++++++++++++++++++++++
Asrc/double44.h | 26++++++++++++++++++++++++++
Msrc/real22.h | 2+-
Msrc/real33.h | 4++--
Msrc/real44.h | 2+-
Msrc/realXY.h | 11+++++++----
Msrc/realXY_begin.h | 27+++++++++++++++++++++++++--
Msrc/realXY_end.h | 4++++
Msrc/realX_begin.h | 2+-
Asrc/test_double22.c | 19+++++++++++++++++++
Asrc/test_double33.c | 19+++++++++++++++++++
Asrc/test_double44.c | 19+++++++++++++++++++
Msrc/test_float22.c | 108++-----------------------------------------------------------------------------
Msrc/test_float33.c | 167+------------------------------------------------------------------------------
Msrc/test_float44.c | 359+------------------------------------------------------------------------------
Msrc/test_real2.h | 1-
Asrc/test_real22.h | 144+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/test_real33.h | 197+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/test_real4.h | 1+
Asrc/test_real44.h | 387+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
22 files changed, 918 insertions(+), 643 deletions(-)

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -35,8 +35,8 @@ include(rcmake) # Configure and define targets ################################################################################ set(VERSION_MAJOR 0) -set(VERSION_MINOR 3) -set(VERSION_PATCH 1) +set(VERSION_MINOR 4) +set(VERSION_PATCH 0) set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}) set(RSYS_FILES_SRC @@ -70,6 +70,9 @@ set(RSYS_FILES_INC_API double2.h double3.h double4.h + double22.h + double33.h + double44.h dynamic_array.h dynamic_array_char.h dynamic_array_double.h @@ -167,13 +170,16 @@ if(NOT NO_TEST) new_test(test_double2 ${MATH_LIB}) new_test(test_double3 ${MATH_LIB}) new_test(test_double4 ${MATH_LIB}) + new_test(test_double22) + new_test(test_double33 ${MATH_LIB}) + new_test(test_double44) new_test(test_dynamic_array rsys) new_test(test_float2 ${MATH_LIB}) new_test(test_float3 ${MATH_LIB}) new_test(test_float4 ${MATH_LIB}) new_test(test_float22) new_test(test_float33 ${MATH_LIB}) - new_test(test_float44 rsys) + new_test(test_float44) new_test(test_free_list rsys) new_test(test_func_name) new_test(test_hash_table rsys) diff --git a/src/double22.h b/src/double22.h @@ -0,0 +1,25 @@ +/* Copyright (C) 2013-2016 Vincent Forest (vaplv@free.fr) + * + * The RSys library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * The RSys library 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the RSys library. If not, see <http://www.gnu.org/licenses/>. */ + +#ifndef DOUBLE22_H +#define DOUBLE22_H + +#include "double2.h" + +#define REAL_TYPE__ double +#include "real22.h" + +#endif /* DOUBLE22_H */ + diff --git a/src/double33.h b/src/double33.h @@ -0,0 +1,25 @@ +/* Copyright (C) 2013-2016 Vincent Forest (vaplv@free.fr) + * + * The RSys library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * The RSys library 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the RSys library. If not, see <http://www.gnu.org/licenses/>. */ + +#ifndef DOUBLE33_H +#define DOUBLE33_H + +#include "double3.h" + +#define REAL_TYPE__ double +#include "real33.h" + +#endif /* DOUBLE33_H */ + diff --git a/src/double44.h b/src/double44.h @@ -0,0 +1,26 @@ +/* Copyright (C) 2013-2016 Vincent Forest (vaplv@free.fr) + * + * The RSys library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * The RSys library 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the RSys library. If not, see <http://www.gnu.org/licenses/>. */ + +#ifndef DOUBLE44_H +#define DOUBLE44_H + +#include "double4.h" +#include "double33.h" + +#define REAL_TYPE__ double +#include "real44.h" + +#endif /* DOUBLE44_H */ + diff --git a/src/real22.h b/src/real22.h @@ -25,7 +25,7 @@ /* Specific real22 funcs */ static FINLINE REAL_TYPE__* -CONCAT(REAL_LETTER__, 22) +REALXY_CTOR__ (REAL_TYPE__* dst, const REAL_TYPE__ a, const REAL_TYPE__ b, diff --git a/src/real33.h b/src/real33.h @@ -25,7 +25,7 @@ /* Specific real33 funcs */ static FINLINE REAL_TYPE__* -CONCAT(REAL_LETTER__, 33) +REALXY_CTOR__ (REAL_TYPE__* dst, const REAL_TYPE__ a, const REAL_TYPE__ b, const REAL_TYPE__ c, const REAL_TYPE__ d, const REAL_TYPE__ e, const REAL_TYPE__ f, @@ -103,7 +103,7 @@ f33_rotation /* XYZ norm */ } static INLINE REAL_TYPE__* -f33_rotation_axis_angle +REALXY_FUNC__(rotation_axis_angle) (REAL_TYPE__* dst, const REAL_TYPE__ axis[3], /* Should be normalized */ const REAL_TYPE__ angle) /* In radian */ diff --git a/src/real44.h b/src/real44.h @@ -33,7 +33,7 @@ /* Specific REAL_TYPE__44 funcs*/ static FINLINE REAL_TYPE__* -CONCAT(REAL_LETTER__, 44) +REALXY_CTOR__ (REAL_TYPE__* dst, const REAL_TYPE__ a, const REAL_TYPE__ b, const REAL_TYPE__ c, const REAL_TYPE__ d, const REAL_TYPE__ e, const REAL_TYPE__ f, const REAL_TYPE__ g, const REAL_TYPE__ h, diff --git a/src/realXY.h b/src/realXY.h @@ -193,7 +193,10 @@ REALXY_FUNC__(eq)(const REAL_TYPE__* a, const REAL_TYPE__* b) } static FINLINE char -REALXY_FUNC__(eq_eps)(const REAL_TYPE__* a, const REAL_TYPE__* b, const REAL_TYPE__ eps) +REALXY_FUNC__(eq_eps) + (const REAL_TYPE__* a, + const REAL_TYPE__* b, + const REAL_TYPE__ eps) { char is_eq = 1; int x = 0; @@ -208,7 +211,7 @@ REALXY_FUNC__(eq_eps)(const REAL_TYPE__* a, const REAL_TYPE__* b, const REAL_TYP } static FINLINE REAL_TYPE__* -REALXY_FUNC__(CONCAT(mulf, REALX_DIMENSION__)) +REALXY_REALX_FUNC__(mul) (REAL_TYPE__* dst, const REAL_TYPE__* mat, const REAL_TYPE__* vec) { REAL_TYPE__ row[REALX_DIMENSION__]; @@ -235,7 +238,7 @@ REALXY_FUNC__(mul)(REAL_TYPE__* dst, const REAL_TYPE__* mat, const REAL_TYPE__ b } static FINLINE REAL_TYPE__* -REALX_FUNC__(CONCAT(CONCAT(mulf, REALX_DIMENSION__), REALY_DIMENSION__)) +REALX_REALXY_FUNC__(mul) (REAL_TYPE__* dst, const REAL_TYPE__* vec, const REAL_TYPE__* mat) { REAL_TYPE__ tmp[REALX_DIMENSION__]; @@ -266,7 +269,7 @@ REALXY_FUNC__(transpose)(REAL_TYPE__* dst, const REAL_TYPE__* src) } static FINLINE REAL_TYPE__* -REALXY_FUNC__(CONCAT(CONCAT(mulf, REALX_DIMENSION__), REALY_DIMENSION__)) +REALXY_REALXY_FUNC__(mul) (REAL_TYPE__* dst, const REAL_TYPE__* a, const REAL_TYPE__* b) { REAL_TYPE__ tmp[REALX_DIMENSION__ * REALY_DIMENSION__]; diff --git a/src/realXY_begin.h b/src/realXY_begin.h @@ -19,7 +19,6 @@ #endif #define REALXY_BEGIN_H - /* Check that the expected arguments are defined */ #if !defined(REALX_DIMENSION__) \ || !defined(REALY_DIMENSION__) \ @@ -29,6 +28,10 @@ #if defined(REALXY_FUNC__) \ || defined(REALY_FUNC__) \ + || defined(REALXY_CTOR__) \ + || defined(REALXY_REALX_FUNC__) \ + || defined(REALX_REALXY_FUNC__) \ + || defined(REALXY_REALXY_FUNC__) \ || defined(SIZEOF_REALXY__) #error Unexpected macro definition #endif @@ -37,8 +40,28 @@ #define REALXY_FUNC__(Func) \ CONCAT(CONCAT(CONCAT(CONCAT \ (REAL_LETTER__, REALX_DIMENSION__), REALY_DIMENSION__), _), Func) + +/* Define the function name generator for the realY functions */ #define REALY_FUNC__(Func) \ - CONCAT(CONCAT(CONCAT(f, REALY_DIMENSION__), _), Func) + CONCAT(CONCAT(CONCAT(REAL_LETTER__, REALY_DIMENSION__), _), Func) + +/* Define the name generator for the realXY x realX -> realX functions */ +#define REALXY_REALX_FUNC__(Func) \ + REALXY_FUNC__(CONCAT(CONCAT(mul, REAL_LETTER__), REALX_DIMENSION__)) + +/* Define the name generator for the realX x realXY -> realXY functions */ +#define REALX_REALXY_FUNC__(Func) \ + REALX_FUNC__(CONCAT(CONCAT(CONCAT( \ + mul, REAL_LETTER__), REALX_DIMENSION__), REALY_DIMENSION__)) + +/* Define the name generator for the realXY x realXY -> realXY functions */ +#define REALXY_REALXY_FUNC__(Func) \ + REALXY_FUNC__(CONCAT(CONCAT(CONCAT( \ + Func, REAL_LETTER__), REALX_DIMENSION__), REALY_DIMENSION__)) + +/* Define the realXY constructor name */ +#define REALXY_CTOR__ \ + CONCAT(CONCAT(REAL_LETTER__, REALX_DIMENSION__), REALY_DIMENSION__) #define SIZEOF_REALXY__ sizeof(REAL_TYPE__[REALX_DIMENSION__*REALY_DIMENSION__]) diff --git a/src/realXY_end.h b/src/realXY_end.h @@ -21,6 +21,10 @@ #undef REALY_FUNC__ #undef REALXY_FUNC__ +#undef REALXY_CTOR__ +#undef REALX_REALXY_FUNC__ +#undef REALXY_REALX_FUNC__ +#undef REALXY_REALXY_FUNC__ #undef SIZEOF_REALXY__ #undef REALXY_BEGIN_H diff --git a/src/realX_begin.h b/src/realX_begin.h @@ -60,7 +60,7 @@ #define REALX_FUNC__(Func) \ CONCAT(CONCAT(CONCAT(REAL_LETTER__, REALX_DIMENSION__), _), Func) -/* Define the function name generator for the realX x real -> realX function */ +/* Define the name generator for the realX x real -> realX functions */ #define REALX_REAL_FUNC__(Func) CONCAT(REALX_FUNC__(Func), REAL_LETTER__) /* Define the realX constructor from reals */ diff --git a/src/test_double22.c b/src/test_double22.c @@ -0,0 +1,19 @@ +/* Copyright (C) 2013-2016 Vincent Forest (vaplv@free.fr) + * + * The RSys library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * The RSys library 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the RSys library. If not, see <http://www.gnu.org/licenses/>. */ + +#include "double22.h" +#define REAL_TYPE__ double +#include "test_real22.h" + diff --git a/src/test_double33.c b/src/test_double33.c @@ -0,0 +1,19 @@ +/* Copyright (C) 2013-2016 Vincent Forest (vaplv@free.fr) + * + * The RSys library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * The RSys library 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the RSys library. If not, see <http://www.gnu.org/licenses/>. */ + +#include "double33.h" +#define REAL_TYPE__ double +#include "test_real33.h" + diff --git a/src/test_double44.c b/src/test_double44.c @@ -0,0 +1,19 @@ +/* Copyright (C) 2013-2016 Vincent Forest (vaplv@free.fr) + * + * The RSys library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * The RSys library 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the RSys library. If not, see <http://www.gnu.org/licenses/>. */ + +#include "double44.h" +#define REAL_TYPE__ double +#include "test_real44.h" + diff --git a/src/test_float22.c b/src/test_float22.c @@ -14,110 +14,6 @@ * along with the RSys library. If not, see <http://www.gnu.org/licenses/>. */ #include "float22.h" -#include "rsys.h" -#include <float.h> - -#define CHECK_F2(A, B) \ - { \ - const float* a__ = (A); \ - const float* b__ = (B); \ - int i__; \ - FOR_EACH(i__, 0, 2) \ - CHECK(a__[i__], b__[i__]); \ - } (void)0 -#define CHECK_F22(A, B) \ - { \ - const float* a__ = (A); \ - const float* b__ = (B); \ - int i__; \ - FOR_EACH(i__, 0, 4) \ - CHECK(a__[i__], b__[i__]); \ - } (void)0 - -int -main(int argc, char** argv) -{ - float a[4], b[4], dst[4], c[4]; - int i; - (void)argc, (void)argv; - - f22_set(c, f22_splat(a, -1.f)); - FOR_EACH(i, 0, 4) { - CHECK(a[i], -1.f); - CHECK(c[i], -1.f); - } - f22_set(a, f22(c, 0.f, 1.f, 2.f, 3.f)); - FOR_EACH(i, 0, 4) { - CHECK(a[i], (float)i); - } - CHECK_F22(f22_set_identity(a), f22(c, 1.f, 0.f, 0.f, 1.f)); - CHECK_F22(a, f22(c, 1.f, 0.f, 0.f, 1.f)); - - f22_splat(a, -1.f); - CHECK_F22(f22_set_row(a, f2(c, 0.f, 1.f), 0), f22(c, 0.f, -1.f, 1.f, -1.f)); - CHECK_F22(a, f22(c, 0.f, -1.f, 1.f, -1.f)); - CHECK_F22(f22_set_row(a, f2(c, 2.f, 3.f), 1), f22(c, 0.f, 2.f, 1.f, 3.f)); - CHECK_F22(a, f22(c, 0.f, 2.f, 1.f, 3.f)); - - CHECK_F22(f22_transpose(a, a), f22(c, 0.f, 1.f, 2.f, 3.f)); - CHECK_F22(a, f22(c, 0.f, 1.f, 2.f, 3.f)); - CHECK_F22(f22_transpose(b, a), f22(c, 0.f, 2.f, 1.f, 3.f)); - CHECK_F22(b, f22(c, 0.f, 2.f, 1.f, 3.f)); - - f22_splat(a, -1.f); - CHECK_F22(f22_set_col(a, f2(c, 0.f, 1.f), 0), f22(c, 0.f, 1.f, -1.f, -1.f)); - CHECK_F22(a, f22(c, 0.f, 1.f, -1.f, -1.f)); - CHECK_F22(f22_set_col(a, f2(c, 2.f, 3.f), 1), f22(c, 0.f, 1.f, 2.f, 3.f)); - CHECK_F22(a, f22(c, 0.f, 1.f, 2.f, 3.f)); - - CHECK_F2(f22_row(b, a, 0), f2(c, 0.f, 2.f)); - CHECK_F2(f22_row(b, a, 1), f2(c, 1.f, 3.f)); - - CHECK_F2(f22_col(b + 2, a, 0), f2(c, 0.f, 1.f)); - CHECK_F2(f22_col(b, a, 1), f2(c, 2.f, 3.f)); - - CHECK_F2(f22_col_ptr(a, 0), f2(c, 0.f, 1.f)); - CHECK_F2(f22_col_ptr(a, 1), f2(c, 2.f, 3.f)); - CHECK_F2(f22_col_cptr(a, 0), f2(c, 0.f, 1.f)); - CHECK_F2(f22_col_cptr(a, 1), f2(c, 2.f, 3.f)); - - f22(a, 1.f, 2.f, 3.f, 4.f); - CHECK_F2(f22_mulf2(dst, a, f2(c, 1.f, 2.f)), f2(c, 7.f, 10.f)); - CHECK_F2(dst, f2(c, 7.f, 10.f)); - CHECK_F2(f2_mulf22(dst, f2(c, 1.f, 2.f), a), f2(c, 5.f, 11.f)); - CHECK_F2(dst, f2(c, 5.f, 11.f)); - CHECK_F22(f22_mul(dst, a, -1.f), f22(c, -1.f, -2.f, -3.f, -4.f)); - CHECK_F22(dst, f22(c, -1.f, -2.f, -3.f, -4.f)); - - f22(b, 2.f, 9.f, 8.f, 1.f); - CHECK_F22(f22_mulf22(dst, a, b), f22(c, 29.f, 40.f, 11.f, 20.0f)); - CHECK_F22(dst, f22(c, 29.f, 40.f, 11.f, 20.0f)); - CHECK_F22(f22_mulf22(b, a, b), f22(c, 29.f, 40.f, 11.f, 20.0f)); - CHECK_F22(b, f22(c, 29.f, 40.f, 11.f, 20.0f)); - - f22(a, 0.f, 1.f, 2.f, 3.f); - f22(b, 1.f, 2.f, 3.f, 4.f); - CHECK_F22(f22_add(dst, a, b), f22(c, 1.f, 3.f, 5.f, 7.f)); - CHECK_F22(dst, f22(c, 1.f, 3.f, 5.f, 7.f)); - CHECK_F22(f22_sub(dst, dst, b), f22(c, 0.f, 1.f, 2.f, 3.f)); - CHECK_F22(dst, f22(c, 0.f, 1.f, 2.f, 3.f)); - CHECK_F22(f22_minus(a, b), f22(c, -1.f, -2.f, -3.f, -4.f)); - CHECK_F22(a, f22(c, -1.f, -2.f, -3.f, -4.f)); - - f22_set(a, b); - CHECK(f22_eq(a, b), 1); - f22_add(a, a, f22_splat(c, FLT_EPSILON)); - CHECK(f22_eq(a, b), 0); - CHECK(f22_eq_eps(a, b, FLT_EPSILON), 1); - CHECK(f22_eq_eps(a, b, FLT_EPSILON * 0.9f), 0); - - f22_set(a, f22(c, 1, 3, 2, 4)); - CHECK(f22_det(a), -2.f); - CHECK(f22_inverse(b, a), -2.f); - CHECK_F22(b, f22(c, -2.f, 1.5f, 1.f, -0.5f)); - CHECK(f22_invtrans(a, a), -2.f); - CHECK_F22(a, f22(c, -2.f, 1.f, 1.5f, -0.5f)); - - return 0; -} +#define REAL_TYPE__ float +#include "test_real22.h" diff --git a/src/test_float33.c b/src/test_float33.c @@ -14,169 +14,6 @@ * along with the RSys library. If not, see <http://www.gnu.org/licenses/>. */ #include "float33.h" -#include "rsys.h" -#include <float.h> +#define REAL_TYPE__ float +#include "test_real33.h" -#define CHECK_F3(A, B) \ - { \ - const float* a__ = (A); \ - const float* b__ = (B); \ - int i__; \ - FOR_EACH(i__, 0, 3) \ - CHECK(a__[i__], b__[i__]); \ - } (void)0 -#define CHECK_F33(A, B) \ - { \ - const float* a__ = (A); \ - const float* b__ = (B); \ - int i__; \ - FOR_EACH(i__, 0, 9) \ - CHECK(a__[i__], b__[i__]); \ - } (void)0 - -int -main(int argc, char** argv) -{ - float a[9], b[9], dst[9], c[9]; - int i; - (void)argc, (void)argv; - - f33_set(a, f33_splat(c, -1.f)); - FOR_EACH(i, 0, 9) { - CHECK(a[i], -1.f); - CHECK(c[i], -1.f); - } - f33(a, 0.f, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f); - FOR_EACH(i, 0, 9) { - CHECK(a[i], (float)i); - } - CHECK_F33 - (f33_set_identity(a), - f33(c, 1.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f, 1.f)); - CHECK_F33(a, f33(c, 1.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f, 1.f)); - - f33_splat(a, -1.f); - CHECK_F33 - (f33_set_row(a, f3(c, 0.f, 1.f, 2.f), 0), - f33(c, 0.f, -1.f, -1.f, 1.f, -1.f, -1.f, 2.f, -1.f, -1.f)); - CHECK_F33(a, f33(c, 0.f, -1.f, -1.f, 1.f, -1.f, -1.f, 2.f, -1.f, -1.f)); - CHECK_F33 - (f33_set_row(a, f3(c, 3.f, 4.f, 5.f), 1), - f33(c, 0.f, 3.f, -1.f, 1.f, 4.f, -1.f, 2.f, 5.f, -1.f)); - CHECK_F33(a, f33(c, 0.f, 3.f, -1.f, 1.f, 4.f, -1.f, 2.f, 5.f, -1.f)); - CHECK_F33 - (f33_set_row(a, f3(c, 6.f, 7.f, 8.f), 2), - f33(c, 0.f, 3.f, 6.f, 1.f, 4.f, 7.f, 2.f, 5.f, 8.f)); - CHECK_F33(a, f33(c, 0.f, 3.f, 6.f, 1.f, 4.f, 7.f, 2.f, 5.f, 8.f)); - - CHECK_F33 - (f33_transpose(a, a), - f33(c, 0.f, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f)); - CHECK_F33(a, f33(c, 0.f, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f)); - CHECK_F33 - (f33_transpose(b, a), - f33(c, 0.f, 3.f, 6.f, 1.f, 4.f, 7.f, 2.f, 5.f, 8.f)); - CHECK_F33(b, f33(c, 0.f, 3.f, 6.f, 1.f, 4.f, 7.f, 2.f, 5.f, 8.f)); - - f33_splat(a, -1.f); - CHECK_F33 - (f33_set_col(a, f3(c, 0.f, 1.f, 2.f), 0), - f33(c, 0.f, 1.f, 2.f, -1.f, -1.f, -1.f, -1.f, -1.f, -1.f)); - CHECK_F33(a, f33(c, 0.f, 1.f, 2.f, -1.f, -1.f, -1.f, -1.f, -1.f, -1.f)); - CHECK_F33 - (f33_set_col(a, f3(c, 3.f, 4.f, 5.f), 1), - f33(c, 0.f, 1.f, 2.f, 3.f, 4.f, 5.f, -1.f, -1.f, -1.f)); - CHECK_F33(a, f33(c, 0.f, 1.f, 2.f, 3.f, 4.f, 5.f, -1.f, -1.f, -1.f)); - CHECK_F33 - (f33_set_col(a, f3(c, 6.f, 7.f, 8.f), 2), - f33(c, 0.f, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f)); - CHECK_F33(a, f33(c, 0.f, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f)); - - CHECK_F3(f33_row(b, a, 0), f3(c, 0.f, 3.f, 6.f)); - CHECK_F3(b, f3(c, 0.f, 3.f, 6.f)); - CHECK_F3(f33_row(b, a, 1), f3(c, 1.f, 4.f, 7.f)); - CHECK_F3(b, f3(c, 1.f, 4.f, 7.f)); - CHECK_F3(f33_row(b, a, 2), f3(c, 2.f, 5.f, 8.f)); - CHECK_F3(b, f3(c, 2.f, 5.f, 8.f)); - - CHECK_F3(f33_col(b + 2, a, 0), f3(c, 0.f, 1.f, 2.f)); - CHECK_F3(b + 2, f3(c, 0.f, 1.f, 2.f)); - CHECK_F3(f33_col(b + 1, a, 1), f3(c, 3.f, 4.f, 5.f)); - CHECK_F3(b + 1, f3(c, 3.f, 4.f, 5.f)); - CHECK_F3(f33_col(b + 5, a, 2), f3(c, 6.f, 7.f, 8.f)); - CHECK_F3(b + 5, f3(c, 6.f, 7.f, 8.f)); - - CHECK_F3(f33_col_ptr(a, 0), f3(c, 0.f, 1.f, 2.f)); - CHECK_F3(f33_col_ptr(a, 1), f3(c, 3.f, 4.f, 5.f)); - CHECK_F3(f33_col_ptr(a, 2), f3(c, 6.f, 7.f, 8.f)); - CHECK_F3(f33_col_cptr(a, 0), f3(c, 0.f, 1.f, 2.f)); - CHECK_F3(f33_col_cptr(a, 1), f3(c, 3.f, 4.f, 5.f)); - CHECK_F3(f33_col_cptr(a, 2), f3(c, 6.f, 7.f, 8.f)); - - f33(a, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f, 9.f); - CHECK_F3(f33_mulf3(dst, a, f3(c, 1.f, 2.f, 3.f)), f3(c, 30.f, 36.f, 42.f)); - CHECK_F3(dst, f3(c, 30.f, 36.f, 42.f)); - CHECK_F3(f3_mulf33(dst, f3(c, 1.f, 2.f, 3.f), a), f3(c, 14.f, 32.f, 50.f)); - CHECK_F3(dst, f3(c, 14.f, 32.f, 50.f)); - CHECK_F3 - (f33_mul(dst, a, -1.f), - f33(c, -1.f, -2.f, -3.f, -4.f, -5.f, -6.f, -7.f, -8.f, -9.f)); - CHECK_F33(dst, f33(c, -1.f, -2.f, -3.f, -4.f, -5.f, -6.f, -7.f, -8.f, -9.f)); - - f33(b, 2.f, 9.f, 8.f, 1.f, -2.f, 2.f, 1.f, -8.f, -4.f); - CHECK_F33 - (f33_mulf33(dst, a, b), - f33(c, 94.f, 113.f, 132.f, 7.f, 8.f, 9.f, -59.f, -70.f,-81.f)); - CHECK_F33(dst, f33(c, 94.f, 113.f, 132.f, 7.f, 8.f, 9.f, -59.f, -70.f,-81.f)); - CHECK_F33 - (f33_mulf33(a, a, b), - f33(c, 94.f, 113.f, 132.f, 7.f, 8.f, 9.f, -59.f, -70.f, -81.f)); - CHECK_F33(a, f33(c, 94.f, 113.f, 132.f, 7.f, 8.f, 9.f, -59.f, -70.f, -81.f)); - f33(a, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f, 9.f); - CHECK_F33 - (f33_mulf33(b, a, b), - f33(c, 94.f, 113.f, 132.f, 7.f, 8.f, 9.f, -59.f, -70.f, -81.f)); - CHECK_F33(b, f33(c, 94.f, 113.f, 132.f, 7.f, 8.f, 9.f, -59.f, -70.f, -81.f)); - f33(b, 2.f, 9.f, 8.f, 1.f, -2.f, 2.f, 1.f, -8.f, -4.f); - - f33(a, 0.f, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f); - f33(b, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f, 9.f); - CHECK_F33 - (f33_add(dst, a, b), - f33(c, 1.f, 3.f, 5.f, 7.f, 9.f, 11.f, 13.f, 15.f, 17.f)); - CHECK_F33(dst, f33(c, 1.f, 3.f, 5.f, 7.f, 9.f, 11.f, 13.f, 15.f, 17.f)); - CHECK_F33 - (f33_sub(dst, dst, b), - f33(c, 0.f, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f)); - CHECK_F33(dst, f33(c, 0.f, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f)); - CHECK_F33 - (f33_minus(a, b), - f33(c, -1.f, -2.f, -3.f, -4.f, -5.f, -6.f, -7.f, -8.f, -9.f)); - CHECK_F33(a, f33(c, -1.f, -2.f, -3.f, -4.f, -5.f, -6.f, -7.f, -8.f, -9.f)); - - f33_set(a, b); - CHECK(f33_eq(a, b), 1); - f33_add(a, a, f33_splat(c, FLT_EPSILON)); - CHECK(f33_eq(a, b), 0); - CHECK(f33_eq_eps(a, b, FLT_EPSILON), 1); - CHECK(f33_eq_eps(a, b, FLT_EPSILON * 0.9f), 0); - - f33(a, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 3.f, -4.f, 9.f); - CHECK(f33_det(a), -60.f); - CHECK(f33_inverse(b, a), -60.f); - f33_mulf33(dst, a, b); - CHECK(f33_eq_eps(dst, f33(c, 1.0f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f, 1.f), - 1.e-6f), 1); - CHECK(f33_invtrans(a, a), -60.f); - CHECK_F33 - (a, f33(c, b[0], b[3], b[6], b[1], b[4], b[7], b[2], b[5], b[8])); - - f3(c, 0.666667f, 0.333333f, 0.666667f); - f33_rotation_axis_angle(a, c, 0.349066f); - CHECK(f33_eq_eps(a, f33(c, - 0.966496f, 0.241415f, -0.0872034f, - -0.214612f, 0.946393f, 0.241415f, - 0.14081f, -0.214612f, 0.966496f), 1.e-6f), 1); - - return 0; -} diff --git a/src/test_float44.c b/src/test_float44.c @@ -14,361 +14,6 @@ * along with the RSys library. If not, see <http://www.gnu.org/licenses/>. */ #include "float44.h" -#include "rsys.h" -#include <float.h> +#define REAL_TYPE__ float +#include "test_real44.h" -#define CHECK_F4(A, B) \ - { \ - const float* a__ = (A); \ - const float* b__ = (B); \ - int i__; \ - FOR_EACH(i__, 0, 4) \ - CHECK(a__[i__], b__[i__]); \ - } (void)0 -#define CHECK_F44(A, B) \ - { \ - const float* a__ = (A); \ - const float* b__ = (B); \ - int i__; \ - FOR_EACH(i__, 0, 16) \ - CHECK(a__[i__], b__[i__]); \ - } (void)0 - -int -main(int argc, char** argv) -{ - float a[16], b[16], dst[16], c[16]; - int i; - (void)argc, (void)argv; - - f44_set(a, f44_splat(c, -1.f)); - FOR_EACH(i, 0, 16) { - CHECK(a[i], -1.f); - CHECK(c[i], -1.f); - } - f44 - (a, - 0.f, 1.f, 2.f, 3.f, - 4.f, 5.f, 6.f, 7.f, - 8.f, 9.f, 10.f, 11.f, - 12.f, 13.f, 14.f, 15.f); - FOR_EACH(i, 0, 16) { - CHECK(a[i], (float)i); - } - CHECK_F44 - (f44_set_identity(a),f44(c, - 1.f, 0.f, 0.f, 0.f, - 0.f, 1.f, 0.f, 0.f, - 0.f, 0.f, 1.f, 0.f, - 0.f, 0.f, 0.f, 1.f)); - CHECK_F44 - (a, f44(c, - 1.f, 0.f, 0.f, 0.f, - 0.f, 1.f, 0.f, 0.f, - 0.f, 0.f, 1.f, 0.f, - 0.f, 0.f, 0.f, 1.f)); - - f44_splat(a, -1.f); - CHECK_F44 - (f44_set_row(a, f4(c, 0.f, 1.f, 2.f, 3.f), 0), f44(c, - 0.f, -1.f, -1.f, -1.f, - 1.f, -1.f, -1.f, -1.f, - 2.f, -1.f, -1.f, -1.f, - 3.f, -1.f, -1.f, -1.f)); - CHECK_F44 - (a, f44(c, - 0.f, -1.f, -1.f, -1.f, - 1.f, -1.f, -1.f, -1.f, - 2.f, -1.f, -1.f, -1.f, - 3.f, -1.f, -1.f, -1.f)); - CHECK_F44 - (f44_set_row(a, f4(c, 4.f, 5.f, 6.f, 7.f), 1), f44(c, - 0.f, 4.f, -1.f, -1.f, - 1.f, 5.f, -1.f, -1.f, - 2.f, 6.f, -1.f, -1.f, - 3.f, 7.f, -1.f, -1.f)); - CHECK_F44 - (a, f44(c, - 0.f, 4.f, -1.f, -1.f, - 1.f, 5.f, -1.f, -1.f, - 2.f, 6.f, -1.f, -1.f, - 3.f, 7.f, -1.f, -1.f)); - CHECK_F44 - (f44_set_row(a, f4(c, 8.f, 9.f, 10.f, 11.f), 2),f44(c, - 0.f, 4.f, 8.f, -1.f, - 1.f, 5.f, 9.f, -1.f, - 2.f, 6.f, 10.f, -1.f, - 3.f, 7.f, 11.f, -1.f)); - CHECK_F44 - (a, f44(c, - 0.f, 4.f, 8.f, -1.f, - 1.f, 5.f, 9.f, -1.f, - 2.f, 6.f, 10.f, -1.f, - 3.f, 7.f, 11.f, -1.f)); - CHECK_F44 - (f44_set_row(a, f4(c, 12.f, 13.f, 14.f, 15.f), 3), f44(c, - 0.f, 4.f, 8.f, 12.f, - 1.f, 5.f, 9.f, 13.f, - 2.f, 6.f, 10.f, 14.f, - 3.f, 7.f, 11.f, 15.f)); - CHECK_F44 - (a, f44(c, - 0.f, 4.f, 8.f, 12.f, - 1.f, 5.f, 9.f, 13.f, - 2.f, 6.f, 10.f, 14.f, - 3.f, 7.f, 11.f, 15.f)); - - CHECK_F44 - (f44_transpose(a, a), f44(c, - 0.f, 1.f, 2.f, 3.f, - 4.f, 5.f, 6.f, 7.f, - 8.f, 9.f, 10.f, 11.f, - 12.f, 13.f, 14.f, 15.f)); - CHECK_F44 - (a, f44(c, - 0.f, 1.f, 2.f, 3.f, - 4.f, 5.f, 6.f, 7.f, - 8.f, 9.f, 10.f, 11.f, - 12.f, 13.f, 14.f, 15.f)); - CHECK_F44 - (f44_transpose(b, a),f44(c, - 0.f, 4.f, 8.f, 12.f, - 1.f, 5.f, 9.f, 13.f, - 2.f, 6.f, 10.f, 14.f, - 3.f, 7.f, 11.f, 15.f)); - CHECK_F44 - (b, f44(c, - 0.f, 4.f, 8.f, 12.f, - 1.f, 5.f, 9.f, 13.f, - 2.f, 6.f, 10.f, 14.f, - 3.f, 7.f, 11.f, 15.f)); - - f44_splat(a, -1.f); - CHECK_F44 - (f44_set_col(a, f4(c, 0.f, 1.f, 2.f, 3.f), 0), f44(c, - 0.f, 1.f, 2.f, 3.f, - -1.f, -1.f, -1.f, -1.f, - -1.f, -1.f, -1.f, -1.f, - -1.f, -1.f, -1.f, -1.f)); - CHECK_F44 - (a, f44(c, - 0.f, 1.f, 2.f, 3.f, - -1.f, -1.f, -1.f, -1.f, - -1.f, -1.f, -1.f, -1.f, - -1.f, -1.f, -1.f, -1.f)); - CHECK_F44 - (f44_set_col(a, f4(c, 4.f, 5.f, 6.f, 7.f), 1), f44(c, - 0.f, 1.f, 2.f, 3.f, - 4.f, 5.f, 6.f, 7.f, - -1.f, -1.f, -1.f, -1.f, - -1.f, -1.f, -1.f, -1.f)); - CHECK_F44 - (a, f44(c, - 0.f, 1.f, 2.f, 3.f, - 4.f, 5.f, 6.f, 7.f, - -1.f, -1.f, -1.f, -1.f, - -1.f, -1.f, -1.f, -1.f)); - CHECK_F44 - (f44_set_col(a, f4(c, 8.f, 9.f, 10.f, 11.f), 2), f44(c, - 0.f, 1.f, 2.f, 3.f, - 4.f, 5.f, 6.f, 7.f, - 8.f, 9.f, 10.f, 11.f, - -1.f, -1.f, -1.f, -1.f)); - CHECK_F44 - (a, f44(c, - 0.f, 1.f, 2.f, 3.f, - 4.f, 5.f, 6.f, 7.f, - 8.f, 9.f, 10.f, 11.f, - -1.f, -1.f, -1.f, -1.f)); - CHECK_F44 - (f44_set_col(a, f4(c, 12.f, 13.f, 14.f, 15.f), 3),f44(c, - 0.f, 1.f, 2.f, 3.f, - 4.f, 5.f, 6.f, 7.f, - 8.f, 9.f, 10.f, 11.f, - 12.f, 13.f, 14.f, 15.f)); - CHECK_F44 - (a, f44(c, - 0.f, 1.f, 2.f, 3.f, - 4.f, 5.f, 6.f, 7.f, - 8.f, 9.f, 10.f, 11.f, - 12.f, 13.f, 14.f, 15.f)); - - CHECK_F4(f44_row(b + 1, a, 0), f4(c, 0.f, 4.f, 8.f, 12.f)); - CHECK_F4(b + 1, f4(c, 0.f, 4.f, 8.f, 12.f)); - CHECK_F4(f44_row(b + 2, a, 1), f4(c, 1.f, 5.f, 9.f, 13.f)); - CHECK_F4(b + 2, f4(c, 1.f, 5.f, 9.f, 13.f)); - CHECK_F4(f44_row(b + 8, a, 2), f4(c, 2.f, 6.f, 10.f, 14.f)); - CHECK_F4(b + 8, f4(c, 2.f, 6.f, 10.f, 14.f)); - CHECK_F4(f44_row(b + 5, a, 2), f4(c, 2.f, 6.f, 10.f, 14.f)); - CHECK_F4(b + 5, f4(c, 2.f, 6.f, 10.f, 14.f)); - - CHECK_F4(f44_col(b + 2, a, 0), f4(c, 0.f, 1.f, 2.f, 3.f)); - CHECK_F4(b + 2, f4(c, 0.f, 1.f, 2.f, 3.f)); - CHECK_F4(f44_col(b + 1, a, 1), f4(c, 4.f, 5.f, 6.f, 7.f)); - CHECK_F4(b + 1, f4(c, 4.f, 5.f, 6.f, 7.f)); - CHECK_F4(f44_col(b + 5, a, 2), f4(c, 8.f, 9.f, 10.f, 11.f)); - CHECK_F4(b + 5, f4(c, 8.f, 9.f, 10.f, 11.f)); - CHECK_F4(f44_col(b + 5, a, 3), f4(c, 12.f, 13.f, 14.f, 15.f)); - CHECK_F4(b + 5, f4(c, 12.f, 13.f, 14.f, 15.f)); - CHECK_F4(f44_col_ptr(a, 0), f4(c, 0.f, 1.f, 2.f, 3.f)); - CHECK_F4(f44_col_ptr(a, 1), f4(c, 4.f, 5.f, 6.f, 7.f)); - CHECK_F4(f44_col_ptr(a, 2), f4(c, 8.f, 9.f, 10.f, 11.f)); - CHECK_F4(f44_col_ptr(a, 3), f4(c, 12.f, 13.f, 14.f, 15.f)); - CHECK_F4(f44_col_cptr(a, 0), f4(c, 0.f, 1.f, 2.f, 3.f)); - CHECK_F4(f44_col_cptr(a, 1), f4(c, 4.f, 5.f, 6.f, 7.f)); - CHECK_F4(f44_col_cptr(a, 2), f4(c, 8.f, 9.f, 10.f, 11.f)); - CHECK_F4(f44_col_cptr(a, 3), f4(c, 12.f, 13.f, 14.f, 15.f)); - - CHECK_F4 - (f44_mulf4(dst, a, f4(c, 1.f, 2.f, 3.f, 1.f)), - f4(c, 44.f, 51.f, 58.f, 65.f)); - CHECK_F4(dst, f4(c, 44.f, 51.f, 58.f, 65.f)); - CHECK_F4 - (f4_mulf44(dst, f4(c, 1.f, 2.f, 3.f, 1.f), a), - f4(c, 11.f, 39.f, 67.f, 95.f)); - CHECK_F4(dst, f4(c, 11.f, 39.f, 67.f, 95.f)); - CHECK_F44 - (f44_mul(dst, a, -1.f), f44(c, - 0.f, -1.f, -2.f, -3.f, - -4.f, -5.f, -6.f, -7.f, - -8.f, -9.f, -10.f, -11.f, - -12.f, -13.f, -14.f, -15.f)); - CHECK_F44 - (dst, f44(c, - 0.f, -1.f, -2.f, -3.f, - -4.f, -5.f, -6.f, -7.f, - -8.f, -9.f, -10.f, -11.f, - -12.f, -13.f, -14.f, -15.f)); - - f44 - (a, - 1.f, 2.f, 3.f, 4.f, - 4.f, 5.f, 6.f, 7.f, - 7.f, 8.f, 9.f, 10.f, - 10.f, 11.f, 12.f, 13.f); - f44 - (b, - 2.f, 9.f, 8.f, 1.f, - 1.f, -2.f, 2.f, 1.f, - 1.f, -8.f, -4.f, 2.f, - 1.f, 3.f, 4.f, 2.f); - CHECK_F44 - (f44_mulf44(dst, a, b), f44(c, - 104.f, 124.f, 144.f, 164.f, - 17.f, 19.f, 21.f, 23.f, - -39.f, -48.f, -57.f, -66.f, - 61.f, 71.f, 81.f, 91.f)); - CHECK_F44 - (dst, f44(c, - 104.f, 124.f, 144.f, 164.f, - 17.f, 19.f, 21.f, 23.f, - -39.f, -48.f, -57.f, -66.f, - 61.f, 71.f, 81.f, 91.f)); - CHECK_F44 - (f44_mulf44(a, a, b), f44(c, - 104.f, 124.f, 144.f, 164.f, - 17.f, 19.f, 21.f, 23.f, - -39.f, -48.f, -57.f, -66.f, - 61.f, 71.f, 81.f, 91.f)); - CHECK_F44 - (a, f44(c, - 104.f, 124.f, 144.f, 164.f, - 17.f, 19.f, 21.f, 23.f, - -39.f, -48.f, -57.f, -66.f, - 61.f, 71.f, 81.f, 91.f)); - f44 - (a, - 1.f, 2.f, 3.f, 4.f, - 4.f, 5.f, 6.f, 7.f, - 7.f, 8.f, 9.f, 10.f, - 10.f, 11.f, 12.f, 13.f); - CHECK_F44 - (f44_mulf44(b, a, b), f44(c, - 104.f, 124.f, 144.f, 164.f, - 17.f, 19.f, 21.f, 23.f, - -39.f, -48.f, -57.f, -66.f, - 61.f, 71.f, 81.f, 91.f)); - CHECK_F44 - (b, f44(c, - 104.f, 124.f, 144.f, 164.f, - 17.f, 19.f, 21.f, 23.f, - -39.f, -48.f, -57.f, -66.f, - 61.f, 71.f, 81.f, 91.f)); - - f44 - (a, - 0.f, 1.f, 2.f, 3.f, - 4.f, 5.f, 6.f, 7.f, - 8.f, 9.f, 10.f, 11.f, - 12.f, 13.f, 14.f, 15.f); - f44 - (b, - 0.f, 2.f, 1.f, 3.f, - 1.f, -2.f, -1.f, -3.f, - 1.f, 0.f, 0.f, 2.f, - 3.f, 2.f, 1.f, 0.f); - CHECK_F44 - (f44_add(dst, a, b), f44(c, - 0.f, 3.f, 3.f, 6.f, - 5.f, 3.f, 5.f, 4.f, - 9.f, 9.f, 10.f, 13.f, - 15.f, 15.f, 15.f, 15.f)); - CHECK_F44 - (dst, f44(c, - 0.f, 3.f, 3.f, 6.f, - 5.f, 3.f, 5.f, 4.f, - 9.f, 9.f, 10.f, 13.f, - 15.f, 15.f, 15.f, 15.f)); - CHECK_F44 - (f44_sub(dst, a, b), f44(c, - 0.f, -1.f, 1.f, 0.f, - 3.f, 7.f, 7.f, 10.f, - 7.f, 9.f, 10.f, 9.f, - 9.f, 11.f, 13.f, 15.f)); - CHECK_F44 - (dst, f44(c, - 0.f, -1.f, 1.f, 0.f, - 3.f, 7.f, 7.f, 10.f, - 7.f, 9.f, 10.f, 9.f, - 9.f, 11.f, 13.f, 15.f)); - CHECK_F44 - (f44_minus(a, b), f44(c, - 0.f, -2.f, -1.f, -3.f, - -1.f, 2.f, 1.f, 3.f, - -1.f, 0.f, 0.f, -2.f, - -3.f, -2.f, -1.f, 0.f)); - CHECK_F44 - (a, f44(c, - 0.f, -2.f, -1.f, -3.f, - -1.f, 2.f, 1.f, 3.f, - -1.f, 0.f, 0.f, -2.f, - -3.f, -2.f, -1.f, 0.f)); - - f44_set(a, b); - CHECK(f44_eq(a, b), 1); - f44_add(a, a, f44_splat(c, FLT_EPSILON)); - CHECK(f44_eq_eps(a, b, FLT_EPSILON), 1); - CHECK(f44_eq_eps(a, b, FLT_EPSILON * 0.9f), 0); - - f44_set - (a, f44(c, - 2.f, 9.f, 8.f, 1.f, - 1.f, -2.f, 2.f, 1.f, - 1.f, -8.f, -4.f, 2.f, - 1.f, 3.f, 4.f, 2.f)); - CHECK(f44_det(a), 78.f); - CHECK(f44_inverse(b, a), 78.f); - f44_mulf44(dst, a, b); - CHECK(f44_eq_eps - (dst, f44(c, - 1.f, 0.f, 0.f, 0.f, - 0.f, 1.f, 0.f, 0.f, - 0.f, 0.f, 1.f, 0.f, - 0.f, 0.f, 0.f, 1.f), - 1.e-6f), 1); - CHECK(f44_invtrans(a, a), 78.f); - f44_transpose(a, a); - CHECK_F44(a, b); - - return 0; -} diff --git a/src/test_real2.h b/src/test_real2.h @@ -105,5 +105,4 @@ main(int argc, char** argv) CHECK_REAL2(dst, REALX_CTOR__(c, -3.0, -2.0)); return 0; } -#include "realX_end.h" diff --git a/src/test_real22.h b/src/test_real22.h @@ -0,0 +1,144 @@ +/* Copyright (C) 2013-2016 Vincent Forest (vaplv@free.fr) + * + * The RSys library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * The RSys library 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the RSys library. If not, see <http://www.gnu.org/licenses/>. */ + +#include "rsys.h" +#include <float.h> + +#define REALX_DIMENSION__ 2 +#define REALY_DIMENSION__ 2 +#include "realXY_begin.h" + +#define REAL REAL_TYPE__ + +#define CHEK_REAL2(A, B) \ + { \ + const REAL* a__ = (A); \ + const REAL* b__ = (B); \ + int i__; \ + FOR_EACH(i__, 0, 2) \ + CHECK(a__[i__], b__[i__]); \ + } (void)0 +#define CHEK_REAL22(A, B) \ + { \ + const REAL* a__ = (A); \ + const REAL* b__ = (B); \ + int i__; \ + FOR_EACH(i__, 0, 4) \ + CHECK(a__[i__], b__[i__]); \ + } (void)0 + +int +main(int argc, char** argv) +{ + REAL a[4], b[4], dst[4], c[4]; + int i; + (void)argc, (void)argv; + + REALXY_FUNC__(set)(c, REALXY_FUNC__(splat)(a, -1.0)); + FOR_EACH(i, 0, 4) { + CHECK(a[i], -1.0); + CHECK(c[i], -1.0); + } + REALXY_FUNC__(set)(a, REALXY_CTOR__(c, 0.0, 1.0, 2.0, 3.0)); + FOR_EACH(i, 0, 4) { + CHECK(a[i], (REAL)i); + } + CHEK_REAL22(REALXY_FUNC__(set_identity)(a), + REALXY_CTOR__(c, 1.0, 0.0, 0.0, 1.0)); + CHEK_REAL22(a, REALXY_CTOR__(c, 1.0, 0.0, 0.0, 1.0)); + + REALXY_FUNC__(splat)(a, -1.0); + CHEK_REAL22(REALXY_FUNC__(set_row)(a, REALX_CTOR__(c, 0.0, 1.0), 0), + REALXY_CTOR__(c, 0.0, -1.0, 1.0, -1.0)); + CHEK_REAL22(a, REALXY_CTOR__(c, 0.0, -1.0, 1.0, -1.0)); + CHEK_REAL22(REALXY_FUNC__(set_row)(a, REALX_CTOR__(c, 2.0, 3.0), 1), + REALXY_CTOR__(c, 0.0, 2.0, 1.0, 3.0)); + CHEK_REAL22(a, REALXY_CTOR__(c, 0.0, 2.0, 1.0, 3.0)); + + CHEK_REAL22(REALXY_FUNC__(transpose)(a, a), + REALXY_CTOR__(c, 0.0, 1.0, 2.0, 3.0)); + CHEK_REAL22(a, REALXY_CTOR__(c, 0.0, 1.0, 2.0, 3.0)); + CHEK_REAL22(REALXY_FUNC__(transpose)(b, a), + REALXY_CTOR__(c, 0.0, 2.0, 1.0, 3.0)); + CHEK_REAL22(b, REALXY_CTOR__(c, 0.0, 2.0, 1.0, 3.0)); + + REALXY_FUNC__(splat)(a, -1.0); + CHEK_REAL22(REALXY_FUNC__(set_col)(a, REALX_CTOR__(c, 0.0, 1.0), 0), + REALXY_CTOR__(c, 0.0, 1.0, -1.0, -1.0)); + CHEK_REAL22(a, REALXY_CTOR__(c, 0.0, 1.0, -1.0, -1.0)); + CHEK_REAL22(REALXY_FUNC__(set_col)(a, REALX_CTOR__(c, 2.0, 3.0), 1), + REALXY_CTOR__(c, 0.0, 1.0, 2.0, 3.0)); + CHEK_REAL22(a, REALXY_CTOR__(c, 0.0, 1.0, 2.0, 3.0)); + + CHEK_REAL2(REALXY_FUNC__(row)(b, a, 0), REALX_CTOR__(c, 0.0, 2.0)); + CHEK_REAL2(REALXY_FUNC__(row)(b, a, 1), REALX_CTOR__(c, 1.0, 3.0)); + + CHEK_REAL2(REALXY_FUNC__(col)(b + 2, a, 0), REALX_CTOR__(c, 0.0, 1.0)); + CHEK_REAL2(REALXY_FUNC__(col)(b, a, 1), REALX_CTOR__(c, 2.0, 3.0)); + + CHEK_REAL2(REALXY_FUNC__(col_ptr)(a, 0), REALX_CTOR__(c, 0.0, 1.0)); + CHEK_REAL2(REALXY_FUNC__(col_ptr)(a, 1), REALX_CTOR__(c, 2.0, 3.0)); + CHEK_REAL2(REALXY_FUNC__(col_cptr)(a, 0), REALX_CTOR__(c, 0.0, 1.0)); + CHEK_REAL2(REALXY_FUNC__(col_cptr)(a, 1), REALX_CTOR__(c, 2.0, 3.0)); + + REALXY_CTOR__(a, 1.0, 2.0, 3.0, 4.0); + CHEK_REAL2(REALXY_REALX_FUNC__(mul)(dst, a, REALX_CTOR__(c, 1.0, 2.0)), + REALX_CTOR__(c, 7.0, 10.0)); + CHEK_REAL2(dst, REALX_CTOR__(c, 7.0, 10.0)); + CHEK_REAL2(REALX_REALXY_FUNC__(mul)(dst, REALX_CTOR__(c, 1.0, 2.0), a), + REALX_CTOR__(c, 5.0, 11.0)); + CHEK_REAL2(dst, REALX_CTOR__(c, 5.0, 11.0)); + CHEK_REAL22(REALXY_FUNC__(mul)(dst, a, -1.0), + REALXY_CTOR__(c, -1.0, -2.0, -3.0, -4.0)); + CHEK_REAL22(dst, REALXY_CTOR__(c, -1.0, -2.0, -3.0, -4.0)); + + REALXY_CTOR__(b, 2.0, 9.0, 8.0, 1.0); + CHEK_REAL22(REALXY_REALXY_FUNC__(mul)(dst, a, b), + REALXY_CTOR__(c, 29.0, 40.0, 11.0, 20.0)); + CHEK_REAL22(dst, REALXY_CTOR__(c, 29.0, 40.0, 11.0, 20.0)); + CHEK_REAL22(REALXY_REALXY_FUNC__(mul)(b, a, b), + REALXY_CTOR__(c, 29.0, 40.0, 11.0, 20.0)); + CHEK_REAL22(b, REALXY_CTOR__(c, 29.0, 40.0, 11.0, 20.0)); + + REALXY_CTOR__(a, 0.0, 1.0, 2.0, 3.0); + REALXY_CTOR__(b, 1.0, 2.0, 3.0, 4.0); + CHEK_REAL22(REALXY_FUNC__(add)(dst, a, b), + REALXY_CTOR__(c, 1.0, 3.0, 5.0, 7.0)); + CHEK_REAL22(dst, REALXY_CTOR__(c, 1.0, 3.0, 5.0, 7.0)); + CHEK_REAL22(REALXY_FUNC__(sub)(dst, dst, b), + REALXY_CTOR__(c, 0.0, 1.0, 2.0, 3.0)); + CHEK_REAL22(dst, REALXY_CTOR__(c, 0.0, 1.0, 2.0, 3.0)); + CHEK_REAL22(REALXY_FUNC__(minus)(a, b), + REALXY_CTOR__(c, -1.0, -2.0, -3.0, -4.0)); + CHEK_REAL22(a, REALXY_CTOR__(c, -1.0, -2.0, -3.0, -4.0)); + + REALXY_FUNC__(set)(a, b); + CHECK(REALXY_FUNC__(eq)(a, b), 1); + REALXY_FUNC__(add)(a, a, REALXY_FUNC__(splat)(c, REAL_EPSILON__)); + CHECK(REALXY_FUNC__(eq)(a, b), 0); + CHECK(REALXY_FUNC__(eq_eps)(a, b, REAL_EPSILON__), 1); + CHECK(REALXY_FUNC__(eq_eps)(a, b, REAL_EPSILON__ * (REAL)0.9), 0); + + REALXY_FUNC__(set)(a, REALXY_CTOR__(c, 1, 3, 2, 4)); + CHECK(REALXY_FUNC__(det)(a), -2.0); + CHECK(REALXY_FUNC__(inverse)(b, a), -2.0); + CHEK_REAL22(b, REALXY_CTOR__(c, -2.0, 1.5, 1.0, -0.5)); + CHECK(REALXY_FUNC__(invtrans)(a, a), -2.0); + CHEK_REAL22(a, REALXY_CTOR__(c, -2.0, 1.0, 1.5, -0.5)); + + return 0; +} + +#include "realXY_end.h" diff --git a/src/test_real33.h b/src/test_real33.h @@ -0,0 +1,197 @@ +/* Copyright (C) 2013-2016 Vincent Forest (vaplv@free.fr) + * + * The RSys library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * The RSys library 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the RSys library. If not, see <http://www.gnu.org/licenses/>. */ + +#include "rsys.h" +#include <float.h> + +#define REALX_DIMENSION__ 3 +#define REALY_DIMENSION__ 3 +#include "realXY_begin.h" + +#define REAL REAL_TYPE__ + +#define CHECK_REAL3(A, B) \ + { \ + const REAL* a__ = (A); \ + const REAL* b__ = (B); \ + int i__; \ + FOR_EACH(i__, 0, 3) \ + CHECK(a__[i__], b__[i__]); \ + } (void)0 +#define CHECK_REAL33(A, B) \ + { \ + const REAL* a__ = (A); \ + const REAL* b__ = (B); \ + int i__; \ + FOR_EACH(i__, 0, 9) \ + CHECK(a__[i__], b__[i__]); \ + } (void)0 + +int +main(int argc, char** argv) +{ + REAL a[9], b[9], dst[9], c[9]; + int i; + (void)argc, (void)argv; + + REALXY_FUNC__(set)(a, REALXY_FUNC__(splat)(c, -1.0)); + FOR_EACH(i, 0, 9) { + CHECK(a[i], -1.0); + CHECK(c[i], -1.0); + } + REALXY_CTOR__(a, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0); + FOR_EACH(i, 0, 9) { + CHECK(a[i], (REAL)i); + } + CHECK_REAL33 + (REALXY_FUNC__(set_identity)(a), + REALXY_CTOR__(c, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0)); + CHECK_REAL33(a, REALXY_CTOR__(c, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0)); + + REALXY_FUNC__(splat)(a, -1.0); + CHECK_REAL33 + (REALXY_FUNC__(set_row)(a, REALX_CTOR__(c, 0.0, 1.0, 2.0), 0), + REALXY_CTOR__(c, 0.0, -1.0, -1.0, 1.0, -1.0, -1.0, 2.0, -1.0, -1.0)); + CHECK_REAL33(a, REALXY_CTOR__(c, 0.0, -1.0, -1.0, 1.0, -1.0, -1.0, 2.0, -1.0, -1.0)); + CHECK_REAL33 + (REALXY_FUNC__(set_row)(a, REALX_CTOR__(c, 3.0, 4.0, 5.0), 1), + REALXY_CTOR__(c, 0.0, 3.0, -1.0, 1.0, 4.0, -1.0, 2.0, 5.0, -1.0)); + CHECK_REAL33(a, REALXY_CTOR__(c, 0.0, 3.0, -1.0, 1.0, 4.0, -1.0, 2.0, 5.0, -1.0)); + CHECK_REAL33 + (REALXY_FUNC__(set_row)(a, REALX_CTOR__(c, 6.0, 7.0, 8.0), 2), + REALXY_CTOR__(c, 0.0, 3.0, 6.0, 1.0, 4.0, 7.0, 2.0, 5.0, 8.0)); + CHECK_REAL33(a, REALXY_CTOR__(c, 0.0, 3.0, 6.0, 1.0, 4.0, 7.0, 2.0, 5.0, 8.0)); + + CHECK_REAL33 + (REALXY_FUNC__(transpose)(a, a), + REALXY_CTOR__(c, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0)); + CHECK_REAL33(a, REALXY_CTOR__(c, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0)); + CHECK_REAL33 + (REALXY_FUNC__(transpose)(b, a), + REALXY_CTOR__(c, 0.0, 3.0, 6.0, 1.0, 4.0, 7.0, 2.0, 5.0, 8.0)); + CHECK_REAL33(b, REALXY_CTOR__(c, 0.0, 3.0, 6.0, 1.0, 4.0, 7.0, 2.0, 5.0, 8.0)); + + REALXY_FUNC__(splat)(a, -1.0); + CHECK_REAL33 + (REALXY_FUNC__(set_col)(a, REALX_CTOR__(c, 0.0, 1.0, 2.0), 0), + REALXY_CTOR__(c, 0.0, 1.0, 2.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0)); + CHECK_REAL33(a, REALXY_CTOR__(c, 0.0, 1.0, 2.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0)); + CHECK_REAL33 + (REALXY_FUNC__(set_col)(a, REALX_CTOR__(c, 3.0, 4.0, 5.0), 1), + REALXY_CTOR__(c, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, -1.0, -1.0, -1.0)); + CHECK_REAL33(a, REALXY_CTOR__(c, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, -1.0, -1.0, -1.0)); + CHECK_REAL33 + (REALXY_FUNC__(set_col)(a, REALX_CTOR__(c, 6.0, 7.0, 8.0), 2), + REALXY_CTOR__(c, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0)); + CHECK_REAL33(a, REALXY_CTOR__(c, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0)); + + CHECK_REAL3(REALXY_FUNC__(row)(b, a, 0), REALX_CTOR__(c, 0.0, 3.0, 6.0)); + CHECK_REAL3(b, REALX_CTOR__(c, 0.0, 3.0, 6.0)); + CHECK_REAL3(REALXY_FUNC__(row)(b, a, 1), REALX_CTOR__(c, 1.0, 4.0, 7.0)); + CHECK_REAL3(b, REALX_CTOR__(c, 1.0, 4.0, 7.0)); + CHECK_REAL3(REALXY_FUNC__(row)(b, a, 2), REALX_CTOR__(c, 2.0, 5.0, 8.0)); + CHECK_REAL3(b, REALX_CTOR__(c, 2.0, 5.0, 8.0)); + + CHECK_REAL3(REALXY_FUNC__(col)(b + 2, a, 0), REALX_CTOR__(c, 0.0, 1.0, 2.0)); + CHECK_REAL3(b + 2, REALX_CTOR__(c, 0.0, 1.0, 2.0)); + CHECK_REAL3(REALXY_FUNC__(col)(b + 1, a, 1), REALX_CTOR__(c, 3.0, 4.0, 5.0)); + CHECK_REAL3(b + 1, REALX_CTOR__(c, 3.0, 4.0, 5.0)); + CHECK_REAL3(REALXY_FUNC__(col)(b + 5, a, 2), REALX_CTOR__(c, 6.0, 7.0, 8.0)); + CHECK_REAL3(b + 5, REALX_CTOR__(c, 6.0, 7.0, 8.0)); + + CHECK_REAL3(REALXY_FUNC__(col_ptr)(a, 0), REALX_CTOR__(c, 0.0, 1.0, 2.0)); + CHECK_REAL3(REALXY_FUNC__(col_ptr)(a, 1), REALX_CTOR__(c, 3.0, 4.0, 5.0)); + CHECK_REAL3(REALXY_FUNC__(col_ptr)(a, 2), REALX_CTOR__(c, 6.0, 7.0, 8.0)); + CHECK_REAL3(REALXY_FUNC__(col_cptr)(a, 0), REALX_CTOR__(c, 0.0, 1.0, 2.0)); + CHECK_REAL3(REALXY_FUNC__(col_cptr)(a, 1), REALX_CTOR__(c, 3.0, 4.0, 5.0)); + CHECK_REAL3(REALXY_FUNC__(col_cptr)(a, 2), REALX_CTOR__(c, 6.0, 7.0, 8.0)); + + REALXY_CTOR__(a, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0); + CHECK_REAL3(REALXY_REALX_FUNC__(mul)(dst, a, REALX_CTOR__(c, 1.0, 2.0, 3.0)), + REALX_CTOR__(c, 30.0, 36.0, 42.0)); + CHECK_REAL3(dst, REALX_CTOR__(c, 30.0, 36.0, 42.0)); + CHECK_REAL3(REALX_REALXY_FUNC__(mul)(dst, REALX_CTOR__(c, 1.0, 2.0, 3.0), a), + REALX_CTOR__(c, 14.0, 32.0, 50.0)); + CHECK_REAL3(dst, REALX_CTOR__(c, 14.0, 32.0, 50.0)); + CHECK_REAL3 + (REALXY_FUNC__(mul)(dst, a, -1.0), + REALXY_CTOR__(c, -1.0, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0, -9.0)); + CHECK_REAL33(dst, + REALXY_CTOR__(c, -1.0, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0, -9.0)); + + REALXY_CTOR__(b, 2.0, 9.0, 8.0, 1.0, -2.0, 2.0, 1.0, -8.0, -4.0); + CHECK_REAL33 + (REALXY_REALXY_FUNC__(mul)(dst, a, b), + REALXY_CTOR__(c, 94.0, 113.0, 132.0, 7.0, 8.0, 9.0, -59.0, -70.0,-81.0)); + CHECK_REAL33(dst, + REALXY_CTOR__(c, 94.0, 113.0, 132.0, 7.0, 8.0, 9.0, -59.0, -70.0,-81.0)); + CHECK_REAL33 + (REALXY_REALXY_FUNC__(mul)(a, a, b), + REALXY_CTOR__(c, 94.0, 113.0, 132.0, 7.0, 8.0, 9.0, -59.0, -70.0, -81.0)); + CHECK_REAL33(a, + REALXY_CTOR__(c, 94.0, 113.0, 132.0, 7.0, 8.0, 9.0, -59.0, -70.0, -81.0)); + REALXY_CTOR__(a, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0); + CHECK_REAL33 + (REALXY_REALXY_FUNC__(mul)(b, a, b), + REALXY_CTOR__(c, 94.0, 113.0, 132.0, 7.0, 8.0, 9.0, -59.0, -70.0, -81.0)); + CHECK_REAL33(b, + REALXY_CTOR__(c, 94.0, 113.0, 132.0, 7.0, 8.0, 9.0, -59.0, -70.0, -81.0)); + REALXY_CTOR__(b, 2.0, 9.0, 8.0, 1.0, -2.0, 2.0, 1.0, -8.0, -4.0); + + REALXY_CTOR__(a, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0); + REALXY_CTOR__(b, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0); + CHECK_REAL33 + (REALXY_FUNC__(add)(dst, a, b), + REALXY_CTOR__(c, 1.0, 3.0, 5.0, 7.0, 9.0, 11.0, 13.0, 15.0, 17.0)); + CHECK_REAL33(dst, + REALXY_CTOR__(c, 1.0, 3.0, 5.0, 7.0, 9.0, 11.0, 13.0, 15.0, 17.0)); + CHECK_REAL33 + (REALXY_FUNC__(sub)(dst, dst, b), + REALXY_CTOR__(c, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0)); + CHECK_REAL33(dst, + REALXY_CTOR__(c, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0)); + CHECK_REAL33 + (REALXY_FUNC__(minus)(a, b), + REALXY_CTOR__(c, -1.0, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0, -9.0)); + CHECK_REAL33(a, + REALXY_CTOR__(c, -1.0, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0, -9.0)); + + REALXY_FUNC__(set)(a, b); + CHECK(REALXY_FUNC__(eq)(a, b), 1); + REALXY_FUNC__(add)(a, a, REALXY_FUNC__(splat)(c, FLT_EPSILON)); + CHECK(REALXY_FUNC__(eq)(a, b), 0); + CHECK(REALXY_FUNC__(eq_eps)(a, b, FLT_EPSILON), 1); + CHECK(REALXY_FUNC__(eq_eps)(a, b, FLT_EPSILON * (REAL)0.9), 0); + + REALXY_CTOR__(a, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 3.0, -4.0, 9.0); + CHECK(REALXY_FUNC__(det)(a), -60.0); + CHECK(REALXY_FUNC__(inverse)(b, a), -60.0); + REALXY_REALXY_FUNC__(mul)(dst, a, b); + CHECK(REALXY_FUNC__(eq_eps)(dst, + REALXY_CTOR__(c, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0), 1.e-6f), 1); + CHECK(REALXY_FUNC__(invtrans)(a, a), -60.0); + CHECK_REAL33 + (a, REALXY_CTOR__(c, b[0], b[3], b[6], b[1], b[4], b[7], b[2], b[5], b[8])); + + REALX_CTOR__(c, (REAL)0.66666667, (REAL)0.33333333, (REAL)0.66666667); + REALXY_FUNC__(rotation_axis_angle)(a, c, (REAL)0.349066); + CHECK(REALXY_FUNC__(eq_eps)(a, REALXY_CTOR__(c, + (REAL)0.966496, (REAL)0.241415, (REAL)-0.0872034, + (REAL)-0.214612, (REAL)0.946393, (REAL)0.241415, + (REAL)0.14081, (REAL)-0.214612, (REAL)0.966496), (REAL)1.e-6), 1); + + return 0; +} + diff --git a/src/test_real4.h b/src/test_real4.h @@ -113,3 +113,4 @@ main(int argc, char** argv) CHECK_REAL4(dst, REALX_CTOR__(c, -1.0, 3.0, (REAL)-2.1, (REAL)0.1)); return 0; } + diff --git a/src/test_real44.h b/src/test_real44.h @@ -0,0 +1,387 @@ +/* Copyright (C) 2013-2016 Vincent Forest (vaplv@free.fr) + * + * The RSys library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * The RSys library 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the RSys library. If not, see <http://www.gnu.org/licenses/>. */ + +#include "rsys.h" +#include <float.h> + +#define REALX_DIMENSION__ 4 +#define REALY_DIMENSION__ 4 +#include "realXY_begin.h" + +#define REAL REAL_TYPE__ + +#define CHECK_REAL4(A, B) \ + { \ + const REAL* a__ = (A); \ + const REAL* b__ = (B); \ + int i__; \ + FOR_EACH(i__, 0, 4) \ + CHECK(a__[i__], b__[i__]); \ + } (void)0 +#define CHECK_REAL44(A, B) \ + { \ + const REAL* a__ = (A); \ + const REAL* b__ = (B); \ + int i__; \ + FOR_EACH(i__, 0, 16) \ + CHECK(a__[i__], b__[i__]); \ + } (void)0 + +int +main(int argc, char** argv) +{ + REAL a[16], b[16], dst[16], c[16]; + int i; + (void)argc, (void)argv; + + REALXY_FUNC__(set)(a, REALXY_FUNC__(splat)(c, -1.0)); + FOR_EACH(i, 0, 16) { + CHECK(a[i], -1.0); + CHECK(c[i], -1.0); + } + REALXY_CTOR__ + (a, + 0.0, 1.0, 2.0, 3.0, + 4.0, 5.0, 6.0, 7.0, + 8.0, 9.0, 10.0, 11.0, + 12.0, 13.0, 14.0, 15.0); + FOR_EACH(i, 0, 16) { + CHECK(a[i], (REAL)i); + } + CHECK_REAL44 + (REALXY_FUNC__(set_identity)(a),REALXY_CTOR__(c, + 1.0, 0.0, 0.0, 0.0, + 0.0, 1.0, 0.0, 0.0, + 0.0, 0.0, 1.0, 0.0, + 0.0, 0.0, 0.0, 1.0)); + CHECK_REAL44 + (a, REALXY_CTOR__(c, + 1.0, 0.0, 0.0, 0.0, + 0.0, 1.0, 0.0, 0.0, + 0.0, 0.0, 1.0, 0.0, + 0.0, 0.0, 0.0, 1.0)); + + REALXY_FUNC__(splat)(a, -1.0); + CHECK_REAL44 + (REALXY_FUNC__(set_row)(a, REALX_CTOR__(c, 0.0, 1.0, 2.0, 3.0), 0), + REALXY_CTOR__(c, + 0.0, -1.0, -1.0, -1.0, + 1.0, -1.0, -1.0, -1.0, + 2.0, -1.0, -1.0, -1.0, + 3.0, -1.0, -1.0, -1.0)); + CHECK_REAL44 + (a, REALXY_CTOR__(c, + 0.0, -1.0, -1.0, -1.0, + 1.0, -1.0, -1.0, -1.0, + 2.0, -1.0, -1.0, -1.0, + 3.0, -1.0, -1.0, -1.0)); + CHECK_REAL44 + (REALXY_FUNC__(set_row)(a, REALX_CTOR__(c, 4.0, 5.0, 6.0, 7.0), 1), + REALXY_CTOR__(c, + 0.0, 4.0, -1.0, -1.0, + 1.0, 5.0, -1.0, -1.0, + 2.0, 6.0, -1.0, -1.0, + 3.0, 7.0, -1.0, -1.0)); + CHECK_REAL44 + (a, REALXY_CTOR__(c, + 0.0, 4.0, -1.0, -1.0, + 1.0, 5.0, -1.0, -1.0, + 2.0, 6.0, -1.0, -1.0, + 3.0, 7.0, -1.0, -1.0)); + CHECK_REAL44 + (REALXY_FUNC__(set_row)(a, REALX_CTOR__(c, 8.0, 9.0, 10.0, 11.0), 2), + REALXY_CTOR__(c, + 0.0, 4.0, 8.0, -1.0, + 1.0, 5.0, 9.0, -1.0, + 2.0, 6.0, 10.0, -1.0, + 3.0, 7.0, 11.0, -1.0)); + CHECK_REAL44 + (a, REALXY_CTOR__(c, + 0.0, 4.0, 8.0, -1.0, + 1.0, 5.0, 9.0, -1.0, + 2.0, 6.0, 10.0, -1.0, + 3.0, 7.0, 11.0, -1.0)); + CHECK_REAL44 + (REALXY_FUNC__(set_row)(a, REALX_CTOR__(c, 12.0, 13.0, 14.0, 15.0), 3), + REALXY_CTOR__(c, + 0.0, 4.0, 8.0, 12.0, + 1.0, 5.0, 9.0, 13.0, + 2.0, 6.0, 10.0, 14.0, + 3.0, 7.0, 11.0, 15.0)); + CHECK_REAL44 + (a, REALXY_CTOR__(c, + 0.0, 4.0, 8.0, 12.0, + 1.0, 5.0, 9.0, 13.0, + 2.0, 6.0, 10.0, 14.0, + 3.0, 7.0, 11.0, 15.0)); + + CHECK_REAL44 + (REALXY_FUNC__(transpose)(a, a), REALXY_CTOR__(c, + 0.0, 1.0, 2.0, 3.0, + 4.0, 5.0, 6.0, 7.0, + 8.0, 9.0, 10.0, 11.0, + 12.0, 13.0, 14.0, 15.0)); + CHECK_REAL44 + (a, REALXY_CTOR__(c, + 0.0, 1.0, 2.0, 3.0, + 4.0, 5.0, 6.0, 7.0, + 8.0, 9.0, 10.0, 11.0, + 12.0, 13.0, 14.0, 15.0)); + CHECK_REAL44 + (REALXY_FUNC__(transpose)(b, a),REALXY_CTOR__(c, + 0.0, 4.0, 8.0, 12.0, + 1.0, 5.0, 9.0, 13.0, + 2.0, 6.0, 10.0, 14.0, + 3.0, 7.0, 11.0, 15.0)); + CHECK_REAL44 + (b, REALXY_CTOR__(c, + 0.0, 4.0, 8.0, 12.0, + 1.0, 5.0, 9.0, 13.0, + 2.0, 6.0, 10.0, 14.0, + 3.0, 7.0, 11.0, 15.0)); + + REALXY_FUNC__(splat)(a, -1.0); + CHECK_REAL44 + (REALXY_FUNC__(set_col)(a, REALX_CTOR__(c, 0.0, 1.0, 2.0, 3.0), 0), + REALXY_CTOR__(c, + 0.0, 1.0, 2.0, 3.0, + -1.0, -1.0, -1.0, -1.0, + -1.0, -1.0, -1.0, -1.0, + -1.0, -1.0, -1.0, -1.0)); + CHECK_REAL44 + (a, REALXY_CTOR__(c, + 0.0, 1.0, 2.0, 3.0, + -1.0, -1.0, -1.0, -1.0, + -1.0, -1.0, -1.0, -1.0, + -1.0, -1.0, -1.0, -1.0)); + CHECK_REAL44 + (REALXY_FUNC__(set_col)(a, REALX_CTOR__(c, 4.0, 5.0, 6.0, 7.0), 1), + REALXY_CTOR__(c, + 0.0, 1.0, 2.0, 3.0, + 4.0, 5.0, 6.0, 7.0, + -1.0, -1.0, -1.0, -1.0, + -1.0, -1.0, -1.0, -1.0)); + CHECK_REAL44 + (a, REALXY_CTOR__(c, + 0.0, 1.0, 2.0, 3.0, + 4.0, 5.0, 6.0, 7.0, + -1.0, -1.0, -1.0, -1.0, + -1.0, -1.0, -1.0, -1.0)); + CHECK_REAL44 + (REALXY_FUNC__(set_col)(a, REALX_CTOR__(c, 8.0, 9.0, 10.0, 11.0), 2), + REALXY_CTOR__(c, + 0.0, 1.0, 2.0, 3.0, + 4.0, 5.0, 6.0, 7.0, + 8.0, 9.0, 10.0, 11.0, + -1.0, -1.0, -1.0, -1.0)); + CHECK_REAL44 + (a, REALXY_CTOR__(c, + 0.0, 1.0, 2.0, 3.0, + 4.0, 5.0, 6.0, 7.0, + 8.0, 9.0, 10.0, 11.0, + -1.0, -1.0, -1.0, -1.0)); + CHECK_REAL44 + (REALXY_FUNC__(set_col)(a, REALX_CTOR__(c, 12.0, 13.0, 14.0, 15.0), 3), + REALXY_CTOR__(c, + 0.0, 1.0, 2.0, 3.0, + 4.0, 5.0, 6.0, 7.0, + 8.0, 9.0, 10.0, 11.0, + 12.0, 13.0, 14.0, 15.0)); + CHECK_REAL44 + (a, REALXY_CTOR__(c, + 0.0, 1.0, 2.0, 3.0, + 4.0, 5.0, 6.0, 7.0, + 8.0, 9.0, 10.0, 11.0, + 12.0, 13.0, 14.0, 15.0)); + + CHECK_REAL4(REALXY_FUNC__(row)(b + 1, a, 0), REALX_CTOR__(c, 0.0, 4.0, 8.0, 12.0)); + CHECK_REAL4(b + 1, REALX_CTOR__(c, 0.0, 4.0, 8.0, 12.0)); + CHECK_REAL4(REALXY_FUNC__(row)(b + 2, a, 1), REALX_CTOR__(c, 1.0, 5.0, 9.0, 13.0)); + CHECK_REAL4(b + 2, REALX_CTOR__(c, 1.0, 5.0, 9.0, 13.0)); + CHECK_REAL4(REALXY_FUNC__(row)(b + 8, a, 2), REALX_CTOR__(c, 2.0, 6.0, 10.0, 14.0)); + CHECK_REAL4(b + 8, REALX_CTOR__(c, 2.0, 6.0, 10.0, 14.0)); + CHECK_REAL4(REALXY_FUNC__(row)(b + 5, a, 2), REALX_CTOR__(c, 2.0, 6.0, 10.0, 14.0)); + CHECK_REAL4(b + 5, REALX_CTOR__(c, 2.0, 6.0, 10.0, 14.0)); + + CHECK_REAL4(REALXY_FUNC__(col)(b + 2, a, 0), REALX_CTOR__(c, 0.0, 1.0, 2.0, 3.0)); + CHECK_REAL4(b + 2, REALX_CTOR__(c, 0.0, 1.0, 2.0, 3.0)); + CHECK_REAL4(REALXY_FUNC__(col)(b + 1, a, 1), REALX_CTOR__(c, 4.0, 5.0, 6.0, 7.0)); + CHECK_REAL4(b + 1, REALX_CTOR__(c, 4.0, 5.0, 6.0, 7.0)); + CHECK_REAL4(REALXY_FUNC__(col)(b + 5, a, 2), REALX_CTOR__(c, 8.0, 9.0, 10.0, 11.0)); + CHECK_REAL4(b + 5, REALX_CTOR__(c, 8.0, 9.0, 10.0, 11.0)); + CHECK_REAL4(REALXY_FUNC__(col)(b + 5, a, 3), REALX_CTOR__(c, 12.0, 13.0, 14.0, 15.0)); + CHECK_REAL4(b + 5, REALX_CTOR__(c, 12.0, 13.0, 14.0, 15.0)); + CHECK_REAL4(REALXY_FUNC__(col_ptr)(a, 0), REALX_CTOR__(c, 0.0, 1.0, 2.0, 3.0)); + CHECK_REAL4(REALXY_FUNC__(col_ptr)(a, 1), REALX_CTOR__(c, 4.0, 5.0, 6.0, 7.0)); + CHECK_REAL4(REALXY_FUNC__(col_ptr)(a, 2), REALX_CTOR__(c, 8.0, 9.0, 10.0, 11.0)); + CHECK_REAL4(REALXY_FUNC__(col_ptr)(a, 3), REALX_CTOR__(c, 12.0, 13.0, 14.0, 15.0)); + CHECK_REAL4(REALXY_FUNC__(col_cptr)(a, 0), REALX_CTOR__(c, 0.0, 1.0, 2.0, 3.0)); + CHECK_REAL4(REALXY_FUNC__(col_cptr)(a, 1), REALX_CTOR__(c, 4.0, 5.0, 6.0, 7.0)); + CHECK_REAL4(REALXY_FUNC__(col_cptr)(a, 2), REALX_CTOR__(c, 8.0, 9.0, 10.0, 11.0)); + CHECK_REAL4(REALXY_FUNC__(col_cptr)(a, 3), REALX_CTOR__(c, 12.0, 13.0, 14.0, 15.0)); + + CHECK_REAL4 + (REALXY_REALX_FUNC__(mul)(dst, a, REALX_CTOR__(c, 1.0, 2.0, 3.0, 1.0)), + REALX_CTOR__(c, 44.0, 51.0, 58.0, 65.0)); + CHECK_REAL4(dst, REALX_CTOR__(c, 44.0, 51.0, 58.0, 65.0)); + CHECK_REAL4 + (REALX_REALXY_FUNC__(mul)(dst, REALX_CTOR__(c, 1.0, 2.0, 3.0, 1.0), a), + REALX_CTOR__(c, 11.0, 39.0, 67.0, 95.0)); + CHECK_REAL4(dst, REALX_CTOR__(c, 11.0, 39.0, 67.0, 95.0)); + CHECK_REAL44 + (REALXY_FUNC__(mul)(dst, a, -1.0), REALXY_CTOR__(c, + 0.0, -1.0, -2.0, -3.0, + -4.0, -5.0, -6.0, -7.0, + -8.0, -9.0, -10.0, -11.0, + -12.0, -13.0, -14.0, -15.0)); + CHECK_REAL44 + (dst, REALXY_CTOR__(c, + 0.0, -1.0, -2.0, -3.0, + -4.0, -5.0, -6.0, -7.0, + -8.0, -9.0, -10.0, -11.0, + -12.0, -13.0, -14.0, -15.0)); + + REALXY_CTOR__ + (a, + 1.0, 2.0, 3.0, 4.0, + 4.0, 5.0, 6.0, 7.0, + 7.0, 8.0, 9.0, 10.0, + 10.0, 11.0, 12.0, 13.0); + REALXY_CTOR__ + (b, + 2.0, 9.0, 8.0, 1.0, + 1.0, -2.0, 2.0, 1.0, + 1.0, -8.0, -4.0, 2.0, + 1.0, 3.0, 4.0, 2.0); + CHECK_REAL44 + (REALXY_REALXY_FUNC__(mul)(dst, a, b), REALXY_CTOR__(c, + 104.0, 124.0, 144.0, 164.0, + 17.0, 19.0, 21.0, 23.0, + -39.0, -48.0, -57.0, -66.0, + 61.0, 71.0, 81.0, 91.0)); + CHECK_REAL44 + (dst, REALXY_CTOR__(c, + 104.0, 124.0, 144.0, 164.0, + 17.0, 19.0, 21.0, 23.0, + -39.0, -48.0, -57.0, -66.0, + 61.0, 71.0, 81.0, 91.0)); + CHECK_REAL44 + (REALXY_REALXY_FUNC__(mul)(a, a, b), REALXY_CTOR__(c, + 104.0, 124.0, 144.0, 164.0, + 17.0, 19.0, 21.0, 23.0, + -39.0, -48.0, -57.0, -66.0, + 61.0, 71.0, 81.0, 91.0)); + CHECK_REAL44 + (a, REALXY_CTOR__(c, + 104.0, 124.0, 144.0, 164.0, + 17.0, 19.0, 21.0, 23.0, + -39.0, -48.0, -57.0, -66.0, + 61.0, 71.0, 81.0, 91.0)); + REALXY_CTOR__ + (a, + 1.0, 2.0, 3.0, 4.0, + 4.0, 5.0, 6.0, 7.0, + 7.0, 8.0, 9.0, 10.0, + 10.0, 11.0, 12.0, 13.0); + CHECK_REAL44 + (REALXY_REALXY_FUNC__(mul)(b, a, b), REALXY_CTOR__(c, + 104.0, 124.0, 144.0, 164.0, + 17.0, 19.0, 21.0, 23.0, + -39.0, -48.0, -57.0, -66.0, + 61.0, 71.0, 81.0, 91.0)); + CHECK_REAL44 + (b, REALXY_CTOR__(c, + 104.0, 124.0, 144.0, 164.0, + 17.0, 19.0, 21.0, 23.0, + -39.0, -48.0, -57.0, -66.0, + 61.0, 71.0, 81.0, 91.0)); + + REALXY_CTOR__ + (a, + 0.0, 1.0, 2.0, 3.0, + 4.0, 5.0, 6.0, 7.0, + 8.0, 9.0, 10.0, 11.0, + 12.0, 13.0, 14.0, 15.0); + REALXY_CTOR__ + (b, + 0.0, 2.0, 1.0, 3.0, + 1.0, -2.0, -1.0, -3.0, + 1.0, 0.0, 0.0, 2.0, + 3.0, 2.0, 1.0, 0.0); + CHECK_REAL44 + (REALXY_FUNC__(add)(dst, a, b), REALXY_CTOR__(c, + 0.0, 3.0, 3.0, 6.0, + 5.0, 3.0, 5.0, 4.0, + 9.0, 9.0, 10.0, 13.0, + 15.0, 15.0, 15.0, 15.0)); + CHECK_REAL44 + (dst, REALXY_CTOR__(c, + 0.0, 3.0, 3.0, 6.0, + 5.0, 3.0, 5.0, 4.0, + 9.0, 9.0, 10.0, 13.0, + 15.0, 15.0, 15.0, 15.0)); + CHECK_REAL44 + (REALXY_FUNC__(sub)(dst, a, b), REALXY_CTOR__(c, + 0.0, -1.0, 1.0, 0.0, + 3.0, 7.0, 7.0, 10.0, + 7.0, 9.0, 10.0, 9.0, + 9.0, 11.0, 13.0, 15.0)); + CHECK_REAL44 + (dst, REALXY_CTOR__(c, + 0.0, -1.0, 1.0, 0.0, + 3.0, 7.0, 7.0, 10.0, + 7.0, 9.0, 10.0, 9.0, + 9.0, 11.0, 13.0, 15.0)); + CHECK_REAL44 + (REALXY_FUNC__(minus)(a, b), REALXY_CTOR__(c, + 0.0, -2.0, -1.0, -3.0, + -1.0, 2.0, 1.0, 3.0, + -1.0, 0.0, 0.0, -2.0, + -3.0, -2.0, -1.0, 0.0)); + CHECK_REAL44 + (a, REALXY_CTOR__(c, + 0.0, -2.0, -1.0, -3.0, + -1.0, 2.0, 1.0, 3.0, + -1.0, 0.0, 0.0, -2.0, + -3.0, -2.0, -1.0, 0.0)); + + REALXY_FUNC__(set)(a, b); + CHECK(REALXY_FUNC__(eq)(a, b), 1); + REALXY_FUNC__(add)(a, a, REALXY_FUNC__(splat)(c, FLT_EPSILON)); + CHECK(REALXY_FUNC__(eq_eps)(a, b, FLT_EPSILON), 1); + CHECK(REALXY_FUNC__(eq_eps)(a, b, FLT_EPSILON * (REAL)0.9), 0); + + REALXY_FUNC__(set) + (a, REALXY_CTOR__(c, + 2.0, 9.0, 8.0, 1.0, + 1.0, -2.0, 2.0, 1.0, + 1.0, -8.0, -4.0, 2.0, + 1.0, 3.0, 4.0, 2.0)); + CHECK(REALXY_FUNC__(det)(a), 78.0); + CHECK(REALXY_FUNC__(inverse)(b, a), 78.0); + REALXY_REALXY_FUNC__(mul)(dst, a, b); + CHECK(REALXY_FUNC__(eq_eps) + (dst, REALXY_CTOR__(c, + 1.0, 0.0, 0.0, 0.0, + 0.0, 1.0, 0.0, 0.0, + 0.0, 0.0, 1.0, 0.0, + 0.0, 0.0, 0.0, 1.0), + 1.e-6f), 1); + CHECK(REALXY_FUNC__(invtrans)(a, a), 78.0); + REALXY_FUNC__(transpose)(a, a); + CHECK_REAL44(a, b); + + return 0; +}