diff options
author | Campbell Barton <ideasman42@gmail.com> | 2016-07-08 02:52:29 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2016-07-08 02:52:29 +0300 |
commit | 6035cf05bf1c794c35e89fbf467cfc35901d81e3 (patch) | |
tree | 0f1464facc3b8188e7ba5873f6b63371b7a6832d /source/blender/blenlib/intern/math_vector_inline.c | |
parent | 30d951ce34da6a1c3c17268505a91f1b9cf38087 (diff) |
BLI_math: add normalize functions which fit to a length
Convenient since its common to normalize then scale,
since these are inlined, use for regular normalize w/ 1.0 length.
Diffstat (limited to 'source/blender/blenlib/intern/math_vector_inline.c')
-rw-r--r-- | source/blender/blenlib/intern/math_vector_inline.c | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/source/blender/blenlib/intern/math_vector_inline.c b/source/blender/blenlib/intern/math_vector_inline.c index fd9f3d5ff99..e9fb77f6302 100644 --- a/source/blender/blenlib/intern/math_vector_inline.c +++ b/source/blender/blenlib/intern/math_vector_inline.c @@ -859,13 +859,13 @@ MINLINE float len_v3v3(const float a[3], const float b[3]) return len_v3(d); } -MINLINE float normalize_v2_v2(float r[2], const float a[2]) +MINLINE float normalize_v2_v2_length(float r[2], const float a[2], const float unit_length) { float d = dot_v2v2(a, a); if (d > 1.0e-35f) { d = sqrtf(d); - mul_v2_v2fl(r, a, 1.0f / d); + mul_v2_v2fl(r, a, unit_length / d); } else { zero_v2(r); @@ -874,13 +874,22 @@ MINLINE float normalize_v2_v2(float r[2], const float a[2]) return d; } +MINLINE float normalize_v2_v2(float r[2], const float a[2]) +{ + return normalize_v2_v2_length(r, a, 1.0f); +} MINLINE float normalize_v2(float n[2]) { return normalize_v2_v2(n, n); } -MINLINE float normalize_v3_v3(float r[3], const float a[3]) +MINLINE float normalize_v2_length(float n[2], const float unit_length) +{ + return normalize_v2_v2_length(n, n, unit_length); +} + +MINLINE float normalize_v3_v3_length(float r[3], const float a[3], const float unit_length) { float d = dot_v3v3(a, a); @@ -888,7 +897,7 @@ MINLINE float normalize_v3_v3(float r[3], const float a[3]) * scaled down models with camera extreme close */ if (d > 1.0e-35f) { d = sqrtf(d); - mul_v3_v3fl(r, a, 1.0f / d); + mul_v3_v3fl(r, a, unit_length / d); } else { zero_v3(r); @@ -897,8 +906,12 @@ MINLINE float normalize_v3_v3(float r[3], const float a[3]) return d; } +MINLINE float normalize_v3_v3(float r[3], const float a[3]) +{ + return normalize_v3_v3_length(r, a, 1.0f); +} -MINLINE double normalize_v3_d(double n[3]) +MINLINE double normalize_v3_length_d(double n[3], const double unit_length) { double d = n[0] * n[0] + n[1] * n[1] + n[2] * n[2]; @@ -908,7 +921,7 @@ MINLINE double normalize_v3_d(double n[3]) double mul; d = sqrt(d); - mul = 1.0 / d; + mul = unit_length / d; n[0] *= mul; n[1] *= mul; @@ -921,6 +934,15 @@ MINLINE double normalize_v3_d(double n[3]) return d; } +MINLINE double normalize_v3_d(double n[3]) +{ + return normalize_v3_length_d(n, 1.0); +} + +MINLINE float normalize_v3_length(float n[3], const float unit_length) +{ + return normalize_v3_v3_length(n, n, unit_length); +} MINLINE float normalize_v3(float n[3]) { |