8
8
#include < stdexcept>
9
9
#include < utility>
10
10
#include " Vector3.hpp"
11
-
11
+ # include " omath/omath_export.hpp "
12
12
13
13
namespace omath
14
14
{
15
- struct MatSize
15
+ struct OMATH_API MatSize
16
16
{
17
17
size_t rows, columns;
18
18
};
@@ -28,15 +28,15 @@ namespace omath
28
28
class Mat final
29
29
{
30
30
public:
31
- constexpr Mat ()
31
+ OMATH_API constexpr Mat ()
32
32
{
33
33
Clear ();
34
34
}
35
- constexpr static MatStoreType GetStoreOrdering ()
35
+ OMATH_API constexpr static MatStoreType GetStoreOrdering ()
36
36
{
37
37
return StoreType;
38
38
}
39
- constexpr Mat (const std::initializer_list<std::initializer_list<Type>>& rows)
39
+ OMATH_API constexpr Mat (const std::initializer_list<std::initializer_list<Type>>& rows)
40
40
{
41
41
if (rows.size () != Rows)
42
42
throw std::invalid_argument (" Initializer list rows size does not match template parameter Rows" );
@@ -56,40 +56,40 @@ namespace omath
56
56
}
57
57
}
58
58
59
- constexpr explicit Mat (const Type* rawData)
59
+ OMATH_API constexpr explicit Mat (const Type* rawData)
60
60
{
61
61
std::copy_n (rawData, Rows * Columns, m_data.begin ());
62
62
}
63
63
64
- constexpr Mat (const Mat& other) noexcept
64
+ OMATH_API constexpr Mat (const Mat& other) noexcept
65
65
{
66
66
m_data = other.m_data ;
67
67
}
68
68
69
- constexpr Mat (Mat&& other) noexcept
69
+ OMATH_API constexpr Mat (Mat&& other) noexcept
70
70
{
71
71
m_data = std::move (other.m_data );
72
72
}
73
73
74
74
[[nodiscard]]
75
- static constexpr size_t RowCount () noexcept
75
+ OMATH_API static constexpr size_t RowCount () noexcept
76
76
{
77
77
return Rows;
78
78
}
79
79
80
80
[[nodiscard]]
81
- static constexpr size_t ColumnsCount () noexcept
81
+ OMATH_API static constexpr size_t ColumnsCount () noexcept
82
82
{
83
83
return Columns;
84
84
}
85
85
86
86
[[nodiscard]]
87
- static consteval MatSize Size () noexcept
87
+ OMATH_API static consteval MatSize Size () noexcept
88
88
{
89
89
return {Rows, Columns};
90
90
}
91
91
92
- [[nodiscard]] constexpr const Type& At (const size_t rowIndex, const size_t columnIndex) const
92
+ [[nodiscard]] OMATH_API constexpr const Type& At (const size_t rowIndex, const size_t columnIndex) const
93
93
{
94
94
if (rowIndex >= Rows || columnIndex >= Columns)
95
95
throw std::out_of_range (" Index out of range" );
@@ -107,13 +107,13 @@ namespace omath
107
107
}
108
108
}
109
109
110
- [[nodiscard]] constexpr Type& At (const size_t rowIndex, const size_t columnIndex)
110
+ [[nodiscard]] OMATH_API constexpr Type& At (const size_t rowIndex, const size_t columnIndex)
111
111
{
112
112
return const_cast <Type&>(std::as_const (*this ).At (rowIndex, columnIndex));
113
113
}
114
114
115
115
[[nodiscard]]
116
- constexpr Type Sum () const noexcept
116
+ OMATH_API constexpr Type Sum () const noexcept
117
117
{
118
118
Type sum = 0 ;
119
119
for (size_t i = 0 ; i < Rows; ++i)
@@ -123,20 +123,20 @@ namespace omath
123
123
return sum;
124
124
}
125
125
126
- constexpr void Clear () noexcept
126
+ OMATH_API constexpr void Clear () noexcept
127
127
{
128
128
Set (0 );
129
129
}
130
130
131
- constexpr void Set (const Type& value) noexcept
131
+ OMATH_API constexpr void Set (const Type& value) noexcept
132
132
{
133
133
std::ranges::fill (m_data, value);
134
134
}
135
135
136
136
// Operator overloading for multiplication with another Mat
137
137
template <size_t OtherColumns>
138
138
constexpr Mat<Rows, OtherColumns, Type, StoreType>
139
- operator *(const Mat<Columns, OtherColumns, Type, StoreType>& other) const
139
+ OMATH_API operator *(const Mat<Columns, OtherColumns, Type, StoreType>& other) const
140
140
{
141
141
Mat<Rows, OtherColumns, Type, StoreType> result;
142
142
@@ -151,7 +151,7 @@ namespace omath
151
151
return result;
152
152
}
153
153
154
- constexpr Mat& operator *=(const Type& f) noexcept
154
+ OMATH_API constexpr Mat& operator *=(const Type& f) noexcept
155
155
{
156
156
for (size_t i = 0 ; i < Rows; ++i)
157
157
for (size_t j = 0 ; j < Columns; ++j)
@@ -161,34 +161,34 @@ namespace omath
161
161
162
162
template <size_t OtherColumns>
163
163
constexpr Mat<Rows, OtherColumns, Type, StoreType>
164
- operator *=(const Mat<Columns, OtherColumns, Type, StoreType>& other)
164
+ OMATH_API operator *=(const Mat<Columns, OtherColumns, Type, StoreType>& other)
165
165
{
166
166
return *this = *this * other;
167
167
}
168
168
169
- constexpr Mat operator *(const Type& f) const noexcept
169
+ OMATH_API constexpr Mat operator *(const Type& f) const noexcept
170
170
{
171
171
Mat result (*this );
172
172
result *= f;
173
173
return result;
174
174
}
175
175
176
- constexpr Mat& operator /=(const Type& f) noexcept
176
+ OMATH_API constexpr Mat& operator /=(const Type& f) noexcept
177
177
{
178
178
for (size_t i = 0 ; i < Rows; ++i)
179
179
for (size_t j = 0 ; j < Columns; ++j)
180
180
At (i, j) /= f;
181
181
return *this ;
182
182
}
183
183
184
- constexpr Mat operator /(const Type& f) const noexcept
184
+ OMATH_API constexpr Mat operator /(const Type& f) const noexcept
185
185
{
186
186
Mat result (*this );
187
187
result /= f;
188
188
return result;
189
189
}
190
190
191
- constexpr Mat& operator =(const Mat& other) noexcept
191
+ OMATH_API constexpr Mat& operator =(const Mat& other) noexcept
192
192
{
193
193
if (this == &other)
194
194
return *this ;
@@ -198,7 +198,7 @@ namespace omath
198
198
return *this ;
199
199
}
200
200
201
- constexpr Mat& operator =(Mat&& other) noexcept
201
+ OMATH_API constexpr Mat& operator =(Mat&& other) noexcept
202
202
{
203
203
if (this == &other)
204
204
return *this ;
@@ -211,7 +211,7 @@ namespace omath
211
211
}
212
212
213
213
[[nodiscard]]
214
- constexpr Mat<Columns, Rows, Type, StoreType> Transposed () const noexcept
214
+ OMATH_API constexpr Mat<Columns, Rows, Type, StoreType> Transposed () const noexcept
215
215
{
216
216
Mat<Columns, Rows, Type, StoreType> transposed;
217
217
for (size_t i = 0 ; i < Rows; ++i)
@@ -222,7 +222,7 @@ namespace omath
222
222
}
223
223
224
224
[[nodiscard]]
225
- constexpr Type Determinant () const
225
+ OMATH_API constexpr Type Determinant () const
226
226
{
227
227
static_assert (Rows == Columns, " Determinant is only defined for square matrices." );
228
228
@@ -244,7 +244,7 @@ namespace omath
244
244
}
245
245
246
246
[[nodiscard]]
247
- constexpr Mat<Rows - 1 , Columns - 1 , Type, StoreType> Minor (const size_t row, const size_t column) const
247
+ OMATH_API constexpr Mat<Rows - 1 , Columns - 1 , Type, StoreType> Minor (const size_t row, const size_t column) const
248
248
{
249
249
Mat<Rows - 1 , Columns - 1 , Type, StoreType> result;
250
250
for (size_t i = 0 , m = 0 ; i < Rows; ++i)
@@ -264,19 +264,19 @@ namespace omath
264
264
}
265
265
266
266
[[nodiscard]]
267
- constexpr const std::array<Type, Rows * Columns>& RawArray () const
267
+ OMATH_API constexpr const std::array<Type, Rows * Columns>& RawArray () const
268
268
{
269
269
return m_data;
270
270
}
271
271
272
272
[[nodiscard]]
273
- constexpr std::array<Type, Rows * Columns>& RawArray ()
273
+ OMATH_API constexpr std::array<Type, Rows * Columns>& RawArray ()
274
274
{
275
275
return const_cast <std::array<Type, Rows * Columns>>(std::as_const (*this ).RawArray ());
276
276
}
277
277
278
278
[[nodiscard]]
279
- std::string ToString () const noexcept
279
+ OMATH_API std::string ToString () const noexcept
280
280
{
281
281
std::ostringstream oss;
282
282
for (size_t i = 0 ; i < Rows; ++i)
@@ -293,20 +293,20 @@ namespace omath
293
293
}
294
294
295
295
[[nodiscard]]
296
- bool operator ==(const Mat& mat) const
296
+ OMATH_API bool operator ==(const Mat& mat) const
297
297
{
298
298
return m_data == mat.m_data ;
299
299
}
300
300
301
301
[[nodiscard]]
302
- bool operator !=(const Mat& mat) const
302
+ OMATH_API bool operator !=(const Mat& mat) const
303
303
{
304
304
return !operator ==(mat);
305
305
}
306
306
307
307
// Static methods that return fixed-size matrices
308
308
[[nodiscard]]
309
- constexpr static Mat<4 , 4 > ToScreenMat (const Type& screenWidth, const Type& screenHeight) noexcept
309
+ OMATH_API constexpr static Mat<4 , 4 > ToScreenMat (const Type& screenWidth, const Type& screenHeight) noexcept
310
310
{
311
311
return {
312
312
{screenWidth / 2 , 0 , 0 , 0 },
@@ -336,7 +336,7 @@ namespace omath
336
336
337
337
template <class Type = float , MatStoreType St = MatStoreType::ROW_MAJOR>
338
338
[[nodiscard]]
339
- constexpr Mat<4 , 4 , Type, St> MatTranslation (const Vector3& diff) noexcept
339
+ OMATH_API constexpr Mat<4 , 4 , Type, St> MatTranslation (const Vector3& diff) noexcept
340
340
{
341
341
return
342
342
{
@@ -349,7 +349,7 @@ namespace omath
349
349
350
350
template <class Type = float , MatStoreType St = MatStoreType::ROW_MAJOR, class Angle >
351
351
[[nodiscard]]
352
- Mat<4 , 4 , Type, St> MatRotationAxisX (const Angle& angle) noexcept
352
+ OMATH_API Mat<4 , 4 , Type, St> MatRotationAxisX (const Angle& angle) noexcept
353
353
{
354
354
return
355
355
{
@@ -362,7 +362,7 @@ namespace omath
362
362
363
363
template <class Type = float , MatStoreType St = MatStoreType::ROW_MAJOR, class Angle >
364
364
[[nodiscard]]
365
- Mat<4 , 4 , Type, St> MatRotationAxisY (const Angle& angle) noexcept
365
+ OMATH_API Mat<4 , 4 , Type, St> MatRotationAxisY (const Angle& angle) noexcept
366
366
{
367
367
return
368
368
{
@@ -375,7 +375,7 @@ namespace omath
375
375
376
376
template <class Type = float , MatStoreType St = MatStoreType::ROW_MAJOR, class Angle >
377
377
[[nodiscard]]
378
- Mat<4 , 4 , Type, St> MatRotationAxisZ (const Angle& angle) noexcept
378
+ OMATH_API Mat<4 , 4 , Type, St> MatRotationAxisZ (const Angle& angle) noexcept
379
379
{
380
380
return
381
381
{
@@ -403,7 +403,7 @@ namespace omath
403
403
404
404
template <class Type = float , MatStoreType St = MatStoreType::ROW_MAJOR, class ViewAngles >
405
405
[[nodiscard]]
406
- Mat<4 , 4 , Type, St> MatRotation (const ViewAngles& angles) noexcept
406
+ OMATH_API Mat<4 , 4 , Type, St> MatRotation (const ViewAngles& angles) noexcept
407
407
{
408
408
return MatRotationAxisZ (angles.yaw ) * MatRotationAxisY (angles.pitch ) * MatRotationAxisX (angles.roll );
409
409
}
0 commit comments