[Bf-blender-cvs] [98b1e09d064] geometry-nodes-point-separate-node: Optimize comparisons by squaring threshold first

Hans Goudey noreply at git.blender.org
Thu Dec 10 16:18:36 CET 2020


Commit: 98b1e09d06440deb8c83f966e0c10b87591584b2
Author: Hans Goudey
Date:   Thu Dec 10 09:09:44 2020 -0600
Branches: geometry-nodes-point-separate-node
https://developer.blender.org/rB98b1e09d06440deb8c83f966e0c10b87591584b2

Optimize comparisons by squaring threshold first

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

M	source/blender/nodes/geometry/nodes/node_geo_attribute_compare.cc

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

diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_compare.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_compare.cc
index dc1fe858b07..7ec27bc85d6 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_attribute_compare.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_compare.cc
@@ -121,11 +121,12 @@ static void do_equal_operation(const Float3ReadAttribute &input_a,
                                const float threshold,
                                MutableSpan<bool> span_result)
 {
+  const float threshold_squared = pow2f(threshold);
   const int size = input_a.size();
   for (const int i : IndexRange(size)) {
     const float3 a = input_a[i];
     const float3 b = input_b[i];
-    span_result[i] = len_v3v3(a, b) < threshold;
+    span_result[i] = len_squared_v3v3(a, b) < threshold_squared;
   }
 }
 
@@ -134,11 +135,12 @@ static void do_equal_operation(const Color4fReadAttribute &input_a,
                                const float threshold,
                                MutableSpan<bool> span_result)
 {
+  const float threshold_squared = pow2f(threshold);
   const int size = input_a.size();
   for (const int i : IndexRange(size)) {
     const Color4f a = input_a[i];
     const Color4f b = input_b[i];
-    span_result[i] = sqrtf(len_squared_v4v4(a, b)) < threshold;
+    span_result[i] = len_squared_v4v4(a, b) < threshold_squared;
   }
 }
 
@@ -173,12 +175,12 @@ static void do_not_equal_operation(const Float3ReadAttribute &input_a,
                                    const float threshold,
                                    MutableSpan<bool> span_result)
 {
+  const float threshold_squared = pow2f(threshold);
   const int size = input_a.size();
   for (const int i : IndexRange(size)) {
     const float3 a = input_a[i];
     const float3 b = input_b[i];
-
-    span_result[i] = len_v3v3(a, b) >= threshold;
+    span_result[i] = len_squared_v3v3(a, b) >= threshold_squared;
   }
 }
 
@@ -187,11 +189,12 @@ static void do_not_equal_operation(const Color4fReadAttribute &input_a,
                                    const float threshold,
                                    MutableSpan<bool> span_result)
 {
+  const float threshold_squared = pow2f(threshold);
   const int size = input_a.size();
   for (const int i : IndexRange(size)) {
     const Color4f a = input_a[i];
     const Color4f b = input_b[i];
-    span_result[i] = sqrtf(len_squared_v4v4(a, b)) >= threshold;
+    span_result[i] = len_squared_v4v4(a, b) >= threshold_squared;
   }
 }



More information about the Bf-blender-cvs mailing list