MathLib
Loading...
Searching...
No Matches
TestVector3D.cpp
Go to the documentation of this file.
4#include <iostream>
5#include <format>
6#include <numbers>
7#include <cstdlib>
8
9
11{
12
13using namespace Math;
14
15void TestFunction(const Vector3Df &input)
16{
17 std::cout << std::format("{}\t{} {} {}", __func__, input.x, input.y, input.z) << std::endl;
18}
19
21{
22 std::cout << __func__ << std::endl;
23
24 Vector3Df default_initialized;
25
26 CHECK_IF_EQUAL( default_initialized.x, 0.0f );
27 CHECK_IF_EQUAL( default_initialized.y, 0.0f );
28 CHECK_IF_EQUAL( default_initialized.z, 0.0f );
29}
30
32{
33 std::cout << __func__ << std::endl;
34
35 Vector3Df one{ 2.2f };
36
37 CHECK_IF_EQUAL( one.x, 2.2f );
38 CHECK_IF_EQUAL( one.y, 0.0f );
39 CHECK_IF_EQUAL( one.z, 0.0f );
40
41}
42
44{
45 std::cout << __func__ << std::endl;
46
47 Vector3Df one{ 2.2f, 3.3f };
48
49 CHECK_IF_EQUAL( one.x, 2.2f );
50 CHECK_IF_EQUAL( one.y, 3.3f );
51 CHECK_IF_EQUAL( one.z, 0.0f );
52}
53
55{
56 std::cout << __func__ << std::endl;
57
58 Vector3Df one{ 2.2f, 3.3f, 4.4f };
59
60 CHECK_IF_EQUAL( one.x, 2.2f );
61 CHECK_IF_EQUAL( one.y, 3.3f );
62 CHECK_IF_EQUAL( one.z, 4.4f );
63}
64
66{
67 std::cout << __func__ << std::endl;
68
69 TestFunction( { } );
70 TestFunction( { 1.0f } );
71 TestFunction( { 66.0f, 33.3f } );
72 TestFunction( { 66.0f, 33.3f, 99.9f } );
73
74 Vector3Df t{ 1.1f, 2.2f, 3.3f };
75
76 TestFunction( t.zyx() );
77}
78
80{
81 Vector3Df one{ 1.0f, 2.0f, 3.0f };
82 Vector3Df two{ 1.0f, 2.0f, 3.0f };
83 Vector3Df three{ 9.16f, 32.7f, 128.0f };
84
85 CHECK_IF_EQUAL( one, two );
86 CHECK_IF_NOT_EQUAL( one, three );
87}
88
90{
91 std::cout << __func__ << std::endl;
92
93 Vector3Df one{ 1.0f, 2.0f };
94 Vector3Df two{ 2.1f, 2.3f, 12.0f };
95
96 CHECK_IF_NOT_EQUAL( one.x, two.x );
97 CHECK_IF_NOT_EQUAL( one.y, two.y );
98 CHECK_IF_NOT_EQUAL( one.z, two.z );
99
100 one.xyz() = two;
101
102 CHECK_IF_EQUAL( one.x, two.x );
103 CHECK_IF_EQUAL( one.y, two.y );
104 CHECK_IF_EQUAL( one.z, two.z );
105
106 one.zyx() = two;
107
108 CHECK_IF_EQUAL( one.x, two.z );
109 CHECK_IF_EQUAL( one.y, two.y );
110 CHECK_IF_EQUAL( one.z, two.x );
111
112 two.zyx() = { 5.5f, 6.6f, 7.7f };
113
114 CHECK_IF_EQUAL( two.x, 7.7f );
115 CHECK_IF_EQUAL( two.y, 6.6f );
116 CHECK_IF_EQUAL( two.z, 5.5f );
117}
118
120{
121 std::cout << __func__ << std::endl;
122
123 Vector3Df one{ 1.0f, 2.0f, 3.0f };
124 Vector3Df two{ 2.1f, 2.3f, 2.4f };
125
126 CHECK_IF_NOT_EQUAL( one.x, two.x );
127 CHECK_IF_NOT_EQUAL( one.y, two.y );
128 CHECK_IF_NOT_EQUAL( one.z, two.z );
129
130 one.xyz() = two.xyz();
131
132 CHECK_IF_EQUAL( one.x, two.x );
133 CHECK_IF_EQUAL( one.y, two.y );
134 CHECK_IF_EQUAL( one.z, two.z );
135}
136
138{
139 std::cout << __func__ << std::endl;
140
141 Vector3Df one{ 1.0f, 2.0f, 3.0f };
142 Vector3Df two{ 2.1f, 2.3f, 2.5f };
143
144 CHECK_IF_NOT_EQUAL( one.x, two.y );
145 CHECK_IF_NOT_EQUAL( one.y, two.y );
146 CHECK_IF_NOT_EQUAL( one.z, two.z );
147
148 one = two.zyx();
149
150 CHECK_IF_EQUAL( one.x, two.z );
151 CHECK_IF_EQUAL( one.y, two.y );
152 CHECK_IF_EQUAL( one.z, two.x );
153}
154
156{
157 std::cout << __func__ << std::endl;
158
159 Vector3Df one{ 1.0f, 2.0f, 3.0f };
160 Vector3Df two{ 2.1f, 2.3f, 2.5f };
161
162 CHECK_IF_NOT_EQUAL( one.x, two.x );
163 CHECK_IF_NOT_EQUAL( one.y, two.y );
164 CHECK_IF_NOT_EQUAL( one.z, two.z );
165
166 one = two;
167
168 CHECK_IF_EQUAL( one.x, two.x );
169 CHECK_IF_EQUAL( one.y, two.y );
170 CHECK_IF_EQUAL( one.z, two.z );
171}
172
173void Dot()
174{
175 std::cout << __func__ << std::endl;
176
177 float sqrt2_over_2 = std::numbers::sqrt2_v<float> / 2.0f;
178 // At first, let's use unit vectors...
179
180 // Perpendicular vectors are 0
181 CHECK_IF_ZERO( dot(Vector3Df::unit_x(), Vector3Df::unit_y()) );
182 CHECK_IF_ZERO( dot(Vector3Df::unit_x(), Vector3Df::unit_z()) );
183
184 // Parallel vectors are 1
185 CHECK_IF_EQUAL( dot(Vector3Df::unit_x(), Vector3Df::unit_x()), 1.0f);
186 CHECK_IF_EQUAL( dot(Vector3Df::unit_y(), Vector3Df::unit_y()), 1.0f);
187 CHECK_IF_EQUAL( dot(Vector3Df::unit_z(), Vector3Df::unit_z()), 1.0f);
188
189 // Misc Rotations
190 CHECK_IF_EQUAL( dot(Vector3Df{sqrt2_over_2, sqrt2_over_2, 0.0f}, Vector3Df{sqrt2_over_2, sqrt2_over_2, 0.0f}), 1.0f ); // 45 deg rotation
191}
192
194{
195 Generic::VecArray<double, 3> input_vector( {0.0, 1.0, 2.0} );
196 Generic::VecArray<double, 3> new_vector = Generic::swizzle<double, 3, 2, 1, 0>(input_vector);
197
198 assert(input_vector[0] == new_vector[2]);
199 assert(input_vector[1] == new_vector[1]);
200 assert(input_vector[2] == new_vector[0]);
201}
202
203void Run()
204{
205 std::cout << "Running Vector3D Tests..." << std::endl;
206
217 Dot();
218
219 std::cout << "PASSED!" << std::endl;
220
221}
222}
223
224int main(void)
225{
227 return EXIT_SUCCESS;
228}
int main(void)
void CHECK_IF_NOT_EQUAL(float input, float near_to, float tolerance=0.0002f)
Definition Checks.hpp:158
void CHECK_IF_EQUAL(float input, float near_to, float tolerance=0.0002f)
Definition Checks.hpp:127
void CHECK_IF_ZERO(float input, float tolerance=0.0002f)
Definition Checks.hpp:189
Definition Angle.hpp:16
void AssignVector3DToVector3DRef()
void ThreeInitializers()
void AssignVector3DToVector3D()
void DefaultInitialied()
void TestFunction(const Vector3Df &input)
void AssignVector3DRefToVector3D()
void TwoInitializers()
void OneInitializer()
void OperatorEqualsAndNotEquals()
void AssignVector3DRefToVector3DRef()
void PassedToFunction()