Line |
Branch |
Exec |
Source |
1 |
|
|
#pragma once |
2 |
|
|
|
3 |
|
|
#include "base/vec3.h" |
4 |
|
|
|
5 |
|
|
#include "assert/assert.h" |
6 |
|
|
#include "base/numeric.h" |
7 |
|
|
|
8 |
|
|
namespace eu |
9 |
|
|
{ |
10 |
|
|
/** \addtogroup math |
11 |
|
|
* @{ |
12 |
|
|
*/ |
13 |
|
|
|
14 |
|
|
/// A 4d vector. |
15 |
|
|
/// It represents a homogeneous coordinate/projective coordinate. |
16 |
|
|
struct v4 |
17 |
|
|
{ |
18 |
|
|
float x; |
19 |
|
|
float y; |
20 |
|
|
float z; |
21 |
|
|
float w; |
22 |
|
|
|
23 |
|
|
v4(float ax, float ay, float az, float aw); |
24 |
|
|
|
25 |
|
|
/// @param a the xyz components |
26 |
|
|
/// @param aw the w component, point=1, vector=0 |
27 |
|
|
v4(const v3 &a, float aw); |
28 |
|
|
|
29 |
|
|
/// Construct the vector from an array. |
30 |
|
|
/// It is assumed the array is of at least 4 elements in xyzw order. |
31 |
|
|
explicit v4(const float *a); |
32 |
|
|
|
33 |
|
|
/// asserts that the w component is what is expected, point=1, vector=0 |
34 |
|
|
[[nodiscard]] v3 to_vec3(float ww) const; |
35 |
|
|
|
36 |
|
|
/// returns a 3d vector using perspective division |
37 |
|
|
[[nodiscard]] v3 to_vec3_persp_div() const; |
38 |
|
|
|
39 |
|
|
/// returns an array to the data |
40 |
|
|
float* get_data_ptr(); |
41 |
|
|
|
42 |
|
|
/// returns an array to the data |
43 |
|
|
[[nodiscard]] const float *get_data_ptr() const; |
44 |
|
|
|
45 |
|
|
bool operator==(const v4 &rhs) = delete; |
46 |
|
|
}; |
47 |
|
|
|
48 |
|
|
/// converts a 4d vector to a string, prefer fmt |
49 |
|
|
std::string string_from(const v4 &v); |
50 |
|
|
|
51 |
|
|
/** @}*/ |
52 |
|
|
|
53 |
|
|
ADD_CATCH_FORMATTER_DEF(v4) |
54 |
|
|
} |
55 |
|
|
|
56 |
1/2
✓ Branch 0 (2 → 3) taken 1 times.
✗ Branch 1 (2 → 17) not taken.
|
2 |
ADD_DEFAULT_FORMATTER(eu::v4, std::string, eu::string_from); |
57 |
|
|
|
58 |
|
|
|