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') 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