[Bf-blender-cvs] [e57d50d4d40] greasepencil-object: GPencil: Cleanup equals functions and add for floats and V2
Antonioya
noreply at git.blender.org
Sat Jul 6 11:56:15 CEST 2019
Commit: e57d50d4d400f33753306c9938c4ed642e627a88
Author: Antonioya
Date: Sat Jul 6 11:48:48 2019 +0200
Branches: greasepencil-object
https://developer.blender.org/rBe57d50d4d400f33753306c9938c4ed642e627a88
GPencil: Cleanup equals functions and add for floats and V2
===================================================================
M source/blender/blenkernel/intern/gpencil.c
===================================================================
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index a09340ef82f..0d13727edf6 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -2044,29 +2044,34 @@ bool BKE_gpencil_close_stroke(bGPDstroke *gps)
return true;
}
-/* Check if to v3 are equal but with a limit in the precission to get some tolerance.
+/* Check if two floats are equal but with a limit in the precission to get some tolerance.
*
* \param v1: First value.
* \param v2: Second value.
* \param limit: Maximum difference limit.
* \return: True
*/
-static bool equals_v4v4_limit(const float v1[4], const float v2[4], const float limit)
+static bool equals_f_f_limit(const float v1, const float v2, const float limit)
{
- float vd[4];
- vd[0] = fabsf(v1[0] - v2[0]);
- vd[1] = fabsf(v1[1] - v2[1]);
- vd[2] = fabsf(v1[2] - v2[2]);
- vd[3] = fabsf(v1[3] - v2[3]);
-
- if ((vd[0] > limit) || (vd[1] > limit) || (vd[2] > limit) || (vd[3] > limit)) {
+ if (fabsf(v1 - v2) > limit) {
return false;
}
-
return true;
}
-/* Check if to v3 are equal but with a limit in the precission to get some tolerance.
+/* Check if two v2 are equal but with a limit in the precission to get some tolerance.
+ *
+ * \param v1: First value.
+ * \param v2: Second value.
+ * \param limit: Maximum difference limit.
+ * \return: True
+ */
+static bool equals_v2v2_limit(const float v1[2], const float v2[2], const float limit)
+{
+ return (bool)(equals_f_f_limit(v1[0], v2[0], limit) && equals_f_f_limit(v1[1], v2[1], limit));
+}
+
+/* Check if two v3 are equal but with a limit in the precission to get some tolerance.
*
* \param v1: First value.
* \param v2: Second value.
@@ -2075,10 +2080,21 @@ static bool equals_v4v4_limit(const float v1[4], const float v2[4], const float
*/
static bool equals_v3v3_limit(const float v1[3], const float v2[3], const float limit)
{
- float v1a[4], v2a[4];
- ARRAY_SET_ITEMS(v1a, v1[0], v1[1], v1[2], 0.0f);
- ARRAY_SET_ITEMS(v2a, v2[0], v2[1], v2[2], 0.0f);
- return equals_v4v4_limit(v1a, v2a, limit);
+ return (bool)(equals_f_f_limit(v1[0], v2[0], limit) && equals_f_f_limit(v1[1], v2[1], limit) &&
+ equals_f_f_limit(v1[2], v2[2], limit));
+}
+
+/* Check if two v4 are equal but with a limit in the precission to get some tolerance.
+ *
+ * \param v1: First value.
+ * \param v2: Second value.
+ * \param limit: Maximum difference limit.
+ * \return: True
+ */
+static bool equals_v4v4_limit(const float v1[4], const float v2[4], const float limit)
+{
+ return (bool)(equals_f_f_limit(v1[0], v2[0], limit) && equals_f_f_limit(v1[1], v2[1], limit) &&
+ equals_f_f_limit(v1[2], v2[2], limit) && equals_f_f_limit(v1[3], v2[3], limit));
}
/* Helper function to check materials with same color */
More information about the Bf-blender-cvs
mailing list