[Bf-blender-cvs] [f3fd69067a9] bli-math-basic-types: Fix ambiguous definitions

Hans Goudey noreply at git.blender.org
Wed Feb 16 16:34:07 CET 2022


Commit: f3fd69067a94b285f6ec1a36448011956b2cc932
Author: Hans Goudey
Date:   Mon Feb 14 17:27:44 2022 -0600
Branches: bli-math-basic-types
https://developer.blender.org/rBf3fd69067a94b285f6ec1a36448011956b2cc932

Fix ambiguous definitions

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

M	source/blender/blenlib/BLI_math_base.hh

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

diff --git a/source/blender/blenlib/BLI_math_base.hh b/source/blender/blenlib/BLI_math_base.hh
index 9684867afd3..89a3fd3b826 100644
--- a/source/blender/blenlib/BLI_math_base.hh
+++ b/source/blender/blenlib/BLI_math_base.hh
@@ -12,7 +12,7 @@
 #include <type_traits>
 
 #include "BLI_math_base_safe.h"
-#include "BLI_math_vector.h"
+#include "BLI_math_vec_types.hh"
 #include "BLI_utildefines.h"
 
 #ifdef WITH_GMP
@@ -21,41 +21,47 @@
 
 namespace blender::math {
 
+/* To avoid being overly specific about what a "basic" type is, for now simply allow anything that
+ * isn't a `vec_base` type. In the future, if another implementation of these functions is needed,
+ * this would have to become more specific. */
+#define BLI_ENABLE_IF_BASE(T) BLI_ENABLE_IF((!is_math_vec_type<T>))
+
 #ifdef WITH_GMP
 #  define BLI_ENABLE_IF_FLT(T) \
-    BLI_ENABLE_IF((std::is_floating_point_v<T> || std::is_same_v<T, mpq_class>))
+    BLI_ENABLE_IF_BASE(T), \
+        BLI_ENABLE_IF((std::is_floating_point_v<T> || std::is_same_v<T, mpq_class>))
 #else
-#  define BLI_ENABLE_IF_FLT(T) BLI_ENABLE_IF((std::is_floating_point_v<T>))
+#  define BLI_ENABLE_IF_FLT(T) BLI_ENABLE_IF_BASE(T), BLI_ENABLE_IF((std::is_floating_point_v<T>))
 #endif
 
-#define BLI_ENABLE_IF_INT(T) BLI_ENABLE_IF((std::is_integral_v<T>))
+#define BLI_ENABLE_IF_INT(T) BLI_ENABLE_IF_BASE(T), BLI_ENABLE_IF((std::is_integral_v<T>))
 
-template<typename T> inline bool is_zero(const T &a)
+template<typename T, BLI_ENABLE_IF_BASE(T)> inline bool is_zero(const T &a)
 {
   return a == T(0);
 }
 
-template<typename T> inline bool is_any_zero(const T &a)
+template<typename T, BLI_ENABLE_IF_BASE(T)> inline bool is_any_zero(const T &a)
 {
   return is_zero(a);
 }
 
-template<typename T> inline T abs(const T &a)
+template<typename T, BLI_ENABLE_IF_BASE(T)> inline T abs(const T &a)
 {
   return std::abs(a);
 }
 
-template<typename T> inline T min(const T &a, const T &b)
+template<typename T, BLI_ENABLE_IF_BASE(T)> inline T min(const T &a, const T &b)
 {
   return std::min(a, b);
 }
 
-template<typename T> inline T max(const T &a, const T &b)
+template<typename T, BLI_ENABLE_IF_BASE(T)> inline T max(const T &a, const T &b)
 {
   return std::max(a, b);
 }
 
-template<typename T> inline T clamp(const T &a, const T &min, const T &max)
+template<typename T, BLI_ENABLE_IF_BASE(T)> inline T clamp(const T &a, const T &min, const T &max)
 {
   return std::clamp(a, min, max);
 }
@@ -70,7 +76,8 @@ template<typename T, BLI_ENABLE_IF_FLT(T)> inline T safe_mod(const T &a, const T
   return (b != 0) ? std::fmod(a, b) : 0;
 }
 
-template<typename T> inline void min_max(const T &vector, T &min_vec, T &max_vec)
+template<typename T, BLI_ENABLE_IF_BASE(T)>
+inline void min_max(const T &vector, T &min_vec, T &max_vec)
 {
   min_vec = min(vector, min_vec);
   max_vec = max(vector, max_vec);
@@ -107,6 +114,7 @@ template<typename T, BLI_ENABLE_IF_FLT(T)> inline T midpoint(const T &a, const T
   return (a + b) * 0.5;
 }
 
+#undef BLI_ENABLE_IF_BASE
 #undef BLI_ENABLE_IF_FLT
 #undef BLI_ENABLE_IF_INT



More information about the Bf-blender-cvs mailing list