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