[Bf-blender-cvs] [d56e6bf] master: Math Lib: accept a limit of 0.0 when comparing vectors

Campbell Barton noreply at git.blender.org
Mon Jul 14 03:34:52 CEST 2014


Commit: d56e6bf1bf82c2112913442e1a416fb6ebcc9fa5
Author: Campbell Barton
Date:   Mon Jul 14 11:33:19 2014 +1000
https://developer.blender.org/rBd56e6bf1bf82c2112913442e1a416fb6ebcc9fa5

Math Lib: accept a limit of 0.0 when comparing vectors

===================================================================

M	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 aed604e..4a18987 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__ */




More information about the Bf-blender-cvs mailing list