From cf6d0713610ca3d0f23fbf7ddc8d77eeaa6df717 Mon Sep 17 00:00:00 2001
From: Rye Mutt <rye@alchemyviewer.org>
Date: Sat, 4 Jan 2020 12:17:13 -0500
Subject: [PATCH] Move a few matrix math operators to headers

---
 indra/llmath/m3math.cpp | 143 +++++++---------------------------------
 indra/llmath/m3math.h   |  95 ++++++++++++++++++++++++++
 2 files changed, 117 insertions(+), 121 deletions(-)

diff --git a/indra/llmath/m3math.cpp b/indra/llmath/m3math.cpp
index cbb66d09d0..1ae8895a6e 100644
--- a/indra/llmath/m3math.cpp
+++ b/indra/llmath/m3math.cpp
@@ -470,137 +470,38 @@ const LLMatrix3&	LLMatrix3::orthogonalize()
 	return (*this);
 }
 
-
-// LLMatrix3 Operators
-
-LLMatrix3 operator*(const LLMatrix3 &a, const LLMatrix3 &b)
-{
-	U32		i, j;
-	LLMatrix3	mat;
-	for (i = 0; i < NUM_VALUES_IN_MAT3; i++)
-	{
-		for (j = 0; j < NUM_VALUES_IN_MAT3; j++)
-		{
-			mat.mMatrix[j][i] = a.mMatrix[j][0] * b.mMatrix[0][i] + 
-							    a.mMatrix[j][1] * b.mMatrix[1][i] + 
-							    a.mMatrix[j][2] * b.mMatrix[2][i];
-		}
-	}
-	return mat;
-}
-
-/* Not implemented to help enforce code consistency with the syntax of 
-   row-major notation.  This is a Good Thing.
-LLVector3 operator*(const LLMatrix3 &a, const LLVector3 &b)
-{
-	LLVector3	vec;
-	// matrix operates "from the left" on column vector
-	vec.mV[VX] = a.mMatrix[VX][VX] * b.mV[VX] + 
-				 a.mMatrix[VX][VY] * b.mV[VY] + 
-				 a.mMatrix[VX][VZ] * b.mV[VZ];
-	
-	vec.mV[VY] = a.mMatrix[VY][VX] * b.mV[VX] + 
-				 a.mMatrix[VY][VY] * b.mV[VY] + 
-				 a.mMatrix[VY][VZ] * b.mV[VZ];
-	
-	vec.mV[VZ] = a.mMatrix[VZ][VX] * b.mV[VX] + 
-				 a.mMatrix[VZ][VY] * b.mV[VY] + 
-				 a.mMatrix[VZ][VZ] * b.mV[VZ];
-	return vec;
-}
-*/
-
-
-LLVector3 operator*(const LLVector3 &a, const LLMatrix3 &b)
+LLVector3 operator*(const LLVector3& a, const LLMatrix3& b)
 {
 	// matrix operates "from the right" on row vector
 	return LLVector3(
-				a.mV[VX] * b.mMatrix[VX][VX] + 
-				a.mV[VY] * b.mMatrix[VY][VX] + 
-				a.mV[VZ] * b.mMatrix[VZ][VX],
-	
-				a.mV[VX] * b.mMatrix[VX][VY] + 
-				a.mV[VY] * b.mMatrix[VY][VY] + 
-				a.mV[VZ] * b.mMatrix[VZ][VY],
-	
-				a.mV[VX] * b.mMatrix[VX][VZ] + 
-				a.mV[VY] * b.mMatrix[VY][VZ] + 
-				a.mV[VZ] * b.mMatrix[VZ][VZ] );
-}
-
-LLVector3d operator*(const LLVector3d &a, const LLMatrix3 &b)
-{
-	// matrix operates "from the right" on row vector
-	return LLVector3d(
-				a.mdV[VX] * static_cast<F64>(b.mMatrix[VX][VX]) +
-				a.mdV[VY] * static_cast<F64>(b.mMatrix[VY][VX]) +
-				a.mdV[VZ] * static_cast<F64>(b.mMatrix[VZ][VX]),
-	
-				a.mdV[VX] * static_cast<F64>(b.mMatrix[VX][VY]) +
-				a.mdV[VY] * static_cast<F64>(b.mMatrix[VY][VY]) +
-				a.mdV[VZ] * static_cast<F64>(b.mMatrix[VZ][VY]),
-	
-				a.mdV[VX] * static_cast<F64>(b.mMatrix[VX][VZ]) +
-				a.mdV[VY] * static_cast<F64>(b.mMatrix[VY][VZ]) +
-				a.mdV[VZ] * static_cast<F64>(b.mMatrix[VZ][VZ]) );
-}
+		a.mV[VX] * b.mMatrix[VX][VX] +
+		a.mV[VY] * b.mMatrix[VY][VX] +
+		a.mV[VZ] * b.mMatrix[VZ][VX],
 
-bool operator==(const LLMatrix3 &a, const LLMatrix3 &b)
-{
-	U32		i, j;
-	for (i = 0; i < NUM_VALUES_IN_MAT3; i++)
-	{
-		for (j = 0; j < NUM_VALUES_IN_MAT3; j++)
-		{
-			if (a.mMatrix[j][i] != b.mMatrix[j][i])
-				return FALSE;
-		}
-	}
-	return TRUE;
-}
+		a.mV[VX] * b.mMatrix[VX][VY] +
+		a.mV[VY] * b.mMatrix[VY][VY] +
+		a.mV[VZ] * b.mMatrix[VZ][VY],
 
-bool operator!=(const LLMatrix3 &a, const LLMatrix3 &b)
-{
-	U32		i, j;
-	for (i = 0; i < NUM_VALUES_IN_MAT3; i++)
-	{
-		for (j = 0; j < NUM_VALUES_IN_MAT3; j++)
-		{
-			if (a.mMatrix[j][i] != b.mMatrix[j][i])
-				return TRUE;
-		}
-	}
-	return FALSE;
+		a.mV[VX] * b.mMatrix[VX][VZ] +
+		a.mV[VY] * b.mMatrix[VY][VZ] +
+		a.mV[VZ] * b.mMatrix[VZ][VZ]);
 }
 
-const LLMatrix3& operator*=(LLMatrix3 &a, const LLMatrix3 &b)
+LLVector3d operator*(const LLVector3d& a, const LLMatrix3& b)
 {
-	U32		i, j;
-	LLMatrix3	mat;
-	for (i = 0; i < NUM_VALUES_IN_MAT3; i++)
-	{
-		for (j = 0; j < NUM_VALUES_IN_MAT3; j++)
-		{
-			mat.mMatrix[j][i] = a.mMatrix[j][0] * b.mMatrix[0][i] + 
-							    a.mMatrix[j][1] * b.mMatrix[1][i] + 
-							    a.mMatrix[j][2] * b.mMatrix[2][i];
-		}
-	}
-	a = mat;
-	return a;
-}
+	// matrix operates "from the right" on row vector
+	return LLVector3d(
+		a.mdV[VX] * static_cast<F64>(b.mMatrix[VX][VX]) +
+		a.mdV[VY] * static_cast<F64>(b.mMatrix[VY][VX]) +
+		a.mdV[VZ] * static_cast<F64>(b.mMatrix[VZ][VX]),
 
-const LLMatrix3& operator*=(LLMatrix3 &a, F32 scalar )
-{
-	for (auto& i : a.mMatrix)
-    {
-		for (float& j : i)
-        {
-            j *= scalar;
-		}
-	}
+		a.mdV[VX] * static_cast<F64>(b.mMatrix[VX][VY]) +
+		a.mdV[VY] * static_cast<F64>(b.mMatrix[VY][VY]) +
+		a.mdV[VZ] * static_cast<F64>(b.mMatrix[VZ][VY]),
 
-	return a;
+		a.mdV[VX] * static_cast<F64>(b.mMatrix[VX][VZ]) +
+		a.mdV[VY] * static_cast<F64>(b.mMatrix[VY][VZ]) +
+		a.mdV[VZ] * static_cast<F64>(b.mMatrix[VZ][VZ]));
 }
 
 std::ostream& operator<<(std::ostream& s, const LLMatrix3 &a) 
diff --git a/indra/llmath/m3math.h b/indra/llmath/m3math.h
index 74d7fd7748..87e5d7e50b 100644
--- a/indra/llmath/m3math.h
+++ b/indra/llmath/m3math.h
@@ -176,6 +176,101 @@ inline LLMatrix3::LLMatrix3(const F32 *mat)
 	mMatrix[2][2] = mat[8];
 }
 
+inline LLMatrix3 operator*(const LLMatrix3& a, const LLMatrix3& b)
+{
+	U32		i, j;
+	LLMatrix3	mat;
+	for (i = 0; i < NUM_VALUES_IN_MAT3; i++)
+	{
+		for (j = 0; j < NUM_VALUES_IN_MAT3; j++)
+		{
+			mat.mMatrix[j][i] = a.mMatrix[j][0] * b.mMatrix[0][i] +
+				a.mMatrix[j][1] * b.mMatrix[1][i] +
+				a.mMatrix[j][2] * b.mMatrix[2][i];
+		}
+	}
+	return mat;
+}
+
+/* Not implemented to help enforce code consistency with the syntax of
+   row-major notation.  This is a Good Thing.
+LLVector3 operator*(const LLMatrix3 &a, const LLVector3 &b)
+{
+	LLVector3	vec;
+	// matrix operates "from the left" on column vector
+	vec.mV[VX] = a.mMatrix[VX][VX] * b.mV[VX] +
+				 a.mMatrix[VX][VY] * b.mV[VY] +
+				 a.mMatrix[VX][VZ] * b.mV[VZ];
+
+	vec.mV[VY] = a.mMatrix[VY][VX] * b.mV[VX] +
+				 a.mMatrix[VY][VY] * b.mV[VY] +
+				 a.mMatrix[VY][VZ] * b.mV[VZ];
+
+	vec.mV[VZ] = a.mMatrix[VZ][VX] * b.mV[VX] +
+				 a.mMatrix[VZ][VY] * b.mV[VY] +
+				 a.mMatrix[VZ][VZ] * b.mV[VZ];
+	return vec;
+}
+*/
+
+
+inline bool operator==(const LLMatrix3& a, const LLMatrix3& b)
+{
+	U32		i, j;
+	for (i = 0; i < NUM_VALUES_IN_MAT3; i++)
+	{
+		for (j = 0; j < NUM_VALUES_IN_MAT3; j++)
+		{
+			if (a.mMatrix[j][i] != b.mMatrix[j][i])
+				return FALSE;
+		}
+	}
+	return TRUE;
+}
+
+inline bool operator!=(const LLMatrix3& a, const LLMatrix3& b)
+{
+	U32		i, j;
+	for (i = 0; i < NUM_VALUES_IN_MAT3; i++)
+	{
+		for (j = 0; j < NUM_VALUES_IN_MAT3; j++)
+		{
+			if (a.mMatrix[j][i] != b.mMatrix[j][i])
+				return TRUE;
+		}
+	}
+	return FALSE;
+}
+
+inline const LLMatrix3& operator*=(LLMatrix3& a, const LLMatrix3& b)
+{
+	U32		i, j;
+	LLMatrix3	mat;
+	for (i = 0; i < NUM_VALUES_IN_MAT3; i++)
+	{
+		for (j = 0; j < NUM_VALUES_IN_MAT3; j++)
+		{
+			mat.mMatrix[j][i] = a.mMatrix[j][0] * b.mMatrix[0][i] +
+				a.mMatrix[j][1] * b.mMatrix[1][i] +
+				a.mMatrix[j][2] * b.mMatrix[2][i];
+		}
+	}
+	a = mat;
+	return a;
+}
+
+inline const LLMatrix3& operator*=(LLMatrix3& a, F32 scalar)
+{
+	for (auto& i : a.mMatrix)
+	{
+		for (float& j : i)
+		{
+			j *= scalar;
+		}
+	}
+
+	return a;
+}
 
 #endif
 
-- 
GitLab