From 47a5d7d1bcad974dbeaf5e7f2945027e72835d34 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 14 Jun 2016 16:43:14 +1000 Subject: BLI_math: Add double versions of functions - mul_v3_m3v3_db - mul_m3_v3_db - negate_v3_db --- source/blender/blenlib/BLI_math_matrix.h | 6 +++++- source/blender/blenlib/BLI_math_vector.h | 2 ++ source/blender/blenlib/intern/math_matrix.c | 17 ++++++++++++++--- source/blender/blenlib/intern/math_vector_inline.c | 7 +++++++ 4 files changed, 28 insertions(+), 4 deletions(-) (limited to 'source') diff --git a/source/blender/blenlib/BLI_math_matrix.h b/source/blender/blenlib/BLI_math_matrix.h index 6d6fbe4e7af..9120d9f53f7 100644 --- a/source/blender/blenlib/BLI_math_matrix.h +++ b/source/blender/blenlib/BLI_math_matrix.h @@ -138,10 +138,14 @@ bool invert_m3_m3(float R[3][3], float A[3][3]); bool invert_m4(float R[4][4]); bool invert_m4_m4(float R[4][4], float A[4][4]); -/* double ariphmetics */ +/* double arithmetic (mixed float/double) */ void mul_m4_v4d(float M[4][4], double r[4]); void mul_v4d_m4v4d(double r[4], float M[4][4], double v[4]); +/* double matrix functions (no mixing types) */ +void mul_v3_m3v3_db(double r[3], double M[3][3], const double a[3]); +void mul_m3_v3_db(double M[3][3], double r[3]); + /****************************** Linear Algebra *******************************/ diff --git a/source/blender/blenlib/BLI_math_vector.h b/source/blender/blenlib/BLI_math_vector.h index 25f485a25aa..8a36b047bad 100644 --- a/source/blender/blenlib/BLI_math_vector.h +++ b/source/blender/blenlib/BLI_math_vector.h @@ -148,6 +148,7 @@ MINLINE void negate_v4(float r[4]); MINLINE void negate_v4_v4(float r[4], const float a[3]); MINLINE void negate_v3_short(short r[3]); +MINLINE void negate_v3_db(double r[3]); MINLINE void invert_v2(float r[2]); @@ -231,6 +232,7 @@ void flip_v4_v4v4(float v[4], const float v1[4], const float v2[4]); void flip_v3_v3v3(float v[3], const float v1[3], const float v2[3]); void flip_v2_v2v2(float v[2], const float v1[2], const float v2[2]); + /********************************* Comparison ********************************/ MINLINE bool is_zero_v2(const float a[3]) ATTR_WARN_UNUSED_RESULT; diff --git a/source/blender/blenlib/intern/math_matrix.c b/source/blender/blenlib/intern/math_matrix.c index 0e3f905ef16..c9c61d5c878 100644 --- a/source/blender/blenlib/intern/math_matrix.c +++ b/source/blender/blenlib/intern/math_matrix.c @@ -587,6 +587,15 @@ void mul_v3_m3v3(float r[3], float M[3][3], const float a[3]) r[2] = M[0][2] * a[0] + M[1][2] * a[1] + M[2][2] * a[2]; } +void mul_v3_m3v3_db(double r[3], double M[3][3], const double a[3]) +{ + BLI_assert(r != a); + + r[0] = M[0][0] * a[0] + M[1][0] * a[1] + M[2][0] * a[2]; + r[1] = M[0][1] * a[0] + M[1][1] * a[1] + M[2][1] * a[2]; + r[2] = M[0][2] * a[0] + M[1][2] * a[1] + M[2][2] * a[2]; +} + void mul_v2_m3v3(float r[2], float M[3][3], const float a[3]) { BLI_assert(r != a); @@ -597,10 +606,12 @@ void mul_v2_m3v3(float r[2], float M[3][3], const float a[3]) void mul_m3_v3(float M[3][3], float r[3]) { - float tmp[3]; + mul_v3_m3v3(r, M, (const float[3]){UNPACK3(r)}); +} - mul_v3_m3v3(tmp, M, r); - copy_v3_v3(r, tmp); +void mul_m3_v3_db(double M[3][3], double r[3]) +{ + mul_v3_m3v3_db(r, M, (const double[3]){UNPACK3(r)}); } void mul_transposed_m3_v3(float mat[3][3], float vec[3]) diff --git a/source/blender/blenlib/intern/math_vector_inline.c b/source/blender/blenlib/intern/math_vector_inline.c index b43fb6e986c..fd9f3d5ff99 100644 --- a/source/blender/blenlib/intern/math_vector_inline.c +++ b/source/blender/blenlib/intern/math_vector_inline.c @@ -633,6 +633,13 @@ MINLINE void negate_v3_short(short r[3]) r[2] = (short)-r[2]; } +MINLINE void negate_v3_db(double r[3]) +{ + r[0] = -r[0]; + r[1] = -r[1]; + r[2] = -r[2]; +} + MINLINE void invert_v2(float r[2]) { BLI_assert(!ELEM(0.0f, r[0], r[1])); -- cgit v1.2.3