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
diff options
context:
space:
mode:
authorHimanshi Kalra <calra>2021-08-23 22:19:36 +0300
committerHimanshi Kalra <himanshikalra98@gmail.com>2021-08-23 22:20:03 +0300
commit875c2ea5b5ee8425c3bc969dbaba3fab3ecbaab4 (patch)
tree94d45e8fb3d508e77aa177d253c39186b9863e30 /source/blender/blenlib/intern
parentbe1891e895c012b36ca574a90b5d90fc1433152e (diff)
Using relative threshold for floats in mesh comparison
Changes the threshold comparison from absolute to relative. Removes threshold for MLoopCol comparison. Adds a compare relative threshold function. Reviewed By: JacquesLucke Differential Revision: https://developer.blender.org/D12273
Diffstat (limited to 'source/blender/blenlib/intern')
-rw-r--r--source/blender/blenlib/intern/math_base_inline.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/math_base_inline.c b/source/blender/blenlib/intern/math_base_inline.c
index 983fd3b6543..49f9faf1704 100644
--- a/source/blender/blenlib/intern/math_base_inline.c
+++ b/source/blender/blenlib/intern/math_base_inline.c
@@ -656,6 +656,18 @@ MINLINE int compare_ff_relative(float a, float b, const float max_diff, const in
return ((ua.i < 0) != (ub.i < 0)) ? 0 : (abs(ua.i - ub.i) <= max_ulps) ? 1 : 0;
}
+MINLINE bool compare_threshold_relative(const float value1, const float value2, const float thresh)
+{
+ const float abs_diff = fabsf(value1 - value2);
+ /* Avoid letting the threshold get too small just because the values happen to be close to zero.
+ */
+ if (fabsf(value2) < 1) {
+ return abs_diff > thresh;
+ }
+ /* Using relative threshold in general. */
+ return abs_diff > thresh * fabsf(value2);
+}
+
MINLINE float signf(float f)
{
return (f < 0.0f) ? -1.0f : 1.0f;