IceShard 1
A personal game engine project, with development focused on 2D/2.5D games.
Loading...
Searching...
No Matches
vector.hxx
Go to the documentation of this file.
1
3
4#pragma once
5#include <ice/math/matrix.hxx>
6
7namespace ice::math
8{
9
10 template<typename T>
11 struct mat<1, 1, T>
12 {
13 using value_type = T;
14 static constexpr auto count_rows = 1;
15 static constexpr auto count_columns = 1;
16
17 constexpr mat() noexcept
18 : v{ }
19 { }
20
21 explicit constexpr mat(T value) noexcept
22 : v{ { value } }
23 { }
24
25 constexpr mat(T const(&array)[1]) noexcept
26 : v{ { array[0] }}
27 { }
28
29 union
30 {
32 T x;
33 };
34 };
35
36 template<typename T>
37 struct mat<2, 1, T>
38 {
39 using value_type = T;
40 static constexpr auto count_rows = 2;
41 static constexpr auto count_columns = 1;
42
43 constexpr mat() noexcept
44 : v{ }
45 { }
46
47 explicit constexpr mat(T value) noexcept
48 : v{ { value, value } }
49 { }
50
51 constexpr mat(T const(&array)[2]) noexcept
52 : v{ { array[0], array[1] } }
53 { }
54
55 constexpr mat(T x, T y) noexcept
56 : v{ { x, y } }
57 { }
58
59 template<typename U> requires(std::convertible_to<U, T>)
60 constexpr explicit mat(mat<2, 1, U> other) noexcept
61 : v{ { static_cast<T>(other.x), static_cast<T>(other.y) } }
62 { }
63
64 constexpr explicit mat(T const(&array)[3]) noexcept
65 : v{ { array[0] / array[2], array[1] / array[2] } }
66 { }
67
68 union
69 {
71 struct
72 {
73 T x, y;
74 };
75 };
76 };
77
78 template<typename T>
79 struct mat<3, 1, T>
80 {
81 using value_type = T;
82 static constexpr auto count_rows = 3;
83 static constexpr auto count_columns = 1;
84
85 constexpr mat() noexcept
86 : v{ }
87 { }
88
89 explicit constexpr mat(T value) noexcept
90 : v{ { value, value, value } }
91 { }
92
93 constexpr mat(T const(&array)[3]) noexcept
94 : v{ { array[0], array[1], array[2] } }
95 { }
96
97 constexpr mat(T x, T y, T z) noexcept
98 : v{ { x, y, z } }
99 { }
100
101 template<typename U> requires(std::convertible_to<U, T>)
102 constexpr explicit mat(mat<3, 1, U> other) noexcept
103 : v{ { static_cast<T>(other.x), static_cast<T>(other.y), static_cast<T>(other.z) } }
104 { }
105
106 template<typename U> requires(std::convertible_to<U, T>)
107 constexpr explicit mat(mat<4, 1, U> other) noexcept
108 : v{ {
109 static_cast<T>(other.x) / static_cast<T>(other.w),
110 static_cast<T>(other.y) / static_cast<T>(other.w),
111 static_cast<T>(other.z) / static_cast<T>(other.w)
112 } }
113 { }
114
115 constexpr explicit mat(T const(&array)[4]) noexcept
116 : v{ { array[0] / array[3], array[1] / array[3], array[2] / array[3] } }
117 { }
118
119 union
120 {
122 struct
123 {
124 T x, y, z;
125 };
126 };
127 };
128
129 template<typename T>
130 struct mat<4, 1, T>
131 {
132 using value_type = T;
133 static constexpr auto count_rows = 4;
134 static constexpr auto count_columns = 1;
135
136 constexpr mat() noexcept
137 : v{ }
138 { }
139
140 explicit constexpr mat(T value) noexcept
141 : v{ { value, value, value, value } }
142 { }
143
144 constexpr mat(T const(&array)[4]) noexcept
145 : v{ { array[0], array[1], array[2], array[3] } }
146 { }
147
148 constexpr mat(T x, T y, T z, T w) noexcept
149 : v{ { x, y, z, w } }
150 { }
151
152 template<typename U> requires(std::convertible_to<U, T>)
153 constexpr explicit mat(mat<4, 1, U> other) noexcept
154 : v{ { static_cast<T>(other.x), static_cast<T>(other.y), static_cast<T>(other.z), static_cast<T>(other.w) } }
155 { }
156
157 union
158 {
160 struct
161 {
162 T x, y, z, w;
163 };
164 };
165 };
166
167 // Deduction guide for vectors
168 template<u32 Size, typename T>
169 mat(T(&)[Size]) -> mat<Size, 1, T>;
170
171 template<u32 Size, typename T>
173
177
181
187
191
192
193} // namespace ice::math
Definition algorithm.hxx:8
vec< 3, rad > vec3rad
Definition vector.hxx:186
vec< 2, u32 > vec2u
Definition vector.hxx:179
vec< 1, f32 > vec1f
Definition vector.hxx:174
mat< Size, 1, T > vec
Definition vector.hxx:172
vec< 3, i32 > vec3i
Definition vector.hxx:184
vec< 4, u32 > vec4u
Definition vector.hxx:189
vec< 1, i32 > vec1i
Definition vector.hxx:176
vec< 4, i32 > vec4i
Definition vector.hxx:190
vec< 2, f32 > vec2f
Definition vector.hxx:178
vec< 3, deg > vec3deg
Definition vector.hxx:185
vec< 3, u32 > vec3u
Definition vector.hxx:183
vec< 2, i32 > vec2i
Definition vector.hxx:180
mat(T(&)[Size]) -> mat< Size, 1, T >
vec< 1, u32 > vec1u
Definition vector.hxx:175
vec< 4, f32 > vec4f
Definition vector.hxx:188
vec< 3, f32 > vec3f
Definition vector.hxx:182
static constexpr auto count_columns
Definition vector.hxx:15
T value_type
Definition vector.hxx:13
T v[count_columns][count_rows]
Definition vector.hxx:31
static constexpr auto count_rows
Definition vector.hxx:14
constexpr mat(T const(&array)[1]) noexcept
Definition vector.hxx:25
T x
Definition vector.hxx:32
constexpr mat() noexcept
Definition vector.hxx:17
constexpr mat(T value) noexcept
Definition vector.hxx:21
constexpr mat(T x, T y) noexcept
Definition vector.hxx:55
constexpr mat(T value) noexcept
Definition vector.hxx:47
constexpr mat() noexcept
Definition vector.hxx:43
constexpr mat(T const(&array)[2]) noexcept
Definition vector.hxx:51
T x
Definition vector.hxx:73
constexpr mat(T const(&array)[3]) noexcept
Definition vector.hxx:64
constexpr mat(mat< 2, 1, U > other) noexcept
Definition vector.hxx:60
static constexpr auto count_rows
Definition vector.hxx:40
T value_type
Definition vector.hxx:39
static constexpr auto count_columns
Definition vector.hxx:41
T y
Definition vector.hxx:73
T v[count_columns][count_rows]
Definition vector.hxx:70
static constexpr auto count_columns
Definition vector.hxx:83
constexpr mat(T x, T y, T z) noexcept
Definition vector.hxx:97
constexpr mat() noexcept
Definition vector.hxx:85
constexpr mat(mat< 3, 1, U > other) noexcept
Definition vector.hxx:102
static constexpr auto count_rows
Definition vector.hxx:82
T v[count_columns][count_rows]
Definition vector.hxx:121
constexpr mat(T const(&array)[3]) noexcept
Definition vector.hxx:93
T y
Definition vector.hxx:124
T value_type
Definition vector.hxx:81
T z
Definition vector.hxx:124
T x
Definition vector.hxx:124
constexpr mat(T value) noexcept
Definition vector.hxx:89
constexpr mat(T const(&array)[4]) noexcept
Definition vector.hxx:115
constexpr mat(mat< 4, 1, U > other) noexcept
Definition vector.hxx:107
T v[count_columns][count_rows]
Definition vector.hxx:159
T z
Definition vector.hxx:162
T w
Definition vector.hxx:162
T y
Definition vector.hxx:162
constexpr mat(T const(&array)[4]) noexcept
Definition vector.hxx:144
constexpr mat(T value) noexcept
Definition vector.hxx:140
T value_type
Definition vector.hxx:132
constexpr mat() noexcept
Definition vector.hxx:136
constexpr mat(mat< 4, 1, U > other) noexcept
Definition vector.hxx:153
constexpr mat(T x, T y, T z, T w) noexcept
Definition vector.hxx:148
T x
Definition vector.hxx:162
static constexpr auto count_columns
Definition vector.hxx:134
static constexpr auto count_rows
Definition vector.hxx:133
Definition matrix.hxx:12