From 480c5019bb2359a96f56e52f406250210946d51b Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 30 Mar 2014 12:23:19 +1100 Subject: [PATCH] Code cleanup: reflect_v3_v3v3 made redundant copies --- source/blender/blenlib/intern/math_vector.c | 22 ++++++++------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/source/blender/blenlib/intern/math_vector.c b/source/blender/blenlib/intern/math_vector.c index d3869f307fb..19865aa00bd 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; + const float dot2 = 2.0f * dot_v3v3(vec, normal); - copy_v3_v3(vec, v1); - copy_v3_v3(normal, v2); + BLI_ASSERT_UNIT_V3(normal); - dot2 = 2 * 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]); - - 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])