Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2014-07-14 05:33:19 +0400
committerCampbell Barton <ideasman42@gmail.com>2014-07-14 05:33:19 +0400
commitd56e6bf1bf82c2112913442e1a416fb6ebcc9fa5 (patch)
tree99871551af6e080b6eb90d4dfd4aadb96ce8e5b9 /source
parenta720c4715bd76889cf0ce6ae47ef9cfc55c13b78 (diff)
Math Lib: accept a limit of 0.0 when comparing vectors
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenlib/intern/math_vector_inline.c28
1 files changed, 18 insertions, 10 deletions
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__ */