diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-11-24 08:12:16 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-11-24 08:12:16 +0400 |
commit | c62d33c540830188207bc32d5e3fc5a2134f5ab1 (patch) | |
tree | 5d996cc183651123d518ead7d9a3a6a951c77348 /source/blender/blenlib | |
parent | f94614d791b1381bc4751ad5194680cec81a4b57 (diff) |
patch: [#29382] Arbitrary Length Array Function Additions and Modifications
from Andrew Hale (trumanblending), with some edits to use these in mathutils.Vector added.
Added Functions:
- dot_vn_vn - Dot product of two arrays
- normalize_vn_vn - Normalize an array and store the result in a second array
- normalize_vn - Normalize an array inplace
Renamed Functions:
Some functions have been renamed to make them consistent with the naming conventions used by fixed length array functions.
- fill_vni to fill_vn_i
- fill_vn to fill_vn_fl
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_math_vector.h | 11 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_vector.c | 36 |
2 files changed, 40 insertions, 7 deletions
diff --git a/source/blender/blenlib/BLI_math_vector.h b/source/blender/blenlib/BLI_math_vector.h index 2b9d6d2d6d6..d8e880a9dec 100644 --- a/source/blender/blenlib/BLI_math_vector.h +++ b/source/blender/blenlib/BLI_math_vector.h @@ -194,17 +194,20 @@ void minmax_v3v3_v3(float min[3], float max[3], const float vec[3]); /***************************** Array Functions *******************************/ /* attempted to follow fixed length vertex functions. names could be improved*/ -void range_vni(int *array, const int size, const int start); +double dot_vn_vn(const float *array_src_a, const float *array_src_b, const int size); +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); void negate_vn(float *array_tar, const int size); void negate_vn_vn(float *array_tar, const float *array_src, const int size); -void mul_vn_fl(float *array, const int size, const float f); +void mul_vn_fl(float *array_tar, const int size, const float f); void mul_vn_vn_fl(float *array_tar, const float *array_src, const int size, const float f); void add_vn_vn(float *array_tar, const float *array_src, const int size); void add_vn_vnvn(float *array_tar, const float *array_src_a, const float *array_src_b, const int size); void sub_vn_vn(float *array_tar, const float *array_src, const int size); void sub_vn_vnvn(float *array_tar, const float *array_src_a, const float *array_src_b, const int size); -void fill_vni(int *array_tar, const int size, const int val); -void fill_vn(float *array_tar, const int size, const float val); +void fill_vn_i(int *array_tar, const int size, const int val); +void fill_vn_fl(float *array_tar, const int size, const float val); #ifdef __cplusplus } diff --git a/source/blender/blenlib/intern/math_vector.c b/source/blender/blenlib/intern/math_vector.c index 01c3e112cd8..a9ea90ef555 100644 --- a/source/blender/blenlib/intern/math_vector.c +++ b/source/blender/blenlib/intern/math_vector.c @@ -378,7 +378,37 @@ void minmax_v3v3_v3(float min[3], float max[3], const float vec[3]) /***************************** Array Functions *******************************/ -void range_vni(int *array_tar, const int size, const int start) +double dot_vn_vn(const float *array_src_a, const float *array_src_b, const int size) +{ + double d= 0.0f; + const float *array_pt_a= array_src_a + (size-1); + const float *array_pt_b= array_src_b + (size-1); + int i= size; + while(i--) { d += *(array_pt_a--) * *(array_pt_b--); } + 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); + float d_sqrt; + if (d > 1.0e-35) { + d_sqrt= (float)sqrt(d); + mul_vn_vn_fl(array_tar, array_src, size, 1.0f/d_sqrt); + } + else { + fill_vn_fl(array_tar, size, 0.0f); + d_sqrt= 0.0f; + } + return d_sqrt; +} + +float normalize_vn(float *array_tar, const int size) +{ + return normalize_vn_vn(array_tar, array_tar, size); +} + +void range_vn_i(int *array_tar, const int size, const int start) { int *array_pt= array_tar + (size-1); int j= start + (size-1); @@ -450,14 +480,14 @@ void sub_vn_vnvn(float *array_tar, const float *array_src_a, const float *array_ while(i--) { *(tar--) = *(src_a--) - *(src_b--); } } -void fill_vni(int *array_tar, const int size, const int val) +void fill_vn_i(int *array_tar, const int size, const int val) { int *tar= array_tar + (size-1); int i= size; while(i--) { *(tar--) = val; } } -void fill_vn(float *array_tar, const int size, const float val) +void fill_vn_fl(float *array_tar, const int size, const float val) { float *tar= array_tar + (size-1); int i= size; |