Ocean
Loading...
Searching...
No Matches
TestSquareMatrix4.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#ifndef META_OCEAN_TEST_TESTMATH_TEST_SQUARE_MATRIX_4_H
9#define META_OCEAN_TEST_TESTMATH_TEST_SQUARE_MATRIX_4_H
10
12
13#include "ocean/base/Worker.h"
14
16#include "ocean/math/Vector4.h"
17
18namespace Ocean
19{
20
21namespace Test
22{
23
24namespace TestMath
25{
26
27/**
28 * This class implements a test for 4x4 square matrices.
29 * @ingroup testmath
30 */
31class OCEAN_TEST_MATH_EXPORT TestSquareMatrix4
32{
33 public:
34
35 /**
36 * Tests all square matrix 4x4 functions.
37 * @param testDuration Number of seconds for each test, with range (0, infinity)
38 * @param worker The worker object allowing to distribute computations
39 * @return True, if succeeded
40 */
41 static bool test(const double testDuration, Worker& worker);
42
43 /**
44 * Tests the messenger function.
45 * @return True, if succeeded
46 */
47 static bool testWriteToMessenger();
48
49 /**
50 * Tests the element-based constructor.
51 * @param testDuration The number of seconds for each test, with range (0, infinity)
52 * @return True, if succeeded
53 */
54 static bool testElementConstructor(const double testDuration);
55
56 /**
57 * Tests the vector multiplication operator.
58 * @param testDuration The number of seconds for each test, with range (0, infinity)
59 * @param worker The worker object allowing to distribute computations
60 * @return True, if succeeded
61 * @tparam T The data type of a scalar value
62 */
63 template <typename T>
64 static bool testVectorMultiplication(const double testDuration, Worker& worker);
65
66 /**
67 * Tests the matrix multiplication operator.
68 * @param testDuration The number of seconds for each test, with range (0, infinity)
69 * @return True, if succeeded
70 * @tparam T The data type of a scalar value
71 */
72 template <typename T>
73 static bool testMatrixMultiplication(const double testDuration);
74
75 /**
76 * Tests the invert functions.
77 * @param testDuration Number of seconds for each test, with range (0, infinity)
78 * @return True, if succeeded
79 */
80 static bool testInvert(const double testDuration);
81
82 /**
83 * Tests the matrix conversion functions.
84 * @param testDuration Number of seconds for each test, with range (0, infinity)
85 * @return True, if succeeded
86 */
87 static bool testMatrixConversion(const double testDuration);
88
89 /**
90 * Tests the projection matrix function with field of view.
91 * @param testDuration Number of seconds for each test, with range (0, infinity)
92 * @return True, if succeeded
93 * @tparam T The data type of a scalar value
94 */
95 template <typename T>
96 static bool testProjectionMatrixFieldOfView(const double testDuration);
97
98 /**
99 * Tests the projection matrix function with camera matrix.
100 * @param testDuration Number of seconds for each test, with range (0, infinity)
101 * @return True, if succeeded
102 * @tparam T The data type of a scalar value
103 */
104 template <typename T>
105 static bool testProjectionMatrixCameraMatrix(const double testDuration);
106
107 /**
108 * Tests the transpose functions.
109 * @param testDuration Number of seconds for each test, with range (0, infinity)
110 * @return True, if succeeded
111 * @tparam T The data type of a scalar value
112 */
113 template <typename T>
114 static bool testTranspose(const double testDuration);
115
116 /**
117 * Tests the determinant function.
118 * @param testDuration Number of seconds for each test, with range (0, infinity)
119 * @return True, if succeeded
120 * @tparam T The data type of a scalar value
121 */
122 template <typename T>
123 static bool testDeterminant(const double testDuration);
124
125 /**
126 * Tests the trace function.
127 * @param testDuration Number of seconds for each test, with range (0, infinity)
128 * @return True, if succeeded
129 * @tparam T The data type of a scalar value
130 */
131 template <typename T>
132 static bool testTrace(const double testDuration);
133
134 /**
135 * Tests the matrix addition operators.
136 * @param testDuration Number of seconds for each test, with range (0, infinity)
137 * @return True, if succeeded
138 * @tparam T The data type of a scalar value
139 */
140 template <typename T>
141 static bool testMatrixAddition(const double testDuration);
142
143 /**
144 * Tests the matrix subtraction operators.
145 * @param testDuration Number of seconds for each test, with range (0, infinity)
146 * @return True, if succeeded
147 * @tparam T The data type of a scalar value
148 */
149 template <typename T>
150 static bool testMatrixSubtraction(const double testDuration);
151
152 /**
153 * Tests the accessor operators.
154 * @param testDuration Number of seconds for each test, with range (0, infinity)
155 * @return True, if succeeded
156 */
157 static bool testAccessor(const double testDuration);
158
159 /**
160 * Tests the eigenSystem function.
161 * @param testDuration Number of seconds for each test, with range (0, infinity)
162 * @return True, if succeeded
163 * @tparam T The data type of a scalar value
164 */
165 template <typename T>
166 static bool testEigenSystem(const double testDuration);
167
168 private:
169
170 /**
171 * Standard implementation of a multiplication between a 4x4 matrix and a 4x1 vector.
172 * @param matrix The matrix to be used for multiplication
173 * @param vector The vector to be used for multiplication
174 * @return The multiplication result
175 * @tparam T The data type of the elements
176 */
177 template <typename T>
178 static OCEAN_FORCE_INLINE VectorT4<T> standardVectorMultiplication(const SquareMatrixT4<T>& matrix, const VectorT4<T>& vector);
179
180 /**
181 * Standard implementation of a multiplication between a 4x4 matrix and a 4x4 matrix.
182 * @param matrix The matrix to be used for multiplication
183 * @param rightMatrix The right matrix to be used for multiplication
184 * @return The multiplication result
185 * @tparam T The data type of the elements
186 */
187 template <typename T>
188 static OCEAN_FORCE_INLINE SquareMatrixT4<T> standardMatrixMultiplication(const SquareMatrixT4<T>& matrix, const SquareMatrixT4<T>& rightMatrix);
189};
190
191template <typename T>
193{
194 return VectorT4<T>(matrix[0] * vector[0] + matrix[4] * vector[1] + matrix[8] * vector[2] + matrix[12] * vector[3],
195 matrix[1] * vector[0] + matrix[5] * vector[1] + matrix[9] * vector[2] + matrix[13] * vector[3],
196 matrix[2] * vector[0] + matrix[6] * vector[1] + matrix[10] * vector[2] + matrix[14] * vector[3],
197 matrix[3] * vector[0] + matrix[7] * vector[1] + matrix[11] * vector[2] + matrix[15] * vector[3]);
198}
199
200template <typename T>
202{
203 SquareMatrixT4<T> result;
204
205 result[ 0] = matrix[0] * rightMatrix[ 0] + matrix[4] * rightMatrix[ 1] + matrix[ 8] * rightMatrix[ 2] + matrix[12] * rightMatrix[3];
206 result[ 1] = matrix[1] * rightMatrix[ 0] + matrix[5] * rightMatrix[ 1] + matrix[ 9] * rightMatrix[ 2] + matrix[13] * rightMatrix[3];
207 result[ 2] = matrix[2] * rightMatrix[ 0] + matrix[6] * rightMatrix[ 1] + matrix[10] * rightMatrix[ 2] + matrix[14] * rightMatrix[3];
208 result[ 3] = matrix[3] * rightMatrix[ 0] + matrix[7] * rightMatrix[ 1] + matrix[11] * rightMatrix[ 2] + matrix[15] * rightMatrix[3];
209
210 result[ 4] = matrix[0] * rightMatrix[ 4] + matrix[4] * rightMatrix[ 5] + matrix[ 8] * rightMatrix[ 6] + matrix[12] * rightMatrix[7];
211 result[ 5] = matrix[1] * rightMatrix[ 4] + matrix[5] * rightMatrix[ 5] + matrix[ 9] * rightMatrix[ 6] + matrix[13] * rightMatrix[7];
212 result[ 6] = matrix[2] * rightMatrix[ 4] + matrix[6] * rightMatrix[ 5] + matrix[10] * rightMatrix[ 6] + matrix[14] * rightMatrix[7];
213 result[ 7] = matrix[3] * rightMatrix[ 4] + matrix[7] * rightMatrix[ 5] + matrix[11] * rightMatrix[ 6] + matrix[15] * rightMatrix[7];
214
215 result[ 8] = matrix[0] * rightMatrix[ 8] + matrix[4] * rightMatrix[ 9] + matrix[ 8] * rightMatrix[10] + matrix[12] * rightMatrix[11];
216 result[ 9] = matrix[1] * rightMatrix[ 8] + matrix[5] * rightMatrix[ 9] + matrix[ 9] * rightMatrix[10] + matrix[13] * rightMatrix[11];
217 result[10] = matrix[2] * rightMatrix[ 8] + matrix[6] * rightMatrix[ 9] + matrix[10] * rightMatrix[10] + matrix[14] * rightMatrix[11];
218 result[11] = matrix[3] * rightMatrix[ 8] + matrix[7] * rightMatrix[ 9] + matrix[11] * rightMatrix[10] + matrix[15] * rightMatrix[11];
219
220 result[12] = matrix[0] * rightMatrix[12] + matrix[4] * rightMatrix[13] + matrix[ 8] * rightMatrix[14] + matrix[12] * rightMatrix[15];
221 result[13] = matrix[1] * rightMatrix[12] + matrix[5] * rightMatrix[13] + matrix[ 9] * rightMatrix[14] + matrix[13] * rightMatrix[15];
222 result[14] = matrix[2] * rightMatrix[12] + matrix[6] * rightMatrix[13] + matrix[10] * rightMatrix[14] + matrix[14] * rightMatrix[15];
223 result[15] = matrix[3] * rightMatrix[12] + matrix[7] * rightMatrix[13] + matrix[11] * rightMatrix[14] + matrix[15] * rightMatrix[15];
224
225 return result;
226}
227
228}
229
230}
231
232}
233
234#endif // META_OCEAN_TEST_TESTMATH_TEST_SQUARE_MATRIX_4_H
This class implements a 4x4 square matrix.
Definition SquareMatrix4.h:85
This class implements a test for 4x4 square matrices.
Definition TestSquareMatrix4.h:32
static OCEAN_FORCE_INLINE SquareMatrixT4< T > standardMatrixMultiplication(const SquareMatrixT4< T > &matrix, const SquareMatrixT4< T > &rightMatrix)
Standard implementation of a multiplication between a 4x4 matrix and a 4x4 matrix.
Definition TestSquareMatrix4.h:201
static bool testMatrixSubtraction(const double testDuration)
Tests the matrix subtraction operators.
static bool testProjectionMatrixCameraMatrix(const double testDuration)
Tests the projection matrix function with camera matrix.
static bool testEigenSystem(const double testDuration)
Tests the eigenSystem function.
static bool testProjectionMatrixFieldOfView(const double testDuration)
Tests the projection matrix function with field of view.
static bool test(const double testDuration, Worker &worker)
Tests all square matrix 4x4 functions.
static bool testTranspose(const double testDuration)
Tests the transpose functions.
static bool testElementConstructor(const double testDuration)
Tests the element-based constructor.
static bool testDeterminant(const double testDuration)
Tests the determinant function.
static bool testVectorMultiplication(const double testDuration, Worker &worker)
Tests the vector multiplication operator.
static bool testWriteToMessenger()
Tests the messenger function.
static bool testMatrixAddition(const double testDuration)
Tests the matrix addition operators.
static bool testMatrixConversion(const double testDuration)
Tests the matrix conversion functions.
static bool testAccessor(const double testDuration)
Tests the accessor operators.
static OCEAN_FORCE_INLINE VectorT4< T > standardVectorMultiplication(const SquareMatrixT4< T > &matrix, const VectorT4< T > &vector)
Standard implementation of a multiplication between a 4x4 matrix and a 4x1 vector.
Definition TestSquareMatrix4.h:192
static bool testMatrixMultiplication(const double testDuration)
Tests the matrix multiplication operator.
static bool testTrace(const double testDuration)
Tests the trace function.
static bool testInvert(const double testDuration)
Tests the invert functions.
This class implements a vector with four elements.
Definition Vector4.h:97
This class implements a worker able to distribute function calls over different threads.
Definition Worker.h:33
The namespace covering the entire Ocean framework.
Definition Accessor.h:15