rsys

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

commit 5235c0bde1ace2cbe5f03d39c7978305765e7ff1
parent e9ead68d8ec1eef4487a912b2b861812c6dc9c5d
Author: vaplv <vaplv@free.fr>
Date:   Fri,  7 Oct 2016 13:36:30 +0200

Implement and test the is_identity realXY function

Diffstat:
Msrc/realXY.h | 44++++++++++++++++++++++++++++++--------------
Msrc/test_real22.h | 10++++++++++
Msrc/test_real33.h | 10++++++++++
Msrc/test_real44.h | 8++++++++
4 files changed, 58 insertions(+), 14 deletions(-)

diff --git a/src/realXY.h b/src/realXY.h @@ -79,20 +79,6 @@ REALXY_FUNC__(set)(REAL_TYPE__* dst, const REAL_TYPE__* src) } static FINLINE REAL_TYPE__* -REALXY_FUNC__(set_identity)(REAL_TYPE__* mat) -{ - int x, y, i; - ASSERT(mat); - i = 0; - FOR_EACH(x, 0, REALX_DIMENSION__) { - FOR_EACH(y, 0, REALY_DIMENSION__) { - mat[i] = x == y ? 1.f : 0.f; - ++i; - }} - return mat; -} - -static FINLINE REAL_TYPE__* REALXY_FUNC__(set_row)(REAL_TYPE__* mat, const REAL_TYPE__* row, const int irow) { REAL_TYPE__ tmp[REALX_DIMENSION__]; @@ -267,6 +253,36 @@ REALX_REALXY_FUNC__(mul) #if REALX_DIMENSION__ == REALY_DIMENSION__ static FINLINE REAL_TYPE__* +REALXY_FUNC__(set_identity)(REAL_TYPE__* mat) +{ + int x, y, i; + ASSERT(mat); + i = 0; + FOR_EACH(x, 0, REALX_DIMENSION__) { + FOR_EACH(y, 0, REALY_DIMENSION__) { + mat[i] = x == y ? 1.f : 0.f; + ++i; + }} + return mat; +} + +static FINLINE int +REALXY_FUNC__(is_identity)(const REAL_TYPE__* mat) +{ + int is_identity; + int x = 0; + do { + int y = 0; + do { + is_identity = mat[x*REALY_DIMENSION__ + y] == (REAL_TYPE__)(x==y); + ++y; + } while(y < REALY_DIMENSION__ && is_identity); + ++x; + } while(x < REALX_DIMENSION__ && is_identity); + return is_identity; +} + +static FINLINE REAL_TYPE__* REALXY_FUNC__(transpose)(REAL_TYPE__* dst, const REAL_TYPE__* src) { REAL_TYPE__ tmp[REALX_DIMENSION__ * REALY_DIMENSION__]; diff --git a/src/test_real22.h b/src/test_real22.h @@ -15,6 +15,7 @@ #include "rsys.h" #include <float.h> +#include <math.h> #define REALX_DIMENSION__ 2 #define REALY_DIMENSION__ 2 @@ -60,6 +61,15 @@ main(int argc, char** argv) CHECK_REAL22(REALXY_FUNC__(set_identity)(a), REALXY_CTOR__(c, 1.0, 0.0, 0.0, 1.0)); CHECK_REAL22(a, REALXY_CTOR__(c, 1.0, 0.0, 0.0, 1.0)); + CHECK(REALXY_FUNC__(is_identity)(a), 1); + + REALXY_FUNC__(set)(c, a); + FOR_EACH(i, 0, REALX_DIMENSION__*REALY_DIMENSION__) { + REAL_TYPE__ d = c[i]; + c[i] = c[i] + REAL_EPSILON__; + CHECK(REALXY_FUNC__(is_identity)(c), 0); + c[i] = d; + } d[0] = (REAL_COMPATIBLE)0.1; d[1] = (REAL_COMPATIBLE)(1.0/3.0); diff --git a/src/test_real33.h b/src/test_real33.h @@ -15,6 +15,7 @@ #include "rsys.h" #include <float.h> +#include <math.h> #define REALX_DIMENSION__ 3 #define REALY_DIMENSION__ 3 @@ -61,6 +62,15 @@ main(int argc, char** argv) (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)); + CHECK(REALXY_FUNC__(is_identity)(a), 1); + + REALXY_FUNC__(set)(c, a); + FOR_EACH(i, 0, REALX_DIMENSION__*REALY_DIMENSION__) { + REAL_TYPE__ d = c[i]; + c[i] = c[i] + REAL_EPSILON__; + CHECK(REALXY_FUNC__(is_identity)(c), 0); + c[i] = d; + } d[0] = (REAL_COMPATIBLE)0.1; d[1] = (REAL_COMPATIBLE)(1.0/3.0); diff --git a/src/test_real44.h b/src/test_real44.h @@ -74,6 +74,14 @@ main(int argc, char** argv) 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(REALXY_FUNC__(is_identity)(a), 1); + REALXY_FUNC__(set)(c, a); + FOR_EACH(i, 0, REALX_DIMENSION__*REALY_DIMENSION__) { + REAL_TYPE__ d = c[i]; + c[i] = c[i] + REAL_EPSILON__; + CHECK(REALXY_FUNC__(is_identity)(c), 0); + c[i] = d; + } d[0] = (REAL_COMPATIBLE)0.1; d[1] = (REAL_COMPATIBLE)(1.0/3.0);