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 private:
108
109 /**
110 * Standard implementation of a multiplication between a 4x4 matrix and a 4x1 vector.
111 * @param matrix The matrix to be used for multiplication
112 * @param vector The vector to be used for multiplication
113 * @return The multiplication result
114 * @tparam T The data type of the elements
115 */
116 template <typename T>
117 static OCEAN_FORCE_INLINE VectorT4<T> standardVectorMultiplication(const SquareMatrixT4<T>& matrix, const VectorT4<T>& vector);
118
119 /**
120 * Standard implementation of a multiplication between a 4x4 matrix and a 4x4 matrix.
121 * @param matrix The matrix to be used for multiplication
122 * @param rightMatrix The right matrix to be used for multiplication
123 * @return The multiplication result
124 * @tparam T The data type of the elements
125 */
126 template <typename T>
127 static OCEAN_FORCE_INLINE SquareMatrixT4<T> standardMatrixMultiplication(const SquareMatrixT4<T>& matrix, const SquareMatrixT4<T>& rightMatrix);
128};
129
130template <typename T>
132{
133 return VectorT4<T>(matrix[0] * vector[0] + matrix[4] * vector[1] + matrix[8] * vector[2] + matrix[12] * vector[3],
134 matrix[1] * vector[0] + matrix[5] * vector[1] + matrix[9] * vector[2] + matrix[13] * vector[3],
135 matrix[2] * vector[0] + matrix[6] * vector[1] + matrix[10] * vector[2] + matrix[14] * vector[3],
136 matrix[3] * vector[0] + matrix[7] * vector[1] + matrix[11] * vector[2] + matrix[15] * vector[3]);
137}
138
139template <typename T>
141{
142 SquareMatrixT4<T> result;
143
144 result[ 0] = matrix[0] * rightMatrix[ 0] + matrix[4] * rightMatrix[ 1] + matrix[ 8] * rightMatrix[ 2] + matrix[12] * rightMatrix[3];
145 result[ 1] = matrix[1] * rightMatrix[ 0] + matrix[5] * rightMatrix[ 1] + matrix[ 9] * rightMatrix[ 2] + matrix[13] * rightMatrix[3];
146 result[ 2] = matrix[2] * rightMatrix[ 0] + matrix[6] * rightMatrix[ 1] + matrix[10] * rightMatrix[ 2] + matrix[14] * rightMatrix[3];
147 result[ 3] = matrix[3] * rightMatrix[ 0] + matrix[7] * rightMatrix[ 1] + matrix[11] * rightMatrix[ 2] + matrix[15] * rightMatrix[3];
148
149 result[ 4] = matrix[0] * rightMatrix[ 4] + matrix[4] * rightMatrix[ 5] + matrix[ 8] * rightMatrix[ 6] + matrix[12] * rightMatrix[7];
150 result[ 5] = matrix[1] * rightMatrix[ 4] + matrix[5] * rightMatrix[ 5] + matrix[ 9] * rightMatrix[ 6] + matrix[13] * rightMatrix[7];
151 result[ 6] = matrix[2] * rightMatrix[ 4] + matrix[6] * rightMatrix[ 5] + matrix[10] * rightMatrix[ 6] + matrix[14] * rightMatrix[7];
152 result[ 7] = matrix[3] * rightMatrix[ 4] + matrix[7] * rightMatrix[ 5] + matrix[11] * rightMatrix[ 6] + matrix[15] * rightMatrix[7];
153
154 result[ 8] = matrix[0] * rightMatrix[ 8] + matrix[4] * rightMatrix[ 9] + matrix[ 8] * rightMatrix[10] + matrix[12] * rightMatrix[11];
155 result[ 9] = matrix[1] * rightMatrix[ 8] + matrix[5] * rightMatrix[ 9] + matrix[ 9] * rightMatrix[10] + matrix[13] * rightMatrix[11];
156 result[10] = matrix[2] * rightMatrix[ 8] + matrix[6] * rightMatrix[ 9] + matrix[10] * rightMatrix[10] + matrix[14] * rightMatrix[11];
157 result[11] = matrix[3] * rightMatrix[ 8] + matrix[7] * rightMatrix[ 9] + matrix[11] * rightMatrix[10] + matrix[15] * rightMatrix[11];
158
159 result[12] = matrix[0] * rightMatrix[12] + matrix[4] * rightMatrix[13] + matrix[ 8] * rightMatrix[14] + matrix[12] * rightMatrix[15];
160 result[13] = matrix[1] * rightMatrix[12] + matrix[5] * rightMatrix[13] + matrix[ 9] * rightMatrix[14] + matrix[13] * rightMatrix[15];
161 result[14] = matrix[2] * rightMatrix[12] + matrix[6] * rightMatrix[13] + matrix[10] * rightMatrix[14] + matrix[14] * rightMatrix[15];
162 result[15] = matrix[3] * rightMatrix[12] + matrix[7] * rightMatrix[13] + matrix[11] * rightMatrix[14] + matrix[15] * rightMatrix[15];
163
164 return result;
165}
166
167}
168
169}
170
171}
172
173#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:140
static bool testProjectionMatrixCameraMatrix(const double testDuration)
Tests the projection matrix function with camera matrix.
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 testElementConstructor(const double testDuration)
Tests the element-based constructor.
static bool testVectorMultiplication(const double testDuration, Worker &worker)
Tests the vector multiplication operator.
static bool testWriteToMessenger()
Tests the messenger function.
static bool testMatrixConversion(const double testDuration)
Tests the matrix conversion functions.
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:131
static bool testMatrixMultiplication(const double testDuration)
Tests the matrix multiplication operator.
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