[Bf-blender-cvs] [cb5302f9621] master: Math: Make it possible to use vector for both input and output

Sergey Sharybin noreply at git.blender.org
Fri Jan 18 12:30:33 CET 2019


Commit: cb5302f962185b827e8c8b40f7a10dceebe310f9
Author: Sergey Sharybin
Date:   Thu Jan 17 15:41:27 2019 +0100
Branches: master
https://developer.blender.org/rBcb5302f962185b827e8c8b40f7a10dceebe310f9

Math: Make it possible to use vector for both input and output

Avoids nasty code all over where such math is required, and
compilers can easily deal with such situation.

Don't prefer questionable micro-optimization which comes with
a cost of nasty actual logic code.

===================================================================

M	source/blender/blenlib/BLI_math_vector.h
M	source/blender/blenlib/intern/math_matrix.c
M	source/blender/blenlib/intern/math_vector_inline.c

===================================================================

diff --git a/source/blender/blenlib/BLI_math_vector.h b/source/blender/blenlib/BLI_math_vector.h
index a663d08b074..dc108a7c3ec 100644
--- a/source/blender/blenlib/BLI_math_vector.h
+++ b/source/blender/blenlib/BLI_math_vector.h
@@ -78,6 +78,11 @@ MINLINE void zero_v3_int(int r[3]);
 MINLINE void copy_v2_v2_int(int r[2], const int a[2]);
 MINLINE void copy_v3_v3_int(int r[3], const int a[3]);
 MINLINE void copy_v4_v4_int(int r[4], const int a[4]);
+/* double */
+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]);
 /* 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]);
diff --git a/source/blender/blenlib/intern/math_matrix.c b/source/blender/blenlib/intern/math_matrix.c
index 15858e8797e..518161db565 100644
--- a/source/blender/blenlib/intern/math_matrix.c
+++ b/source/blender/blenlib/intern/math_matrix.c
@@ -656,28 +656,31 @@ void mul_v4_m4v3(float r[4], const float M[4][4], const float v[3])
 
 void mul_v3_m3v3(float r[3], const float M[3][3], const float a[3])
 {
-	BLI_assert(r != a);
+	float t[3];
+	copy_v3_v3(t, 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];
+	r[0] = M[0][0] * t[0] + M[1][0] * t[1] + M[2][0] * t[2];
+	r[1] = M[0][1] * t[0] + M[1][1] * t[1] + M[2][1] * t[2];
+	r[2] = M[0][2] * t[0] + M[1][2] * t[1] + M[2][2] * t[2];
 }
 
 void mul_v3_m3v3_db(double r[3], const double M[3][3], const double a[3])
 {
-	BLI_assert(r != a);
+	double t[3];
+	copy_v3_v3_db(t, 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];
+	r[0] = M[0][0] * t[0] + M[1][0] * t[1] + M[2][0] * t[2];
+	r[1] = M[0][1] * t[0] + M[1][1] * t[1] + M[2][1] * t[2];
+	r[2] = M[0][2] * t[0] + M[1][2] * t[1] + M[2][2] * t[2];
 }
 
 void mul_v2_m3v3(float r[2], const float M[3][3], const float a[3])
 {
-	BLI_assert(r != a);
+	float t[3];
+	copy_v3_v3(t, 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[0] = M[0][0] * t[0] + M[1][0] * t[1] + M[2][0] * t[2];
+	r[1] = M[0][1] * t[0] + M[1][1] * t[1] + M[2][1] * t[2];
 }
 
 void mul_m3_v3(const float M[3][3], float r[3])
diff --git a/source/blender/blenlib/intern/math_vector_inline.c b/source/blender/blenlib/intern/math_vector_inline.c
index fc3f11fd1be..78b3a5420ed 100644
--- a/source/blender/blenlib/intern/math_vector_inline.c
+++ b/source/blender/blenlib/intern/math_vector_inline.c
@@ -142,12 +142,6 @@ MINLINE void copy_v4_v4_char(char r[4], const char a[4])
 }
 
 /* short */
-MINLINE void zero_v3_int(int r[3])
-{
-	r[0] = 0;
-	r[1] = 0;
-	r[2] = 0;
-}
 
 MINLINE void copy_v2_v2_short(short r[2], const short a[2])
 {
@@ -171,6 +165,13 @@ MINLINE void copy_v4_v4_short(short r[4], const short a[4])
 }
 
 /* int */
+MINLINE void zero_v3_int(int r[3])
+{
+	r[0] = 0;
+	r[1] = 0;
+	r[2] = 0;
+}
+
 MINLINE void copy_v2_v2_int(int r[2], const int a[2])
 {
 	r[0] = a[0];
@@ -192,6 +193,35 @@ MINLINE void copy_v4_v4_int(int r[4], const int a[4])
 	r[3] = a[3];
 }
 
+/* double */
+MINLINE void zero_v3_db(double r[3])
+{
+	r[0] = 0.0;
+	r[1] = 0.0;
+	r[2] = 0.0;
+}
+
+MINLINE void copy_v2_v2_db(double r[2], const double a[2])
+{
+	r[0] = a[0];
+	r[1] = a[1];
+}
+
+MINLINE void copy_v3_v3_db(double r[3], const double a[3])
+{
+	r[0] = a[0];
+	r[1] = a[1];
+	r[2] = a[2];
+}
+
+MINLINE void copy_v4_v4_db(double r[4], const double a[4])
+{
+	r[0] = a[0];
+	r[1] = a[1];
+	r[2] = a[2];
+	r[3] = a[3];
+}
+
 /* int <-> float */
 MINLINE void round_v2i_v2fl(int r[2], const float a[2])
 {



More information about the Bf-blender-cvs mailing list