[Bf-blender-cvs] [3ef5ad78d01] geometry-nodes-deduplicate-float-math: continue deduplicating

Jacques Lucke noreply at git.blender.org
Tue Nov 24 17:17:47 CET 2020


Commit: 3ef5ad78d01995bcafb6bd555a3806a834ca1ebe
Author: Jacques Lucke
Date:   Tue Nov 24 16:01:29 2020 +0100
Branches: geometry-nodes-deduplicate-float-math
https://developer.blender.org/rB3ef5ad78d01995bcafb6bd555a3806a834ca1ebe

continue deduplicating

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

M	source/blender/nodes/NOD_math_functions.hh

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

diff --git a/source/blender/nodes/NOD_math_functions.hh b/source/blender/nodes/NOD_math_functions.hh
index 7dbd8f598e4..1997a0bdbe8 100644
--- a/source/blender/nodes/NOD_math_functions.hh
+++ b/source/blender/nodes/NOD_math_functions.hh
@@ -19,6 +19,7 @@
 #include "DNA_node_types.h"
 
 #include "BLI_math_base_safe.h"
+#include "BLI_math_rotation.h"
 #include "BLI_string_ref.hh"
 
 namespace blender::nodes {
@@ -89,10 +90,6 @@ inline bool dispatch_float_math_fl_fl_to_fl(const int operation, OpType &&op)
       op(safe_modf, *info);
       return true;
     }
-    case NODE_MATH_TRUNC: {
-      op([](float a, float b) { return a >= 0.0f ? floorf(a) : ceilf(a); }, *info);
-      return true;
-    }
     case NODE_MATH_SNAP: {
       op([](float a, float b) { return floorf(safe_divide(a, b)) * b; }, *info);
       return true;
@@ -105,4 +102,101 @@ inline bool dispatch_float_math_fl_fl_to_fl(const int operation, OpType &&op)
   return false;
 }
 
+template<typename OpType>
+inline bool dispatch_float_math_fl_to_fl(const int operation, OpType &&op)
+{
+  const FloatMathOperationInfo *info = get_float_math_operation_info(operation);
+  if (info == nullptr) {
+    return false;
+  }
+
+  switch (operation) {
+    case NODE_MATH_EXPONENT: {
+      op(expf, *info);
+      return true;
+    }
+    case NODE_MATH_SQRT: {
+      op(safe_sqrtf, *info);
+      return true;
+    }
+    case NODE_MATH_INV_SQRT: {
+      op(safe_inverse_sqrtf, *info);
+      return true;
+    }
+    case NODE_MATH_ABSOLUTE: {
+      op([](float a) { return fabs(a); }, *info);
+      return true;
+    }
+    case NODE_MATH_RADIANS: {
+      op([](float a) { return DEG2RAD(a); }, *info);
+      return true;
+    }
+    case NODE_MATH_DEGREES: {
+      op([](float a) { return RAD2DEG(a); }, *info);
+      return true;
+    }
+    case NODE_MATH_SIGN: {
+      op(compatible_signf, *info);
+      return true;
+    }
+    case NODE_MATH_ROUND: {
+      op([](float a) { return floorf(a + 0.5f); }, *info);
+      return true;
+    }
+    case NODE_MATH_FLOOR: {
+      op([](float a) { return floorf(a); }, *info);
+      return true;
+    }
+    case NODE_MATH_CEIL: {
+      op([](float a) { return ceilf(a); }, *info);
+      return true;
+    }
+    case NODE_MATH_FRACTION: {
+      op([](float a) { return a - floorf(a); }, *info);
+      return true;
+    }
+    case NODE_MATH_TRUNC: {
+      op([](float a) { return a >= 0.0f ? floorf(a) : ceilf(a); }, *info);
+      return true;
+    }
+    case NODE_MATH_SINE: {
+      op([](float a) { return sinf(a); }, *info);
+      return true;
+    }
+    case NODE_MATH_COSINE: {
+      op([](float a) { return cosf(a); }, *info);
+      return true;
+    }
+    case NODE_MATH_TANGENT: {
+      op([](float a) { return tanf(a); }, *info);
+      return true;
+    }
+    case NODE_MATH_SINH: {
+      op([](float a) { return sinhf(a); }, *info);
+      return true;
+    }
+    case NODE_MATH_COSH: {
+      op([](float a) { return coshf(a); }, *info);
+      return true;
+    }
+    case NODE_MATH_TANH: {
+      op([](float a) { return tanhf(a); }, *info);
+      return true;
+    }
+    case NODE_MATH_ARCSINE: {
+      op([](float a) { return safe_asinf(a); }, *info);
+      return true;
+    }
+    case NODE_MATH_ARCCOSINE: {
+      op([](float a) { return safe_acosf(a); }, *info);
+      return true;
+    }
+    case NODE_MATH_ARCTANGENT: {
+      op([](float a) { return atanf(a); }, *info);
+      return true;
+    }
+  }
+  return false;
+}
+
 }  // namespace blender::nodes



More information about the Bf-blender-cvs mailing list