[Bf-blender-cvs] [6c5a5cb83d9] soc-2021-adaptive-cloth: float2x3 and float3x2: transpose and multiplication with intern file

ishbosamiya noreply at git.blender.org
Mon Sep 6 11:47:41 CEST 2021


Commit: 6c5a5cb83d97a81902451d5c6bf2ac5680a6c54a
Author: ishbosamiya
Date:   Sun Sep 5 11:01:44 2021 +0530
Branches: soc-2021-adaptive-cloth
https://developer.blender.org/rB6c5a5cb83d97a81902451d5c6bf2ac5680a6c54a

float2x3 and float3x2: transpose and multiplication with intern file

Transpose and multiplication requires access to the other structure as
well, this cannot be done through header files only, at least not
easily. So separate implementation files for each with the respective
functions that are required.

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

M	source/blender/blenlib/BLI_float2x3.hh
M	source/blender/blenlib/BLI_float3x2.hh
M	source/blender/blenlib/CMakeLists.txt
A	source/blender/blenlib/intern/BLI_float2x3.cc
A	source/blender/blenlib/intern/BLI_float3x2.cc

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

diff --git a/source/blender/blenlib/BLI_float2x3.hh b/source/blender/blenlib/BLI_float2x3.hh
index ce0523d2d9c..1236b25f174 100644
--- a/source/blender/blenlib/BLI_float2x3.hh
+++ b/source/blender/blenlib/BLI_float2x3.hh
@@ -20,14 +20,15 @@
 #include "BLI_float2.hh"
 #include "BLI_float2x2.hh"
 #include "BLI_float3.hh"
-#include "BLI_float3x2.hh"
 
 namespace blender {
 
+struct float3x2;
+
 /**
  * A 2x3 column major matrix.
  *
- * float3x3::values[i] is the ith column of the matrix.
+ * float2x3::values[i] is the ith column of the matrix.
  *
  * |m00 m10 m20|
  * |m01 m11 m21|
@@ -78,22 +79,7 @@ struct float2x3 {
     return result;
   }
 
-  friend float2x2 operator*(const float2x3 &a, const float3x2 &b)
-  {
-    float2x2 result;
-
-    result.ptr()[0][0] = a.ptr()[0][0] * b.ptr()[0][0] + a.ptr()[1][0] * b.ptr()[0][1] +
-                         a.ptr()[2][0] * b.ptr()[0][2];
-    result.ptr()[0][1] = a.ptr()[0][1] * b.ptr()[0][0] + a.ptr()[1][1] * b.ptr()[0][1] +
-                         a.ptr()[2][1] * b.ptr()[0][2];
-
-    result.ptr()[1][0] = a.ptr()[0][0] * b.ptr()[1][0] + a.ptr()[1][0] * b.ptr()[1][1] +
-                         a.ptr()[2][0] * b.ptr()[1][2];
-    result.ptr()[1][1] = a.ptr()[0][1] * b.ptr()[1][0] + a.ptr()[1][1] * b.ptr()[1][1] +
-                         a.ptr()[2][1] * b.ptr()[1][2];
-
-    return result;
-  }
+  friend float2x2 operator*(const float2x3 &a, const float3x2 &b);
 
   friend float2x3 operator*(const float2x2 &a, const float2x3 &b)
   {
@@ -164,6 +150,8 @@ struct float2x3 {
     return res;
   }
 
+  float3x2 transpose() const;
+
   uint64_t hash() const
   {
     uint64_t h = 435109;
diff --git a/source/blender/blenlib/BLI_float3x2.hh b/source/blender/blenlib/BLI_float3x2.hh
index 1b4731f701c..12b6f18e8b9 100644
--- a/source/blender/blenlib/BLI_float3x2.hh
+++ b/source/blender/blenlib/BLI_float3x2.hh
@@ -23,6 +23,8 @@
 
 namespace blender {
 
+struct float2x3;
+
 /**
  * A 3x2 column major matrix.
  *
@@ -160,6 +162,8 @@ struct float3x2 {
     return res;
   }
 
+  float2x3 transpose() const;
+
   uint64_t hash() const
   {
     uint64_t h = 435109;
diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt
index 5cf53c00128..e79bdb3096b 100644
--- a/source/blender/blenlib/CMakeLists.txt
+++ b/source/blender/blenlib/CMakeLists.txt
@@ -44,6 +44,8 @@ set(SRC
   intern/BLI_dial_2d.c
   intern/BLI_dynstr.c
   intern/BLI_filelist.c
+  intern/BLI_float2x3.cc
+  intern/BLI_float3x2.cc
   intern/BLI_ghash.c
   intern/BLI_ghash_utils.c
   intern/BLI_heap.c
diff --git a/source/blender/blenlib/intern/BLI_float2x3.cc b/source/blender/blenlib/intern/BLI_float2x3.cc
new file mode 100644
index 00000000000..bf3ae086f43
--- /dev/null
+++ b/source/blender/blenlib/intern/BLI_float2x3.cc
@@ -0,0 +1,38 @@
+#include "BLI_float2x3.hh"
+#include "BLI_float3x2.hh"
+
+namespace blender {
+
+float2x2 operator*(const float2x3 &a, const float3x2 &b)
+{
+  float2x2 result;
+
+  result.ptr()[0][0] = a.ptr()[0][0] * b.ptr()[0][0] + a.ptr()[1][0] * b.ptr()[0][1] +
+                       a.ptr()[2][0] * b.ptr()[0][2];
+  result.ptr()[0][1] = a.ptr()[0][1] * b.ptr()[0][0] + a.ptr()[1][1] * b.ptr()[0][1] +
+                       a.ptr()[2][1] * b.ptr()[0][2];
+
+  result.ptr()[1][0] = a.ptr()[0][0] * b.ptr()[1][0] + a.ptr()[1][0] * b.ptr()[1][1] +
+                       a.ptr()[2][0] * b.ptr()[1][2];
+  result.ptr()[1][1] = a.ptr()[0][1] * b.ptr()[1][0] + a.ptr()[1][1] * b.ptr()[1][1] +
+                       a.ptr()[2][1] * b.ptr()[1][2];
+
+  return result;
+}
+
+float3x2 float2x3::transpose() const
+{
+  float3x2 result;
+
+  result.ptr()[0][0] = this->ptr()[0][0];
+  result.ptr()[0][1] = this->ptr()[1][0];
+  result.ptr()[0][2] = this->ptr()[2][0];
+
+  result.ptr()[1][0] = this->ptr()[0][1];
+  result.ptr()[1][1] = this->ptr()[1][1];
+  result.ptr()[1][2] = this->ptr()[2][1];
+
+  return result;
+}
+
+}  // namespace blender
diff --git a/source/blender/blenlib/intern/BLI_float3x2.cc b/source/blender/blenlib/intern/BLI_float3x2.cc
new file mode 100644
index 00000000000..38b6c29687d
--- /dev/null
+++ b/source/blender/blenlib/intern/BLI_float3x2.cc
@@ -0,0 +1,22 @@
+#include "BLI_float3x2.hh"
+#include "BLI_float2x3.hh"
+
+namespace blender {
+
+float2x3 float3x2::transpose() const
+{
+  float2x3 res;
+
+  res.ptr()[0][0] = this->ptr()[0][0];
+  res.ptr()[0][1] = this->ptr()[1][0];
+
+  res.ptr()[1][0] = this->ptr()[0][1];
+  res.ptr()[1][1] = this->ptr()[1][1];
+
+  res.ptr()[2][0] = this->ptr()[0][2];
+  res.ptr()[2][1] = this->ptr()[1][2];
+
+  return res;
+}
+
+}  // namespace blender



More information about the Bf-blender-cvs mailing list