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