From ffcb15d3f25ebc25ee0dab68fadfe5e88e2b755f Mon Sep 17 00:00:00 2001 From: dizcza Date: Sat, 8 Aug 2020 21:07:10 +0200 Subject: added tests --- .circleci/config.yml | 35 ++++++++ README | 12 --- README.md | 15 ++++ linmath.h | 139 ++++++++++++++--------------- linmath_test.c | 9 ++ linmath_test.h | 242 +++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 364 insertions(+), 88 deletions(-) create mode 100644 .circleci/config.yml delete mode 100644 README create mode 100644 README.md create mode 100644 linmath_test.c create mode 100644 linmath_test.h diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..17987bb --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,35 @@ +version: 2.1 + +jobs: + linmath-test: + machine: + image: ubuntu-1604:201903-01 + steps: + - run: gcc --version + - checkout + - run: + command: | + gcc -O0 -o linmath_test.o linmath_test.c -lm + ./linmath_test.o + name: linmath tests gcc -O0 + - run: + command: | + gcc -O1 -o linmath_test.o linmath_test.c -lm + ./linmath_test.o + name: linmath tests gcc -O1 + - run: + command: | + gcc -O2 -o linmath_test.o linmath_test.c -lm + ./linmath_test.o + name: linmath tests gcc -O2 + - run: + command: | + gcc -O3 -o linmath_test.o linmath_test.c -lm + ./linmath_test.o + name: linmath tests gcc -O3 + + +workflows: + main: + jobs: + - linmath-test diff --git a/README b/README deleted file mode 100644 index a61a9e0..0000000 --- a/README +++ /dev/null @@ -1,12 +0,0 @@ -# linmath.h -- A small library for linear math as required for computer graphics - -linmath.h provides the most used types required for programming computer graphics: - -vec3 -- 3 element vector of floats -vec4 -- 4 element vector of floats (4th component used for homogenous computations) -mat4x4 -- 4 by 4 elements matrix, computations are done in column major order -quat -- quaternion - -The types are deliberately named like the types in GLSL. In fact they are meant to -be used for the client side computations and passing to same typed GLSL uniforms. - diff --git a/README.md b/README.md new file mode 100644 index 0000000..7a06566 --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +# linmath.h -- A small library for linear math as required for computer graphics + +[![CircleCI](https://circleci.com/gh/datenwolf/linmath.h.svg?style=svg)](https://app.circleci.com/pipelines/github/datenwolf/linmath.h) + + +linmath.h provides the most used types required for programming computer graphics: + +vec3 -- 3 element vector of floats +vec4 -- 4 element vector of floats (4th component used for homogenous computations) +mat4x4 -- 4 by 4 elements matrix, computations are done in column major order +quat -- quaternion + +The types are deliberately named like the types in GLSL. In fact they are meant to +be used for the client side computations and passing to same typed GLSL uniforms. + diff --git a/linmath.h b/linmath.h index 2a92211..aaa3e1e 100644 --- a/linmath.h +++ b/linmath.h @@ -1,6 +1,7 @@ #ifndef LINMATH_H #define LINMATH_H +#include #include #ifdef LINMATH_NO_INLINE @@ -31,7 +32,7 @@ LINMATH_H_FUNC void vec##n##_scale(vec##n r, vec##n const v, float const s) \ } \ LINMATH_H_FUNC float vec##n##_mul_inner(vec##n const a, vec##n const b) \ { \ - float p = 0.; \ + float p = 0.f; \ int i; \ for(i=0; ib[i] ? a[i] : b[i]; \ +} \ +LINMATH_H_FUNC void vec##n##_dup(vec##n r, vec##n const src) \ +{ \ + int i; \ + for(i=0; i + +#include "linmath_test.h" + +int main() { + linmath_test_run_all(); + printf("linmath tests passed\n"); + return 0; +} diff --git a/linmath_test.h b/linmath_test.h new file mode 100644 index 0000000..5c48444 --- /dev/null +++ b/linmath_test.h @@ -0,0 +1,242 @@ +/* + * linmath_test.h + * + * Created on: Apr 9, 2017 + * Author: Danylo Ulianych + */ + +#ifndef LINMATH_TEST_H +#define LINMATH_TEST_H + +#include +#include "linmath.h" + +#define LINMATH_EPS (0.0001f) +#define linmath_is_close(val1, val2) (fabsf(val1 - val2) < LINMATH_EPS) + +#ifndef linmath_assert +#include +#define linmath_assert assert +#endif /* linmath_assert */ + + +static float linmath_random_float() { + return rand() / (float) RAND_MAX; +} + +#define LINMATH_TEST_DEFINE_VEC(n) \ +static void linmath_vec##n##_set(vec##n v, float value) { \ + int i; \ + for (i=0; i