diff options
Diffstat (limited to 'source/blender/blenlib/intern/math_vector_inline.c')
-rw-r--r-- | source/blender/blenlib/intern/math_vector_inline.c | 81 |
1 files changed, 69 insertions, 12 deletions
diff --git a/source/blender/blenlib/intern/math_vector_inline.c b/source/blender/blenlib/intern/math_vector_inline.c index 8530a6ab129..2f808e5d74e 100644 --- a/source/blender/blenlib/intern/math_vector_inline.c +++ b/source/blender/blenlib/intern/math_vector_inline.c @@ -27,8 +27,8 @@ #include "BLI_math.h" -#ifndef BLI_MATH_VECTOR_INLINE -#define BLI_MATH_VECTOR_INLINE +#ifndef BLI_MATH_VECTOR_INLINE_H +#define BLI_MATH_VECTOR_INLINE_H /********************************** Init *************************************/ @@ -149,6 +149,23 @@ MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3]) r[2]= a[2] - b[2]; } +MINLINE void sub_v4_v4(float r[4], const float a[4]) +{ + r[0] -= a[0]; + r[1] -= a[1]; + r[2] -= a[2]; + r[3] -= a[3]; +} + +MINLINE void sub_v4_v4v4(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]; + r[3]= a[3] - b[3]; +} + + MINLINE void mul_v2_fl(float *v1, float f) { v1[0]*= f; @@ -265,6 +282,22 @@ MINLINE void negate_v3_v3(float r[3], const float a[3]) r[2]= -a[2]; } +MINLINE void negate_v4(float r[4]) +{ + r[0]= -r[0]; + r[1]= -r[1]; + r[2]= -r[2]; + r[3]= -r[3]; +} + +MINLINE void negate_v4_v4(float r[4], const float a[4]) +{ + r[0]= -a[0]; + r[1]= -a[1]; + r[2]= -a[2]; + r[3]= -a[3]; +} + MINLINE float dot_v2v2(const float a[2], const float b[2]) { return a[0]*b[0] + a[1]*b[1]; @@ -302,7 +335,7 @@ MINLINE void star_m3_v3(float mat[][3], float *vec) MINLINE float len_v2(const float v[2]) { - return (float)sqrt(v[0]*v[0] + v[1]*v[1]); + return (float)sqrtf(v[0]*v[0] + v[1]*v[1]); } MINLINE float len_v2v2(const float v1[2], const float v2[2]) @@ -311,7 +344,7 @@ MINLINE float len_v2v2(const float v1[2], const float v2[2]) x = v1[0]-v2[0]; y = v1[1]-v2[1]; - return (float)sqrt(x*x+y*y); + return (float)sqrtf(x*x+y*y); } MINLINE float len_v3(const float a[3]) @@ -319,6 +352,14 @@ MINLINE float len_v3(const float a[3]) return sqrtf(dot_v3v3(a, a)); } +MINLINE float len_squared_v2v2(const float a[3], const float b[3]) +{ + float d[2]; + + sub_v2_v2v2(d, b, a); + return dot_v2v2(d, d); +} + MINLINE float len_v3v3(const float a[3], const float b[3]) { float d[3]; @@ -394,27 +435,37 @@ MINLINE void normal_float_to_short_v3(short *out, const float *in) /********************************* Comparison ********************************/ -MINLINE int is_zero_v3(float *v) +MINLINE int is_zero_v3(const float v[3]) { return (v[0] == 0 && v[1] == 0 && v[2] == 0); } -MINLINE int is_one_v3(float *v) +MINLINE int is_zero_v4(const float v[4]) +{ + return (v[0] == 0 && v[1] == 0 && v[2] == 0 && v[3] == 0); +} + +MINLINE int is_one_v3(const float *v) { return (v[0] == 1 && v[1] == 1 && v[2] == 1); } -MINLINE int equals_v3v3(const float *v1,const float *v2) +MINLINE int equals_v2v2(const float *v1, const float *v2) +{ + return ((v1[0]==v2[0]) && (v1[1]==v2[1])); +} + +MINLINE int equals_v3v3(const float *v1, const float *v2) { return ((v1[0]==v2[0]) && (v1[1]==v2[1]) && (v1[2]==v2[2])); } -MINLINE int equals_v4v4(float *v1, float *v2) +MINLINE int equals_v4v4(const float *v1, const float *v2) { return ((v1[0]==v2[0]) && (v1[1]==v2[1]) && (v1[2]==v2[2]) && (v1[3]==v2[3])); } -MINLINE int compare_v3v3(float *v1, float *v2, float limit) +MINLINE int compare_v3v3(const float *v1, const float *v2, const float limit) { if(fabs(v1[0]-v2[0])<limit) if(fabs(v1[1]-v2[1])<limit) @@ -424,7 +475,7 @@ MINLINE int compare_v3v3(float *v1, float *v2, float limit) return 0; } -MINLINE int compare_len_v3v3(float *v1, float *v2, float limit) +MINLINE int compare_len_v3v3(const float *v1, const float *v2, const float limit) { float x,y,z; @@ -435,7 +486,7 @@ MINLINE int compare_len_v3v3(float *v1, float *v2, float limit) return ((x*x + y*y + z*z) < (limit*limit)); } -MINLINE int compare_v4v4(float *v1, float *v2, float limit) +MINLINE int compare_v4v4(const float *v1, const float *v2, const float limit) { if(fabs(v1[0]-v2[0])<limit) if(fabs(v1[1]-v2[1])<limit) @@ -446,5 +497,11 @@ MINLINE int compare_v4v4(float *v1, float *v2, float limit) return 0; } -#endif /* BLI_MATH_VECTOR_INLINE */ +MINLINE float line_point_side_v2(const float *l1, const float *l2, const float *pt) +{ + return ((l1[0]-pt[0]) * (l2[1]-pt[1])) - + ((l2[0]-pt[0]) * (l1[1]-pt[1])); +} + +#endif /* BLI_MATH_VECTOR_INLINE_H */ |