diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2019-01-20 18:22:55 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2019-01-20 18:27:06 +0300 |
commit | 482c4d099ae88bea018712b92b2990617ef006f8 (patch) | |
tree | cdc6dd9d345da7a6edb2106ecb63d314d14b7a61 /source/blender/blenlib | |
parent | b0dee09a6d5531fb3bc7bbb00069c75e18dfbd1d (diff) |
Cleanup: remove all BLI_utiledefines' ugly vectorial macros.
Not only were those often making doublons with already existing
BLI_math's stuff, but they were also used to hide implicit type
conversions...
As usual this adds some more exotic inlined vector functions (one of
the rare cases where I really miss C++ and its templates... ;) ).
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_math_vector.h | 10 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_utildefines.h | 39 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_vector_inline.c | 42 |
3 files changed, 52 insertions, 39 deletions
diff --git a/source/blender/blenlib/BLI_math_vector.h b/source/blender/blenlib/BLI_math_vector.h index dc108a7c3ec..61f24bae269 100644 --- a/source/blender/blenlib/BLI_math_vector.h +++ b/source/blender/blenlib/BLI_math_vector.h @@ -83,6 +83,8 @@ MINLINE void zero_v3_db(double r[3]); MINLINE void copy_v2_v2_db(double r[2], const double a[2]); MINLINE void copy_v3_v3_db(double r[3], const double a[3]); MINLINE void copy_v4_v4_db(double r[4], const double a[4]); +/* short -> float */ +MINLINE void copy_v3fl_v3s(float r[3], const short a[3]); /* int <-> float */ MINLINE void copy_v2fl_v2i(float r[2], const int a[2]); MINLINE void round_v2i_v2fl(int r[2], const float a[2]); @@ -112,14 +114,20 @@ MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3]); MINLINE void add_v4_v4(float r[4], const float a[4]); MINLINE void add_v4_v4v4(float r[4], const float a[4], const float b[4]); +MINLINE void add_v3fl_v3fl_v3i(float r[3], const float a[3], const int b[3]); +MINLINE void add_v3fl_v3fl_v3s(float r[3], const float a[3], const short b[3]); + MINLINE void sub_v2_v2(float r[2], const float a[2]); MINLINE void sub_v2_v2v2(float r[2], const float a[2], const float b[2]); MINLINE void sub_v2_v2v2_int(int r[2], const int a[2], const int b[2]); MINLINE void sub_v3_v3(float r[3], const float a[3]); MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3]); +MINLINE void sub_v3_v3v3_int(int r[3], const int a[3], const int b[3]); MINLINE void sub_v4_v4(float r[4], const float a[4]); MINLINE void sub_v4_v4v4(float r[4], const float a[4], const float b[4]); +MINLINE void sub_v3db_v3fl_v3fl(double r[3], const float a[3], const float b[3]); + MINLINE void mul_v2_fl(float r[2], float f); MINLINE void mul_v2_v2fl(float r[2], const float a[2], float f); MINLINE void mul_v3_fl(float r[3], float f); @@ -150,6 +158,8 @@ MINLINE void madd_v3_v3v3v3(float r[3], const float a[3], const float b[3], cons MINLINE void madd_v4_v4fl(float r[4], const float a[4], float f); MINLINE void madd_v4_v4v4(float r[4], const float a[4], const float b[4]); +MINLINE void madd_v3fl_v3fl_v3fl_v3i(float r[3], const float a[3], const float b[3], const int c[3]); + MINLINE void negate_v2(float r[2]); MINLINE void negate_v2_v2(float r[2], const float a[2]); MINLINE void negate_v3(float r[3]); diff --git a/source/blender/blenlib/BLI_utildefines.h b/source/blender/blenlib/BLI_utildefines.h index f81bfc2f853..0e08b637c15 100644 --- a/source/blender/blenlib/BLI_utildefines.h +++ b/source/blender/blenlib/BLI_utildefines.h @@ -224,45 +224,6 @@ extern "C" { b = tmp; \ } (void)0 -#define VECCOPY(v1, v2) { \ - *(v1) = *(v2); \ - *(v1 + 1) = *(v2 + 1); \ - *(v1 + 2) = *(v2 + 2); \ -} (void)0 -#define VECCOPY2D(v1, v2) { \ - *(v1) = *(v2); \ - *(v1 + 1) = *(v2 + 1); \ -} (void)0 -#define VECADD(v1, v2, v3) { \ - *(v1) = *(v2) + *(v3); \ - *(v1 + 1) = *(v2 + 1) + *(v3 + 1); \ - *(v1 + 2) = *(v2 + 2) + *(v3 + 2); \ -} (void)0 -#define VECSUB(v1, v2, v3) { \ - *(v1) = *(v2) - *(v3); \ - *(v1 + 1) = *(v2 + 1) - *(v3 + 1); \ - *(v1 + 2) = *(v2 + 2) - *(v3 + 2); \ -} (void)0 -#define VECSUB2D(v1, v2, v3) { \ - *(v1) = *(v2) - *(v3); \ - *(v1 + 1) = *(v2 + 1) - *(v3 + 1); \ -} (void)0 -#define VECADDFAC(v1, v2, v3, fac) { \ - *(v1) = *(v2) + *(v3) * (fac); \ - *(v1 + 1) = *(v2 + 1) + *(v3 + 1) * (fac); \ - *(v1 + 2) = *(v2 + 2) + *(v3 + 2) * (fac); \ -} (void)0 -#define VECMADD(v1, v2, v3, v4) { \ - *(v1) = *(v2) + *(v3) * (*(v4)); \ - *(v1 + 1) = *(v2 + 1) + *(v3 + 1) * (*(v4 + 1)); \ - *(v1 + 2) = *(v2 + 2) + *(v3 + 2) * (*(v4 + 2)); \ -} (void)0 -#define VECSUBFAC(v1, v2, v3, fac) { \ - *(v1) = *(v2) - *(v3) * (fac); \ - *(v1 + 1) = *(v2 + 1) - *(v3 + 1) * (fac); \ - *(v1 + 2) = *(v2 + 2) - *(v3 + 2) * (fac); \ -} (void)0 - /* some misc stuff.... */ /* avoid multiple access for supported compilers */ diff --git a/source/blender/blenlib/intern/math_vector_inline.c b/source/blender/blenlib/intern/math_vector_inline.c index 78b3a5420ed..511b2a98259 100644 --- a/source/blender/blenlib/intern/math_vector_inline.c +++ b/source/blender/blenlib/intern/math_vector_inline.c @@ -68,6 +68,13 @@ MINLINE void copy_v3_v3(float r[3], const float a[3]) r[2] = a[2]; } +MINLINE void copy_v3fl_v3s(float r[3], const short a[3]) +{ + r[0] = (float)a[0]; + r[1] = (float)a[1]; + r[2] = (float)a[2]; +} + MINLINE void copy_v4_v4(float r[4], const float a[4]) { r[0] = a[0]; @@ -378,6 +385,20 @@ MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3]) r[2] = a[2] + b[2]; } +MINLINE void add_v3fl_v3fl_v3i(float r[3], const float a[3], const int b[3]) +{ + r[0] = a[0] + (float)b[0]; + r[1] = a[1] + (float)b[1]; + r[2] = a[2] + (float)b[2]; +} + +MINLINE void add_v3fl_v3fl_v3s(float r[3], const float a[3], const short b[3]) +{ + r[0] = a[0] + (float)b[0]; + r[1] = a[1] + (float)b[1]; + r[2] = a[2] + (float)b[2]; +} + MINLINE void add_v4_v4(float r[4], const float a[4]) { r[0] += a[0]; @@ -426,6 +447,20 @@ MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3]) r[2] = a[2] - b[2]; } +MINLINE void sub_v3_v3v3_int(int r[3], const int a[3], const int b[3]) +{ + r[0] = a[0] - b[0]; + r[1] = a[1] - b[1]; + r[2] = a[2] - b[2]; +} + +MINLINE void sub_v3db_v3fl_v3fl(double r[3], const float a[3], const float b[3]) +{ + r[0] = (double)a[0] - (double)b[0]; + r[1] = (double)a[1] - (double)b[1]; + r[2] = (double)a[2] - (double)b[2]; +} + MINLINE void sub_v4_v4(float r[4], const float a[4]) { r[0] -= a[0]; @@ -622,6 +657,13 @@ MINLINE void madd_v3_v3v3v3(float r[3], const float a[3], const float b[3], cons r[2] = a[2] + b[2] * c[2]; } +MINLINE void madd_v3fl_v3fl_v3fl_v3i(float r[3], const float a[3], const float b[3], const int c[3]) +{ + r[0] = a[0] + b[0] * (float)c[0]; + r[1] = a[1] + b[1] * (float)c[1]; + r[2] = a[2] + b[2] * (float)c[2]; +} + MINLINE void madd_v4_v4fl(float r[4], const float a[4], float f) { r[0] += a[0] * f; |