Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
MathVectorTests.cpp
Go to the documentation of this file.
2
3namespace Divide
4{
5
6TEST_CASE( "Vec Size Tests", "[math_vectors_test]" )
7{
8 const vec2<I8> a1;
9 const vec2<U8> a2;
10 const vec2<I16> a3;
11 const vec2<U16> a4;
12 const vec2<I32> a5;
13 const vec2<U32> a6;
14 const vec2<I64> a7;
15 const vec2<U64> a8;
16 const vec2<F32> a9;
17 const vec2<D64> a10;
18
19 CHECK_EQUAL(sizeof(a5), (32 * 2) / 8);
20
21 CHECK_EQUAL(sizeof(a1), sizeof(I8) * 2);
22 CHECK_EQUAL(sizeof(a2), sizeof(U8) * 2);
23 CHECK_EQUAL(sizeof(a3), sizeof(I16) * 2);
24 CHECK_EQUAL(sizeof(a4), sizeof(U16) * 2);
25 CHECK_EQUAL(sizeof(a5), sizeof(I32) * 2);
26 CHECK_EQUAL(sizeof(a6), sizeof(U32) * 2);
27 CHECK_EQUAL(sizeof(a7), sizeof(I64) * 2);
28 CHECK_EQUAL(sizeof(a8), sizeof(U64) * 2);
29 CHECK_EQUAL(sizeof(a9), sizeof(F32) * 2);
30 CHECK_EQUAL(sizeof(a10), sizeof(D64) * 2);
31 CHECK_EQUAL(sizeof(a10), sizeof(a9) * 2);
32
33 const vec3<I8> b1;
34 const vec3<U8> b2;
35 const vec3<I16> b3;
36 const vec3<U16> b4;
37 const vec3<I32> b5;
38 const vec3<U32> b6;
39 const vec3<I64> b7;
40 const vec3<U64> b8;
41 const vec3<F32> b9;
42 const vec3<D64> b10;
43
44 CHECK_EQUAL(sizeof(b5), (32 * 3) / 8);
45
46 CHECK_EQUAL(sizeof(b1), sizeof(I8) * 3);
47 CHECK_EQUAL(sizeof(b2), sizeof(U8) * 3);
48 CHECK_EQUAL(sizeof(b3), sizeof(I16) * 3);
49 CHECK_EQUAL(sizeof(b4), sizeof(U16) * 3);
50 CHECK_EQUAL(sizeof(b5), sizeof(I32) * 3);
51 CHECK_EQUAL(sizeof(b6), sizeof(U32) * 3);
52 CHECK_EQUAL(sizeof(b7), sizeof(I64) * 3);
53 CHECK_EQUAL(sizeof(b8), sizeof(U64) * 3);
54 CHECK_EQUAL(sizeof(b9), sizeof(F32) * 3);
55 CHECK_EQUAL(sizeof(b10), sizeof(D64) * 3);
56 CHECK_EQUAL(sizeof(b10), sizeof(b9) * 2);
57
58 const vec4<I8> c1;
59 const vec4<U8> c2;
60 const vec4<I16> c3;
61 const vec4<U16> c4;
62 const vec4<I32> c5;
63 const vec4<U32> c6;
64 const vec4<I64> c7;
65 const vec4<U64> c8;
66 const vec4<F32> c9;
67 const vec4<D64> c10;
68
69 CHECK_EQUAL(sizeof(c5), (32 * 4) / 8);
70
71 CHECK_EQUAL(sizeof(c1), sizeof(I8) * 4);
72 CHECK_EQUAL(sizeof(c2), sizeof(U8) * 4);
73 CHECK_EQUAL(sizeof(c3), sizeof(I16) * 4);
74 CHECK_EQUAL(sizeof(c4), sizeof(U16) * 4);
75 CHECK_EQUAL(sizeof(c5), sizeof(I32) * 4);
76 CHECK_EQUAL(sizeof(c6), sizeof(U32) * 4);
77 CHECK_EQUAL(sizeof(c7), sizeof(I64) * 4);
78 CHECK_EQUAL(sizeof(c8), sizeof(U64) * 4);
79 CHECK_EQUAL(sizeof(c9), sizeof(F32) * 4);
80 CHECK_EQUAL(sizeof(c10), sizeof(D64) * 4);
81 CHECK_EQUAL(sizeof(c10), sizeof(c9) * 2);
82}
83
84TEST_CASE( "Vec Constructor Conversions", "[math_vectors_test]" )
85{
86 const vec2<F32> input1(1.0f, 2.0f);
87 const vec2<I32> input2(1, 2);
88
89 CHECK_EQUAL(input2, vec2<I32>(input1));
90
92}
93
94TEST_CASE( "Vec Length Tests", "[math_vectors_test]" )
95{
96 vec2<F32> input1;
97 vec3<F32> input2;
98 vec4<F32> input3;
99 vec4<F32> input4{0.f, 0.f, 0.f, 1.f};
100
101 CHECK_ZERO(input1.length());
102 CHECK_ZERO(input2.length());
103 CHECK_ZERO(input3.length());
104 CHECK_TRUE(COMPARE(input4.length(), 1.f));
105 input3.w = 0.0f;
106 CHECK_ZERO(input3.length());
107
108
109 input1.set(2.0f, 3.0f);
110 CHECK_NOT_ZERO(input1.length());
111
112 input2.set(4.0f, 3.0f, 2.0f);
113 input3.set(4.0f, 3.0f, 2.0f, 0.0f);
114 CHECK_TRUE(COMPARE(std::sqrt(input2.lengthSquared()), input3.length()));
115}
116
117TEST_CASE( "Vec-Scalar Multiply Tests", "[math_vectors_test]" )
118{
119 const vec2<I32> input1(-2);
120 const vec3<F32> input2(5.0f, 0.0f, -5.0f);
121 const vec4<U32> input3(10);
122
123 const vec2<I32> result1(-22);
124 const vec3<F32> result2(2.5f, 0.0f, -2.5f);
125 const vec4<U32> result3(30);
126
127 CHECK_EQUAL(input1 * 11, result1);
128 CHECK_EQUAL(input2 * 0.5f, result2);
129 CHECK_EQUAL(input3 * 3, result3);
130}
131
132TEST_CASE( "Vec-Vec Multiply Tests", "[math_vectors_test]" )
133{
134 const vec2<U32> input1(2);
135 const vec3<I32> input2(5, 0, -5);
136 const vec4<F32> input3(10.0f);
137
138 const vec2<U32> input4(4);
139 const vec3<I32> input5(2, 3, -1);
140 const vec4<F32> input6(1.0f);
141
142 const vec2<U32> result1((2u * 4u), (2u * 4u));
143 const vec3<I32> result2((5 * 2), (0 * 3), (-5 * -1));
144 const vec4<F32> result3((10.0f * 1.0f), (10.0f * 1.0f), (10.0f * 1.0f), (10.0f * 1.0f));
145
146 CHECK_EQUAL(input1 * input4, result1);
147 CHECK_EQUAL(input2 * input5, result2);
148 CHECK_EQUAL(input3 * input6, result3);
149}
150
151TEST_CASE( "Vec Dot Tests", "[math_vectors_test]" )
152{
153 const vec2<U32> input1(2);
154 const vec3<I32> input2(5, 0, -5);
155 const vec4<F32> input3(10.0f);
156
157 const vec2<U32> input4(4);
158 const vec3<I32> input5(2, 3, -1);
159 const vec4<F32> input6(1.0f);
160
161 CHECK_EQUAL(input1.dot(input4), (2u * 4u) + (2u * 4u));
162 CHECK_EQUAL(input2.dot(input5), (5 * 2) +( 0 * 3) + (-5 * -1));
163 CHECK_TRUE(COMPARE(input3.dot(input6), (10.0f * 1.0f) + (10.0f * 1.0f) + (10.0f * 1.0f) + (10.0f * 1.0f)));
164}
165
166
167} //namespace Divide
void set(const T *v) noexcept
set the 2 components of the vector manually using a source pointer to a (large enough) array
Definition: MathVectors.h:335
T length() const noexcept
return the vector's length
Definition: MathVectors.h:375
T dot(const vec2 &v) const noexcept
calculate the dot product between this vector and the specified one
T dot(const vec3 &v) const noexcept
calculate the dot product between this vector and the specified one
T length() const noexcept
return the vector's length
Definition: MathVectors.h:747
T lengthSquared() const noexcept
return the squared distance of the vector
void set(const T *v) noexcept
set the 3 components of the vector manually using a source pointer to a (large enough) array
Definition: MathVectors.h:707
void set(const T *v) noexcept
set the 4 components of the vector manually using a source pointer to a (large enough) array
Definition: MathVectors.h:1241
T length() const noexcept
return the vector's length
Definition: MathVectors.h:1312
T dot(const vec4 &v) const noexcept
calculate the dot product between this vector and the specified one
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
int32_t I32
uint8_t U8
int16_t I16
uint16_t U16
double D64
bool COMPARE(T X, U Y) noexcept
TEST_CASE("ByteBuffer RW Bool", "[byte_buffer]")
int64_t I64
uint32_t U32
uint64_t U64
#define CHECK_ZERO(X)
#define CHECK_NOT_ZERO(X)
#define CHECK_EQUAL(LHS, RHS)
#define CHECK_TRUE(...)