diff options
Diffstat (limited to 'source/blender/blenlib/intern/math_vector_inline.c')
-rw-r--r-- | source/blender/blenlib/intern/math_vector_inline.c | 66 |
1 files changed, 48 insertions, 18 deletions
diff --git a/source/blender/blenlib/intern/math_vector_inline.c b/source/blender/blenlib/intern/math_vector_inline.c index 7fb6b8f6059..33d7f7cdd6d 100644 --- a/source/blender/blenlib/intern/math_vector_inline.c +++ b/source/blender/blenlib/intern/math_vector_inline.c @@ -66,7 +66,7 @@ MINLINE void copy_v3_v3(float r[3], const float a[3]) r[2]= a[2]; } -MINLINE void copy_v4_v4(float r[4], float a[4]) +MINLINE void copy_v4_v4(float r[4], const float a[4]) { r[0]= a[0]; r[1]= a[1]; @@ -97,45 +97,45 @@ MINLINE void swap_v4_v4(float a[4], float b[4]) /********************************* Arithmetic ********************************/ -MINLINE void add_v2_v2(float *r, float *a) +MINLINE void add_v2_v2(float *r, const float *a) { r[0] += a[0]; r[1] += a[1]; } -MINLINE void add_v2_v2v2(float *r, float *a, float *b) +MINLINE void add_v2_v2v2(float *r, const float *a, const float *b) { r[0]= a[0] + b[0]; r[1]= a[1] + b[1]; } -MINLINE void add_v3_v3(float *r, float *a) +MINLINE void add_v3_v3(float *r, const float *a) { r[0] += a[0]; r[1] += a[1]; r[2] += a[2]; } -MINLINE void add_v3_v3v3(float *r, float *a, float *b) +MINLINE void add_v3_v3v3(float *r, const float *a, const float *b) { r[0]= a[0] + b[0]; r[1]= a[1] + b[1]; r[2]= a[2] + b[2]; } -MINLINE void sub_v2_v2(float *r, float *a) +MINLINE void sub_v2_v2(float *r, const float *a) { r[0] -= a[0]; r[1] -= a[1]; } -MINLINE void sub_v2_v2v2(float *r, float *a, float *b) +MINLINE void sub_v2_v2v2(float *r, const float *a, const float *b) { r[0]= a[0] - b[0]; r[1]= a[1] - b[1]; } -MINLINE void sub_v3_v3(float *r, float *a) +MINLINE void sub_v3_v3(float *r, const float *a) { r[0] -= a[0]; r[1] -= a[1]; @@ -181,48 +181,70 @@ MINLINE void mul_v2_v2(float r[2], const float a[2]) r[1] *= a[1]; } -MINLINE void mul_v3_v3(float r[3], float a[3]) +MINLINE void mul_v3_v3(float r[3], const float a[3]) { r[0] *= a[0]; r[1] *= a[1]; r[2] *= a[2]; } -MINLINE void madd_v3_v3fl(float r[3], float a[3], float f) +MINLINE void mul_v4_fl(float r[4], float f) +{ + r[0]*= f; + r[1]*= f; + r[2]*= f; + r[3]*= f; +} + +MINLINE void madd_v2_v2fl(float r[2], const float a[2], float f) +{ + r[0] += a[0]*f; + r[1] += a[1]*f; +} + +MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f) { r[0] += a[0]*f; r[1] += a[1]*f; r[2] += a[2]*f; } -MINLINE void madd_v3_v3v3(float r[3], float a[3], float b[3]) +MINLINE void madd_v3_v3v3(float r[3], const float a[3], const float b[3]) { r[0] += a[0]*b[0]; r[1] += a[1]*b[1]; r[2] += a[2]*b[2]; } -MINLINE void madd_v2_v2v2fl(float r[2], const float a[2], const float b[2], const float f) +MINLINE void madd_v2_v2v2fl(float r[2], const float a[2], const float b[2], float f) { r[0] = a[0] + b[0]*f; r[1] = a[1] + b[1]*f; } -MINLINE void madd_v3_v3v3fl(float r[3], float a[3], float b[3], float f) +MINLINE void madd_v3_v3v3fl(float r[3], const float a[3], const float b[3], float f) { r[0] = a[0] + b[0]*f; r[1] = a[1] + b[1]*f; r[2] = a[2] + b[2]*f; } -MINLINE void madd_v3_v3v3v3(float r[3], float a[3], float b[3], float c[3]) +MINLINE void madd_v3_v3v3v3(float r[3], const float a[3], const float b[3], const float c[3]) { r[0] = a[0] + b[0]*c[0]; r[1] = a[1] + b[1]*c[1]; r[2] = a[2] + b[2]*c[2]; } -MINLINE void mul_v3_v3v3(float *v, float *v1, float *v2) +MINLINE void madd_v4_v4fl(float r[4], const float a[4], float f) +{ + r[0] += a[0]*f; + r[1] += a[1]*f; + r[2] += a[2]*f; + r[3] += a[3]*f; +} + +MINLINE void mul_v3_v3v3(float *v, const float *v1, const float *v2) { v[0] = v1[0] * v2[0]; v[1] = v1[1] * v2[1]; @@ -305,6 +327,14 @@ MINLINE float len_v3v3(const float a[3], const float b[3]) return len_v3(d); } +MINLINE float len_squared_v3v3(const float a[3], const float b[3]) +{ + float d[3]; + + sub_v3_v3v3(d, b, a); + return dot_v3v3(d, d); +} + MINLINE float normalize_v2_v2(float r[2], const float a[2]) { float d= dot_v2v2(a, a); @@ -371,14 +401,14 @@ MINLINE float normalize_v3(float n[3]) return normalize_v3_v3(n, n); } -MINLINE void normal_short_to_float_v3(float *out, short *in) +MINLINE void normal_short_to_float_v3(float *out, const short *in) { out[0] = in[0]*(1.0f/32767.0f); out[1] = in[1]*(1.0f/32767.0f); out[2] = in[2]*(1.0f/32767.0f); } -MINLINE void normal_float_to_short_v3(short *out, float *in) +MINLINE void normal_float_to_short_v3(short *out, const float *in) { out[0] = (short)(in[0]*32767.0f); out[1] = (short)(in[1]*32767.0f); @@ -414,7 +444,7 @@ MINLINE int compare_v3v3(float *v1, float *v2, float limit) MINLINE int compare_len_v3v3(float *v1, float *v2, float limit) { - float x,y,z; + float x,y,z; x=v1[0]-v2[0]; y=v1[1]-v2[1]; |