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
array_operations.hxx
Go to the documentation of this file.
1
3
4
#pragma once
5
#include <
ice/math/array.hxx
>
6
#include <numeric>
7
8
namespace
ice::math
9
{
10
11
template
<u32 Size,
typename
T,
typename
U = T>
12
constexpr
auto
max
(
arr_t<Size, T>
left,
arr_t<Size, U>
right)
noexcept
->
arr_t<Size, T>
;
13
14
template
<u32 Size,
typename
T,
typename
U = T>
15
constexpr
auto
min
(
arr_t<Size, T>
left,
arr_t<Size, U>
right)
noexcept
->
arr_t<Size, T>
;
16
17
template
<u32 Size,
typename
T,
typename
U = T>
18
constexpr
auto
add
(
arr_t<Size, T>
left,
arr_t<Size, U>
right)
noexcept
->
arr_t<Size, T>
;
19
20
template
<u32 Size,
typename
T,
typename
U = T>
21
constexpr
auto
add
(
vec<Size, T>
left,
arr_t<Size, U>
right)
noexcept
->
vec<Size, T>
;
22
23
template
<u32 Size,
typename
T,
typename
U = T>
24
constexpr
auto
sub
(
arr_t<Size, T>
left,
arr_t<Size, U>
right)
noexcept
->
arr_t<Size, T>
;
25
26
template
<u32 Size,
typename
T,
typename
U = T>
27
constexpr
auto
sub
(
vec<Size, T>
left,
arr_t<Size, U>
right)
noexcept
->
vec<Size, T>
;
28
29
template
<u32 Size,
typename
T,
typename
U = T>
30
constexpr
auto
mul
(
arr_t<Size, T>
left, U right)
noexcept
->
arr_t<Size, T>
;
31
32
template
<u32 Size,
typename
T,
typename
U = T>
33
constexpr
auto
mul
(
arr_t<Size, T>
left,
arr_t<Size, U>
right)
noexcept
->
arr_t<Size, T>
;
34
35
template
<u32 Size,
typename
T,
typename
U = T>
36
constexpr
auto
mul
(
vec<Size, T>
left,
arr_t<Size, U>
right)
noexcept
->
vec<Size, T>
;
37
38
template
<u32 Size,
typename
T,
typename
U = T>
39
constexpr
auto
div
(
arr_t<Size, T>
left, U right)
noexcept
->
arr_t<Size, T>
;
40
41
template
<u32 Size,
typename
T,
typename
U = T>
42
constexpr
auto
div
(
arr_t<Size, T>
left,
arr_t<Size, U>
right)
noexcept
->
arr_t<Size, T>
;
43
44
template
<u32 Size,
typename
T,
typename
U = T>
45
constexpr
auto
div
(
vec<Size, T>
left,
arr_t<Size, U>
right)
noexcept
->
vec<Size, T>
;
46
47
48
template
<u32 Size,
typename
T,
typename
U>
49
constexpr
auto
max
(
arr_t<Size, T>
left,
arr_t<Size, U>
right)
noexcept
->
arr_t<Size, T>
50
{
51
arr_t<Size, T>
result;
52
for
(
u32
i = 0; i < Size; ++i)
53
{
54
result.v[i] =
ice::max
(left.v[i], T{ right.v[i] });
55
}
56
return
result;
57
}
58
59
template
<u32 Size,
typename
T,
typename
U>
60
constexpr
auto
min
(
arr_t<Size, T>
left,
arr_t<Size, U>
right)
noexcept
->
arr_t<Size, T>
61
{
62
arr_t<Size, T>
result;
63
for
(
u32
i = 0; i < Size; ++i)
64
{
65
result.v[i] =
ice::min
(left.v[i], T{ right.v[i] });
66
}
67
return
result;
68
}
69
70
template
<u32 Size,
typename
T,
typename
U>
71
constexpr
auto
add
(
arr_t<Size, T>
left,
arr_t<Size, U>
right)
noexcept
->
arr_t<Size, T>
72
{
73
arr_t<Size, T>
result;
74
for
(
u32
i = 0; i < Size; ++i)
75
{
76
result.v[i] = left.v[i] + T{ right.v[i] };
77
}
78
return
result;
79
}
80
81
template
<u32 Size,
typename
T,
typename
U>
82
constexpr
auto
add
(
vec<Size, T>
left,
arr_t<Size, U>
right)
noexcept
->
vec<Size, T>
83
{
84
vec<Size, T>
result;
85
for
(
u32
i = 0; i < Size; ++i)
86
{
87
result.
v
[0][i] = left.v[0][i] + T{ right.v[i] };
88
}
89
return
result;
90
}
91
92
template
<u32 Size,
typename
T,
typename
U>
93
constexpr
auto
sub
(
arr_t<Size, T>
left,
arr_t<Size, U>
right)
noexcept
->
arr_t<Size, T>
94
{
95
arr_t<Size, T>
result;
96
for
(
u32
i = 0; i < Size; ++i)
97
{
98
result.v[i] = left.v[i] - T{ right.v[i] };
99
}
100
return
result;
101
}
102
103
template
<u32 Size,
typename
T,
typename
U>
104
constexpr
auto
sub
(
vec<Size, T>
left,
arr_t<Size, U>
right)
noexcept
->
vec<Size, T>
105
{
106
vec<Size, T>
result;
107
for
(
u32
i = 0; i < Size; ++i)
108
{
109
result.
v
[0][i] = left.v[0][i] - T{ right.v[i] };
110
}
111
return
result;
112
}
113
114
template
<u32 Size,
typename
T,
typename
U>
115
constexpr
auto
mul
(
arr_t<Size, T>
left, U right)
noexcept
->
arr_t<Size, T>
116
{
117
return
mul
(left,
arr_t<Size, U>
{ right });
118
}
119
120
template
<u32 Size,
typename
T,
typename
U>
121
constexpr
auto
mul
(
arr_t<Size, T>
left,
arr_t<Size, U>
right)
noexcept
->
arr_t<Size, T>
122
{
123
arr_t<Size, T>
result;
124
for
(
u32
i = 0; i < Size; ++i)
125
{
126
result.v[i] = left.v[i] * T{ right.v[i] };
127
}
128
return
result;
129
}
130
131
template
<u32 Size,
typename
T,
typename
U>
132
constexpr
auto
mul
(
vec<Size, T>
left,
arr_t<Size, U>
right)
noexcept
->
vec<Size, T>
133
{
134
vec<Size, T>
result;
135
for
(
u32
i = 0; i < Size; ++i)
136
{
137
result.
v
[0][i] = left.v[0][i] * T{ right.v[i] };
138
}
139
return
result;
140
}
141
142
template
<u32 Size,
typename
T,
typename
U>
143
constexpr
auto
div
(
arr_t<Size, T>
left, U right)
noexcept
->
arr_t<Size, T>
144
{
145
return
div
(left,
arr_t<Size, U>
{ right });
146
}
147
148
template
<u32 Size,
typename
T,
typename
U>
149
constexpr
auto
div
(
arr_t<Size, T>
left,
arr_t<Size, U>
right)
noexcept
->
arr_t<Size, T>
150
{
151
arr_t<Size, T>
result;
152
for
(
u32
i = 0; i < Size; ++i)
153
{
154
result.v[i] = left.v[i] / T{ right.v[i] };
155
}
156
return
result;
157
}
158
159
template
<u32 Size,
typename
T,
typename
U>
160
constexpr
auto
div
(
vec<Size, T>
left,
arr_t<Size, U>
right)
noexcept
->
vec<Size, T>
161
{
162
vec<Size, T>
result;
163
for
(
u32
i = 0; i < Size; ++i)
164
{
165
result.
v
[0][i] = left.v[0][i] / T{ right.v[i] };
166
}
167
return
result;
168
}
169
170
}
// namespace ice::math
array.hxx
ice::math
Definition
algorithm.hxx:8
ice::math::mul
constexpr auto mul(U first, Args... args) noexcept
Definition
algorithm.hxx:38
ice::math::div
constexpr auto div(U first, Args... args) noexcept
Definition
algorithm.hxx:46
ice::math::max
constexpr auto max(arr_t< Size, T > left, arr_t< Size, U > right) noexcept -> arr_t< Size, T >
Definition
array_operations.hxx:49
ice::math::vec
mat< Size, 1, T > vec
Definition
vector.hxx:172
ice::math::min
constexpr auto min(arr_t< Size, T > left, arr_t< Size, U > right) noexcept -> arr_t< Size, T >
Definition
array_operations.hxx:60
ice::math::add
constexpr auto add(arr_t< Size, T > left, arr_t< Size, U > right) noexcept -> arr_t< Size, T >
Definition
array_operations.hxx:71
ice::math::sub
constexpr auto sub(U first, Args... args) noexcept
Definition
algorithm.hxx:30
ice::u32
std::uint32_t u32
Definition
types.hxx:26
ice::math::arr_t
Definition
array.hxx:27
ice::math::mat::v
T v[count_columns][count_rows]
Definition
matrix.hxx:17
Generated by
1.18.0