From d56e6bf1bf82c2112913442e1a416fb6ebcc9fa5 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 14 Jul 2014 11:33:19 +1000 Subject: Math Lib: accept a limit of 0.0 when comparing vectors --- source/blender/blenlib/intern/math_vector_inline.c | 28 ++++++++++++++-------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'source/blender/blenlib/intern/math_vector_inline.c') diff --git a/source/blender/blenlib/intern/math_vector_inline.c b/source/blender/blenlib/intern/math_vector_inline.c index aed604eddb4..4a18987e2e4 100644 --- a/source/blender/blenlib/intern/math_vector_inline.c +++ b/source/blender/blenlib/intern/math_vector_inline.c @@ -883,6 +883,12 @@ MINLINE bool is_one_v3(const float v[3]) return (v[0] == 1 && v[1] == 1 && v[2] == 1); } + +/** \name Vector Comparison + * + * \note use ``value <= limit``, so a limit of zero doesn't fail on an exact match. + * \{ */ + MINLINE bool equals_v2v2(const float v1[2], const float v2[2]) { return ((v1[0] == v2[0]) && (v1[1] == v2[1])); @@ -900,8 +906,8 @@ MINLINE bool equals_v4v4(const float v1[4], const float v2[4]) MINLINE bool compare_v2v2(const float v1[2], const float v2[2], const float limit) { - if (fabsf(v1[0] - v2[0]) < limit) - if (fabsf(v1[1] - v2[1]) < limit) + if (fabsf(v1[0] - v2[0]) <= limit) + if (fabsf(v1[1] - v2[1]) <= limit) return true; return false; @@ -909,9 +915,9 @@ MINLINE bool compare_v2v2(const float v1[2], const float v2[2], const float limi MINLINE bool compare_v3v3(const float v1[3], const float v2[3], const float limit) { - if (fabsf(v1[0] - v2[0]) < limit) - if (fabsf(v1[1] - v2[1]) < limit) - if (fabsf(v1[2] - v2[2]) < limit) + if (fabsf(v1[0] - v2[0]) <= limit) + if (fabsf(v1[1] - v2[1]) <= limit) + if (fabsf(v1[2] - v2[2]) <= limit) return true; return false; @@ -925,15 +931,15 @@ MINLINE bool compare_len_v3v3(const float v1[3], const float v2[3], const float y = v1[1] - v2[1]; z = v1[2] - v2[2]; - return ((x * x + y * y + z * z) < (limit * limit)); + return ((x * x + y * y + z * z) <= (limit * limit)); } MINLINE bool compare_v4v4(const float v1[4], const float v2[4], const float limit) { - if (fabsf(v1[0] - v2[0]) < limit) - if (fabsf(v1[1] - v2[1]) < limit) - if (fabsf(v1[2] - v2[2]) < limit) - if (fabsf(v1[3] - v2[3]) < limit) + if (fabsf(v1[0] - v2[0]) <= limit) + if (fabsf(v1[1] - v2[1]) <= limit) + if (fabsf(v1[2] - v2[2]) <= limit) + if (fabsf(v1[3] - v2[3]) <= limit) return true; return false; @@ -945,4 +951,6 @@ MINLINE float line_point_side_v2(const float l1[2], const float l2[2], const flo ((l2[0] - pt[0]) * (l1[1] - pt[1]))); } +/** \} */ + #endif /* __MATH_VECTOR_INLINE_C__ */ -- cgit v1.2.3 From d9f39257f40d58caa53efcad112df9775f95d8bf Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 14 Jul 2014 11:55:38 +1000 Subject: Math Lib: add compare_len_squared_v3v3 from paint branch --- source/blender/blenlib/intern/math_vector_inline.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'source/blender/blenlib/intern/math_vector_inline.c') diff --git a/source/blender/blenlib/intern/math_vector_inline.c b/source/blender/blenlib/intern/math_vector_inline.c index 4a18987e2e4..135050f4a3f 100644 --- a/source/blender/blenlib/intern/math_vector_inline.c +++ b/source/blender/blenlib/intern/math_vector_inline.c @@ -934,6 +934,17 @@ MINLINE bool compare_len_v3v3(const float v1[3], const float v2[3], const float return ((x * x + y * y + z * z) <= (limit * limit)); } +MINLINE bool compare_len_squared_v3v3(const float v1[3], const float v2[3], const float limit_sq) +{ + float x, y, z; + + x = v1[0] - v2[0]; + y = v1[1] - v2[1]; + z = v1[2] - v2[2]; + + return ((x * x + y * y + z * z) <= limit_sq); +} + MINLINE bool compare_v4v4(const float v1[4], const float v2[4], const float limit) { if (fabsf(v1[0] - v2[0]) <= limit) -- cgit v1.2.3 From 74758576fc9c1220563c86ce47a17c51d08a6d4f Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Wed, 30 Jul 2014 11:00:59 +0200 Subject: Cleanup: general cleanup in BLI_math code (mostly, use 'const' where possible, true/false for booleans, format for float litterals). --- source/blender/blenlib/intern/math_vector_inline.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source/blender/blenlib/intern/math_vector_inline.c') diff --git a/source/blender/blenlib/intern/math_vector_inline.c b/source/blender/blenlib/intern/math_vector_inline.c index 135050f4a3f..0a990e0d63d 100644 --- a/source/blender/blenlib/intern/math_vector_inline.c +++ b/source/blender/blenlib/intern/math_vector_inline.c @@ -850,17 +850,17 @@ MINLINE void normal_float_to_short_v3(short out[3], const float in[3]) MINLINE bool is_zero_v2(const float v[2]) { - return (v[0] == 0 && v[1] == 0); + return (v[0] == 0.0f && v[1] == 0.0f); } MINLINE bool is_zero_v3(const float v[3]) { - return (v[0] == 0 && v[1] == 0 && v[2] == 0); + return (v[0] == 0.0f && v[1] == 0.0f && v[2] == 0.0f); } MINLINE bool is_zero_v4(const float v[4]) { - return (v[0] == 0 && v[1] == 0 && v[2] == 0 && v[3] == 0); + return (v[0] == 0.0f && v[1] == 0.0f && v[2] == 0.0f && v[3] == 0.0f); } MINLINE bool is_finite_v2(const float v[2]) @@ -880,7 +880,7 @@ MINLINE bool is_finite_v4(const float v[4]) MINLINE bool is_one_v3(const float v[3]) { - return (v[0] == 1 && v[1] == 1 && v[2] == 1); + return (v[0] == 1.0f && v[1] == 1.0f && v[2] == 1.0f); } -- cgit v1.2.3 From 1dd17bed4a7a322e6493914fee25ee9562e153ea Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 17 Aug 2014 12:50:48 +1000 Subject: Knife tool: simplify hit-depth calculation --- source/blender/blenlib/intern/math_vector_inline.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source/blender/blenlib/intern/math_vector_inline.c') diff --git a/source/blender/blenlib/intern/math_vector_inline.c b/source/blender/blenlib/intern/math_vector_inline.c index 0a990e0d63d..5529433f6c9 100644 --- a/source/blender/blenlib/intern/math_vector_inline.c +++ b/source/blender/blenlib/intern/math_vector_inline.c @@ -466,7 +466,7 @@ MINLINE float mul_project_m4_v3_zfac(float mat[4][4], const float co[3]) } /** - * Has the effect of mul_m3_v3(), on a single axis. + * Has the effect of #mul_m3_v3(), on a single axis. */ MINLINE float dot_m3_v3_row_x(float M[3][3], const float a[3]) { @@ -482,7 +482,8 @@ MINLINE float dot_m3_v3_row_z(float M[3][3], const float a[3]) } /** - * Almost like mul_m4_v3(), misses adding translation. + * Has the effect of #mul_mat3_m4_v3(), on a single axis. + * (no adding translation) */ MINLINE float dot_m4_v3_row_x(float M[4][4], const float a[3]) { -- cgit v1.2.3