[Bf-blender-cvs] [480c501] master: Code cleanup: reflect_v3_v3v3 made redundant copies

Campbell Barton noreply at git.blender.org
Sun Mar 30 03:28:40 CEST 2014


Commit: 480c5019bb2359a96f56e52f406250210946d51b
Author: Campbell Barton
Date:   Sun Mar 30 12:23:19 2014 +1100
https://developer.blender.org/rB480c5019bb2359a96f56e52f406250210946d51b

Code cleanup: reflect_v3_v3v3 made redundant copies

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

M	source/blender/blenlib/intern/math_vector.c

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

diff --git a/source/blender/blenlib/intern/math_vector.c b/source/blender/blenlib/intern/math_vector.c
index d3869f3..19865aa 100644
--- a/source/blender/blenlib/intern/math_vector.c
+++ b/source/blender/blenlib/intern/math_vector.c
@@ -471,25 +471,19 @@ void bisect_v3_v3v3v3(float out[3], const float v1[3], const float v2[3], const
 	normalize_v3(out);
 }
 
-/* Returns a reflection vector from a vector and a normal vector
+/**
+ * Returns a reflection vector from a vector and a normal vector
  * reflect = vec - ((2 * DotVecs(vec, mirror)) * mirror)
  */
-void reflect_v3_v3v3(float out[3], const float v1[3], const float v2[3])
+void reflect_v3_v3v3(float out[3], const float vec[3], const float normal[3])
 {
-	float vec[3], normal[3];
-	float reflect[3] = {0.0f, 0.0f, 0.0f};
-	float dot2;
-
-	copy_v3_v3(vec, v1);
-	copy_v3_v3(normal, v2);
-
-	dot2 = 2 * dot_v3v3(vec, normal);
+	const float dot2 = 2.0f * dot_v3v3(vec, normal);
 
-	reflect[0] = vec[0] - (dot2 * normal[0]);
-	reflect[1] = vec[1] - (dot2 * normal[1]);
-	reflect[2] = vec[2] - (dot2 * normal[2]);
+	BLI_ASSERT_UNIT_V3(normal);
 
-	copy_v3_v3(out, reflect);
+	out[0] = vec[0] - (dot2 * normal[0]);
+	out[1] = vec[1] - (dot2 * normal[1]);
+	out[2] = vec[2] - (dot2 * normal[2]);
 }
 
 void ortho_basis_v3v3_v3(float v1[3], float v2[3], const float v[3])




More information about the Bf-blender-cvs mailing list