diff options
author | Campbell Barton <ideasman42@gmail.com> | 2014-03-31 04:17:46 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2014-03-31 04:19:32 +0400 |
commit | 6aa75d3b2c3d4a5dc58120a51fdee0a7c12ab93c (patch) | |
tree | 86898d7de3be6a175d8cfe6190dd6750a40c0eb1 /source/blender/blenlib | |
parent | e001b5b33ec1fa8897b5fdc0b125a813ec6a4cd1 (diff) |
Fix for error in normalize_vn_vn(), add len_squared_vn
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_math_vector.h | 1 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_vector.c | 18 |
2 files changed, 18 insertions, 1 deletions
diff --git a/source/blender/blenlib/BLI_math_vector.h b/source/blender/blenlib/BLI_math_vector.h index e6e46a4d8cd..9ef2dc781de 100644 --- a/source/blender/blenlib/BLI_math_vector.h +++ b/source/blender/blenlib/BLI_math_vector.h @@ -285,6 +285,7 @@ void axis_sort_v3(const float axis_values[3], int r_axis_order[3]); /***************************** Array Functions *******************************/ /* attempted to follow fixed length vertex functions. names could be improved*/ double dot_vn_vn(const float *array_src_a, const float *array_src_b, const int size) ATTR_WARN_UNUSED_RESULT; +double len_squared_vn(const float *array, const int size) ATTR_WARN_UNUSED_RESULT; float normalize_vn_vn(float *array_tar, const float *array_src, const int size); float normalize_vn(float *array_tar, const int size); void range_vn_i(int *array_tar, const int size, const int start); diff --git a/source/blender/blenlib/intern/math_vector.c b/source/blender/blenlib/intern/math_vector.c index 19865aa00bd..3fbddacaea2 100644 --- a/source/blender/blenlib/intern/math_vector.c +++ b/source/blender/blenlib/intern/math_vector.c @@ -665,6 +665,11 @@ void axis_sort_v3(const float axis_values[3], int r_axis_order[3]) /***************************** Array Functions *******************************/ +MINLINE double sqr_db(double f) +{ + return f * f; +} + double dot_vn_vn(const float *array_src_a, const float *array_src_b, const int size) { double d = 0.0f; @@ -677,9 +682,20 @@ double dot_vn_vn(const float *array_src_a, const float *array_src_b, const int s return d; } +double len_squared_vn(const float *array, const int size) +{ + double d = 0.0f; + const float *array_pt = array + (size - 1); + int i = size; + while (i--) { + d += sqr_db((double)(*(array_pt--))); + } + return d; +} + float normalize_vn_vn(float *array_tar, const float *array_src, const int size) { - double d = dot_vn_vn(array_tar, array_src, size); + double d = len_squared_vn(array_src, size); float d_sqrt; if (d > 1.0e-35) { d_sqrt = (float)sqrt(d); |