[Bf-blender-cvs] [8a9a7199abb] bli-math-basic-types: BLI: Change dependencies in vector math files

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


Commit: 8a9a7199abbe83f6d2d7ceeec9052b50cd4202a9
Author: Hans Goudey
Date:   Mon Feb 14 16:12:37 2022 -0600
Branches: bli-math-basic-types
https://developer.blender.org/rB8a9a7199abbe83f6d2d7ceeec9052b50cd4202a9

BLI: Change dependencies in vector math files

This patch reverses the dependency between `BLI_math_vec_types.hh` and
`BLI_math_vector.hh`. Now the higher level `blender::math` functions
depend on the header that defines the types they work with, rather than
the other way around.

This required changing the includes some files used from the type
header to the math implementation header. I took that change a bit
further removing the C vector math header from the C++ header;
I think that helps to make the transition between the two systems
clearer.

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

M	source/blender/blenkernel/BKE_attribute_math.hh
M	source/blender/blenkernel/intern/curves.cc
M	source/blender/blenkernel/intern/mesh.cc
M	source/blender/blenkernel/intern/mesh_remesh_voxel.cc
M	source/blender/blenkernel/intern/tracking_test.cc
M	source/blender/blenkernel/intern/type_conversions.cc
M	source/blender/blenlib/BLI_float4x4.hh
M	source/blender/blenlib/BLI_math_vec_mpq_types.hh
M	source/blender/blenlib/BLI_math_vec_types.hh
M	source/blender/blenlib/BLI_math_vector.hh
M	source/blender/blenlib/intern/mesh_boolean.cc
M	source/blender/blenlib/intern/mesh_intersect.cc
M	source/blender/blenlib/intern/noise.cc
M	source/blender/editors/space_node/node_intern.hh
M	source/blender/geometry/intern/mesh_merge_by_distance.cc
M	source/blender/io/wavefront_obj/exporter/obj_export_mtl.cc
M	source/blender/nodes/NOD_math_functions.hh
M	source/blender/nodes/composite/nodes/node_composite_chroma_matte.cc
M	source/blender/nodes/function/node_function_util.hh
M	source/blender/nodes/function/nodes/node_fn_align_euler_to_vector.cc
M	source/blender/nodes/function/nodes/node_fn_rotate_euler.cc
M	source/blender/nodes/shader/node_shader_util.hh

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

diff --git a/source/blender/blenkernel/BKE_attribute_math.hh b/source/blender/blenkernel/BKE_attribute_math.hh
index a81ab78a621..42bff89922b 100644
--- a/source/blender/blenkernel/BKE_attribute_math.hh
+++ b/source/blender/blenkernel/BKE_attribute_math.hh
@@ -4,7 +4,8 @@
 
 #include "BLI_array.hh"
 #include "BLI_color.hh"
-#include "BLI_math_vec_types.hh"
+#include "BLI_math_vector.h"
+#include "BLI_math_vector.hh"
 
 #include "DNA_customdata_types.h"
 
diff --git a/source/blender/blenkernel/intern/curves.cc b/source/blender/blenkernel/intern/curves.cc
index 097cfbf3101..ccc20d5118a 100644
--- a/source/blender/blenkernel/intern/curves.cc
+++ b/source/blender/blenkernel/intern/curves.cc
@@ -17,7 +17,7 @@
 #include "BLI_index_range.hh"
 #include "BLI_listbase.h"
 #include "BLI_math_base.h"
-#include "BLI_math_vec_types.hh"
+#include "BLI_math_vector.hh"
 #include "BLI_rand.hh"
 #include "BLI_string.h"
 #include "BLI_utildefines.h"
diff --git a/source/blender/blenkernel/intern/mesh.cc b/source/blender/blenkernel/intern/mesh.cc
index 4e855b6dc2c..6ca5babbf13 100644
--- a/source/blender/blenkernel/intern/mesh.cc
+++ b/source/blender/blenkernel/intern/mesh.cc
@@ -26,7 +26,7 @@
 #include "BLI_linklist.h"
 #include "BLI_listbase.h"
 #include "BLI_math.h"
-#include "BLI_math_vec_types.hh"
+#include "BLI_math_vector.hh"
 #include "BLI_memarena.h"
 #include "BLI_string.h"
 #include "BLI_task.hh"
diff --git a/source/blender/blenkernel/intern/mesh_remesh_voxel.cc b/source/blender/blenkernel/intern/mesh_remesh_voxel.cc
index 5067d67a6c8..b34a241bca8 100644
--- a/source/blender/blenkernel/intern/mesh_remesh_voxel.cc
+++ b/source/blender/blenkernel/intern/mesh_remesh_voxel.cc
@@ -17,6 +17,7 @@
 #include "BLI_array.hh"
 #include "BLI_index_range.hh"
 #include "BLI_math_vec_types.hh"
+#include "BLI_math_vector.h"
 #include "BLI_span.hh"
 
 #include "DNA_mesh_types.h"
diff --git a/source/blender/blenkernel/intern/tracking_test.cc b/source/blender/blenkernel/intern/tracking_test.cc
index 7c93e4b5406..42bbf23ea44 100644
--- a/source/blender/blenkernel/intern/tracking_test.cc
+++ b/source/blender/blenkernel/intern/tracking_test.cc
@@ -6,6 +6,7 @@
 
 #include "BKE_tracking.h"
 #include "BLI_math_vec_types.hh"
+#include "BLI_math_vector.h"
 
 namespace blender {
 
diff --git a/source/blender/blenkernel/intern/type_conversions.cc b/source/blender/blenkernel/intern/type_conversions.cc
index 4ab945d14c6..2e8b5b3433b 100644
--- a/source/blender/blenkernel/intern/type_conversions.cc
+++ b/source/blender/blenkernel/intern/type_conversions.cc
@@ -5,7 +5,7 @@
 #include "FN_multi_function_builder.hh"
 
 #include "BLI_color.hh"
-#include "BLI_math_vec_types.hh"
+#include "BLI_math_vector.hh"
 
 namespace blender::bke {
 
@@ -72,7 +72,7 @@ static int float2_to_int(const float2 &a)
 }
 static bool float2_to_bool(const float2 &a)
 {
-  return !is_zero_v2(a);
+  return !math::is_zero(a);
 }
 static int8_t float2_to_int8(const float2 &a)
 {
@@ -85,7 +85,7 @@ static ColorGeometry4f float2_to_color(const float2 &a)
 
 static bool float3_to_bool(const float3 &a)
 {
-  return !is_zero_v3(a);
+  return !math::is_zero(a);
 }
 static int8_t float3_to_int8(const float3 &a)
 {
diff --git a/source/blender/blenlib/BLI_float4x4.hh b/source/blender/blenlib/BLI_float4x4.hh
index 60765aaec09..9f7fbffc692 100644
--- a/source/blender/blenlib/BLI_float4x4.hh
+++ b/source/blender/blenlib/BLI_float4x4.hh
@@ -5,6 +5,7 @@
 #include "BLI_math_matrix.h"
 #include "BLI_math_vec_types.hh"
 #include "BLI_math_vector.h"
+#include "BLI_math_vector.hh"
 
 namespace blender {
 
diff --git a/source/blender/blenlib/BLI_math_vec_mpq_types.hh b/source/blender/blenlib/BLI_math_vec_mpq_types.hh
index a7dad2921dd..45c416a5734 100644
--- a/source/blender/blenlib/BLI_math_vec_mpq_types.hh
+++ b/source/blender/blenlib/BLI_math_vec_mpq_types.hh
@@ -6,7 +6,7 @@
  * \ingroup bli
  */
 
-#include "BLI_math_vec_types.hh"
+#include "BLI_math_vector.hh"
 
 #ifdef WITH_GMP
 
diff --git a/source/blender/blenlib/BLI_math_vec_types.hh b/source/blender/blenlib/BLI_math_vec_types.hh
index 192284cb8fc..140367b6241 100644
--- a/source/blender/blenlib/BLI_math_vec_types.hh
+++ b/source/blender/blenlib/BLI_math_vec_types.hh
@@ -12,7 +12,6 @@
 #include <iostream>
 #include <type_traits>
 
-#include "BLI_math_vector.hh"
 #include "BLI_utildefines.h"
 
 namespace blender {
@@ -41,6 +40,28 @@ template<typename T> struct vec_struct_base<T, 4> {
   T x, y, z, w;
 };
 
+namespace math {
+
+template<typename T> uint64_t vector_hash(const T &vec)
+{
+  BLI_STATIC_ASSERT(T::type_length <= 4, "Longer types need to implement vector_hash themself.");
+  const typename T::uint_type &uvec = *reinterpret_cast<const typename T::uint_type *>(&vec);
+  uint64_t result;
+  result = uvec[0] * uint64_t(435109);
+  if constexpr (T::type_length > 1) {
+    result ^= uvec[1] * uint64_t(380867);
+  }
+  if constexpr (T::type_length > 2) {
+    result ^= uvec[2] * uint64_t(1059217);
+  }
+  if constexpr (T::type_length > 3) {
+    result ^= uvec[3] * uint64_t(2002613);
+  }
+  return result;
+}
+
+}  // namespace math
+
 template<typename T, int Size> struct vec_base : public vec_struct_base<T, Size> {
 
   static constexpr int type_length = Size;
@@ -234,6 +255,16 @@ template<typename T, int Size> struct vec_base : public vec_struct_base<T, Size>
   } \
   return *this;
 
+  bool is_any_zero() const
+  {
+    for (int i = 0; i < Size; i++) {
+      if ((*this)[i] == T(0)) {
+        return true;
+      }
+    }
+    return false;
+  }
+
   /** Arithmetic operators. */
 
   friend vec_base operator+(const vec_base &a, const vec_base &b)
@@ -318,7 +349,7 @@ template<typename T, int Size> struct vec_base : public vec_struct_base<T, Size>
 
   friend vec_base operator/(const vec_base &a, const vec_base &b)
   {
-    BLI_assert(!math::is_any_zero(b));
+    BLI_assert(!b.is_any_zero());
     BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] / b[i]);
   }
 
@@ -330,19 +361,19 @@ template<typename T, int Size> struct vec_base : public vec_struct_base<T, Size>
 
   friend vec_base operator/(T a, const vec_base &b)
   {
-    BLI_assert(!math::is_any_zero(b));
+    BLI_assert(!b.is_any_zero());
     BLI_VEC_OP_IMPL(ret, i, ret[i] = a / b[i]);
   }
 
   vec_base &operator/=(T b)
   {
-    BLI_assert(b != T(0));
+    BLI_assert(!b.is_any_zero());
     BLI_VEC_OP_IMPL_SELF(i, (*this)[i] /= b);
   }
 
   vec_base &operator/=(const vec_base &b)
   {
-    BLI_assert(!math::is_any_zero(b));
+    BLI_assert(!b != T(0));
     BLI_VEC_OP_IMPL_SELF(i, (*this)[i] /= b[i]);
   }
 
@@ -474,7 +505,7 @@ template<typename T, int Size> struct vec_base : public vec_struct_base<T, Size>
 
   BLI_INT_OP(T) friend vec_base operator%(const vec_base &a, const vec_base &b)
   {
-    BLI_assert(!math::is_any_zero(b));
+    BLI_assert(!b.is_any_zero());
     BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] % b[i]);
   }
 
@@ -486,7 +517,7 @@ template<typename T, int Size> struct vec_base : public vec_struct_base<T, Size>
 
   BLI_INT_OP(T) friend vec_base operator%(T a, const vec_base &b)
   {
-    BLI_assert(!math::is_any_zero(b));
+    BLI_assert(b != T(0));
     BLI_VEC_OP_IMPL(ret, i, ret[i] = a % b[i]);
   }
 
diff --git a/source/blender/blenlib/BLI_math_vector.hh b/source/blender/blenlib/BLI_math_vector.hh
index 930f3b62fa5..302ab39a0b9 100644
--- a/source/blender/blenlib/BLI_math_vector.hh
+++ b/source/blender/blenlib/BLI_math_vector.hh
@@ -11,7 +11,7 @@
 #include <type_traits>
 
 #include "BLI_math_base_safe.h"
-#include "BLI_math_vector.h"
+#include "BLI_math_vec_types.hh"
 #include "BLI_span.hh"
 #include "BLI_utildefines.h"
 
@@ -241,24 +241,6 @@ template<typename T, BLI_ENABLE_IF_FLT_VEC(T)> inline bT distance(const T &a, co
   return length(a - b);
 }
 
-template<typename T> uint64_t vector_hash(const T &vec)
-{
-  BLI_STATIC_ASSERT(T::type_length <= 4, "Longer types need to implement vector_hash themself.");
-  const typename T::uint_type &uvec = *reinterpret_cast<const typename T::uint_type *>(&vec);
-  uint64_t result;
-  result = uvec[0] * uint64_t(435109);
-  if constexpr (T::type_length > 1) {
-    result ^= uvec[1] * uint64_t(380867);
-  }
-  if constexpr (T::type_length > 2) {
-    result ^= uvec[2] * uint64_t(1059217);
-  }
-  if constexpr (T::type_length > 3) {
-    result ^= uvec[3] * uint64_t(2002613);
-  }
-  return result;
-}
-
 template<typename T, BLI_ENABLE_IF_FLT_VEC(T)> inline T reflect(const T &incident, const T &normal)
 {
   BLI_ASSERT_UNIT(normal);
diff --git a/source/blender/blenlib/intern/mesh_boolean.cc b/source/blender/blenlib/intern/mesh_boolean.cc
index 3cdc047f5fe..6e2e9787ebe 100644
--- a/source/blender/blenlib/intern/mesh_boolean.cc
+++ b/source/blender/blenlib/intern/mesh_boolean.cc
@@ -22,7 +22,7 @@
 #  include "BLI_math_geom.h"
 #  include "BLI_math_mpq.hh"
 #  include "BLI_math_vec_mpq_types.hh"
-#  include "BLI_math_vec_types.hh"
+#  include "BLI_math_vector.hh"
 #  include "BLI_mesh_intersect.hh"
 #  include "BLI_set.hh"
 #  include "BLI_span.hh"
diff --git a/source/blender/blenlib/intern/mesh_intersect.cc b/source/blender/blenlib/intern/mesh_intersect.cc
index 5295c44c991..8f2c86556aa 100644
--- a/source/blender/blenlib/intern/mesh_intersect.cc
+++ b/source/blender/blenlib/intern/mesh_intersect.cc
@@ -23,6 +23,7 @@
 #  include "BLI_math_mpq.hh"
 #  include "BLI_math_vec_mpq_types.hh"
 #  include "BLI_math_vec_types.hh"
+#  include "BLI_math_vector.h"
 #  include "BLI_polyfill_2d.h"
 #  include "BLI_set.hh"
 #  include "BLI_span.hh"
diff --git a/source/blender/blenlib/intern/noise.cc b/source/blender/blenlib/intern/noise.cc
index 24af186c1d5..a514c9e5183 100644
--- a/source/blender/blenlib/intern/noise.cc
+++ b/source/blender/blenlib/intern/noise.cc
@@ -7,7 +7,7 @@
 #include <cstdint>
 
 #include "BLI_math_base_safe.h"
-#include "BLI_math_vec_types.hh"
+#include "BLI_math_vector.hh"
 #include "BLI_noise.hh"
 #include "BLI_utildefines.h"
 
diff --git a/source/blender/editors/space_node/node_intern.hh b/source/blender/editors/space_node/node_intern.hh
index 8f0ff1ccd23..592db3f7877 100644
--- a/source/blender/editors/space_node/node_intern.hh
+++ b/source/blender/editors/space_node/node_intern.hh
@@ -7,7 +7,8 @@
 
 #pragma once
 
-#include "BLI_math_vec_types.hh"
+#include "B

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list