rsys

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

commit fad8dd101e4a5e72f36e6cd7e32a96ab25646660
parent b3e0f88729935b489486f6e78e11fcf54e4e3829
Author: vaplv <vaplv@free.fr>
Date:   Mon,  4 Jul 2016 12:12:41 +0200

Make the float<2|3|4> types generic to the data type

Diffstat:
Mcmake/CMakeLists.txt | 8++++++--
Msrc/float2.h | 11+----------
Msrc/float3.h | 15+--------------
Msrc/float4.h | 2++
Asrc/real2.h | 33+++++++++++++++++++++++++++++++++
Asrc/real3.h | 40++++++++++++++++++++++++++++++++++++++++
Msrc/realX.h | 45++++-----------------------------------------
Msrc/realXY.h | 2+-
Asrc/realX_begin.h | 61+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/realX_end.h | 32++++++++++++++++++++++++++++++++
10 files changed, 181 insertions(+), 68 deletions(-)

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -78,11 +78,9 @@ set(RSYS_FILES_INC_API dynamic_array_uint.h dynamic_array_size_t.h dynamic_array_str.h - realX.h float2.h float3.h float4.h - realXY.h float22.h float33.h float44.h @@ -97,6 +95,12 @@ set(RSYS_FILES_INC_API mem_allocator.h mutex.h quaternion.h + real2.h + real3.h + realX.h + realX_begin.h + realX_end.h + realXY.h ref_count.h rsys.h signal.h diff --git a/src/float2.h b/src/float2.h @@ -16,17 +16,8 @@ #ifndef FLOAT2_H #define FLOAT2_H -/* Generate common floatX funcs */ -#define REALX_DIMENSION__ 2 #define REAL_TYPE__ float -#include "realX.h" - -static FINLINE float -f2_cross(const float a[2], const float b[2]) -{ - ASSERT(a && b); - return a[0]*b[1] - a[1]*b[0]; -} +#include "real2.h" #endif /* FLOAT2_H */ diff --git a/src/float3.h b/src/float3.h @@ -16,21 +16,8 @@ #ifndef FLOAT3_H #define FLOAT3_H -/* Generate common realX funcs */ -#define REALX_DIMENSION__ 3 #define REAL_TYPE__ float -#include "realX.h" - -static FINLINE float* -f3_cross(float dst[3], const float a[3], const float b[3]) -{ - float tmp[3]; - ASSERT(dst && a && b); - tmp[0] = a[1]*b[2] - a[2]*b[1]; - tmp[1] = a[2]*b[0] - a[0]*b[2]; - tmp[2] = a[0]*b[1] - a[1]*b[0]; - return f3_set(dst, tmp); -} +#include "real3.h" #endif /* FLOAT3_H */ diff --git a/src/float4.h b/src/float4.h @@ -19,7 +19,9 @@ /* Generate common floatX funcs */ #define REALX_DIMENSION__ 4 #define REAL_TYPE__ float +#include "realX_begin.h" #include "realX.h" +#include "realX_end.h" #endif /* FLOAT4_H */ diff --git a/src/real2.h b/src/real2.h @@ -0,0 +1,33 @@ +/* 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 REAL_TYPE__ + #error Missing arguments +#endif + +/* Generate common realX funcs */ +#define REALX_DIMENSION__ 2 +#include "realX_begin.h" +#include "realX.h" + +static FINLINE REAL_TYPE__ +REALX_FUNC__(cross)(const REAL_TYPE__ a[2], const REAL_TYPE__ b[2]) +{ + ASSERT(a && b); + return a[0]*b[1] - a[1]*b[0]; +} + +#include "realX_end.h" + diff --git a/src/real3.h b/src/real3.h @@ -0,0 +1,40 @@ +/* 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 REAL_TYPE__ + #error Missing arguments +#endif + +/* Generate common realX funcs */ +#define REALX_DIMENSION__ 3 +#include "realX_begin.h" +#include "realX.h" + +static FINLINE REAL_TYPE__* +REALX_FUNC__(cross) + (REAL_TYPE__ dst[3], + const REAL_TYPE__ a[3], + const REAL_TYPE__ b[3]) +{ + REAL_TYPE__ tmp[3]; + ASSERT(dst && a && b); + tmp[0] = a[1]*b[2] - a[2]*b[1]; + tmp[1] = a[2]*b[0] - a[0]*b[2]; + tmp[2] = a[0]*b[1] - a[1]*b[0]; + return REALX_FUNC__(set)(dst, tmp); +} + +#include "realX_end.h" + diff --git a/src/realX.h b/src/realX.h @@ -16,44 +16,18 @@ /* * Internal header used to generate funcs on REAL_TYPE__ vector of X dimensions */ -#if !defined(REALX_DIMENSION__) || !defined(REAL_TYPE__) - #error Missing arguments -#endif - -#if defined(REALX_FUNC__) \ - || defined(REAL_LETTER__) \ - || defined(REAL_EPSILON__) \ - || defined(SIZEOF_REALX__) - #error Unexpected macro definition -#endif - #include "math.h" -#include "rsys.h" #include <math.h> +#ifndef REALX_BEGIN_H + #error The realX_begin.h header must be included +#endif + #ifdef COMPILER_GCC #pragma GCC push_options #pragma GCC optimize("unroll-loops") #endif -STATIC_ASSERT(REALX_DIMENSION__ > 1, Unexpected_value); - -/* Define the epsilon for each real type */ -#define REAL_EPSILON_double 1.e-8 -#define REAL_EPSILON_float 1.e-6f -#define REAL_EPSILON__ CONCAT(REAL_EPSILON_, REAL_TYPE__) - -/* Define the suffix/prefix letter for each real type */ -#define REAL_LETTER_float f -#define REAL_LETTER_double d -#define REAL_LETTER__ CONCAT(REAL_LETTER_, REAL_TYPE__) - -#define REALX_FUNC__(Func) \ - CONCAT(CONCAT(CONCAT(REAL_LETTER__, REALX_DIMENSION__), _), Func) - -/* Helper macro */ -#define SIZEOF_REALX__ sizeof(REAL_TYPE__[REALX_DIMENSION__]) - #if REALX_DIMENSION__ <= 4 static FINLINE REAL_TYPE__* CONCAT(REAL_LETTER__, REALX_DIMENSION__) @@ -372,17 +346,6 @@ REALX_FUNC__(min) return REALX_FUNC__(set__)(dst, tmp); } -#undef REAL_TYPE__ -#undef REAL_LETTER__ -#undef REAL_LETTER__float -#undef REAL_LETTER_double -#undef REAL_EPSILON__ -#undef REAL_EPSILON_float -#undef REAL_EPSILON_double -#undef REALX_DIMENSION__ -#undef REALX_FUNC__ -#undef SIZEOF_REALX__ - #ifdef COMPILER_GCC #pragma GCC pop_options #endif diff --git a/src/realXY.h b/src/realXY.h @@ -335,7 +335,7 @@ REALXY_FUNC__(CONCAT(CONCAT(mulf, REALX_DIMENSION__), REALY_DIMENSION__)) #undef REAL_EPSILON_float #undef REAL_EPSILON_double #undef REAL_LETTER__ -#undef REAL_LETTER__float +#undef REAL_LETTER_float #undef REAL_LETTER_double #undef REALX_FUNC__ #undef REALY_FUNC__ diff --git a/src/realX_begin.h b/src/realX_begin.h @@ -0,0 +1,61 @@ +/* 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/>. */ + +/* Check that the expected arguments are defined */ + +/* This file can be included once */ +#if defined(REALX_BEGIN_H) + #error The realX_begin.h header is already defined +#endif +#define REALX_BEGIN_H + +/* Check the the file arguments are defined */ +#if !defined(REALX_DIMENSION__) || !defined(REAL_TYPE__) + #error Missing arguments +#endif + +/* Check that internal macros are not already defined */ +#if defined(REALX_FUNC__) \ + || defined(REAL_LETTER__) \ + || defined(REAL_LETTER_float) \ + || defined(REAL_LETTER_double) \ + || defined(REAL_EPSILON__) \ + || defined(REAL_EPSILON_float) \ + || defined(REAL_EPSILON_double) \ + || defined(SIZEOF_REALX__) + #error Unexpected macro definition +#endif + +/* Define the epsilon for each real type */ +#define REAL_EPSILON_double 1.e-8 +#define REAL_EPSILON_float 1.e-6f +#define REAL_EPSILON__ CONCAT(REAL_EPSILON_, REAL_TYPE__) + +/* Define the suffix/prefix letter for each real type */ +#define REAL_LETTER_float f +#define REAL_LETTER_double d +#define REAL_LETTER__ CONCAT(REAL_LETTER_, REAL_TYPE__) + +/* Define the function name generator */ +#define REALX_FUNC__(Func) \ + CONCAT(CONCAT(CONCAT(REAL_LETTER__, REALX_DIMENSION__), _), Func) + +/* Helper macro */ +#define SIZEOF_REALX__ sizeof(REAL_TYPE__[REALX_DIMENSION__]) + +/* Check the validity of the vector dimension */ +#include "rsys.h" +STATIC_ASSERT(REALX_DIMENSION__ > 1, Unexpected_value); + diff --git a/src/realX_end.h b/src/realX_end.h @@ -0,0 +1,32 @@ +/* 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 REALX_BEGIN_H + #error The realX_begin.h header must be included +#endif + +#undef REAL_TYPE__ +#undef REAL_LETTER__ +#undef REAL_LETTER_float +#undef REAL_LETTER_double +#undef REAL_EPSILON__ +#undef REAL_EPSILON_float +#undef REAL_EPSILON_double +#undef REALX_DIMENSION__ +#undef REALX_FUNC__ +#undef SIZEOF_REALX__ + +#undef REALX_BEGIN_H +