forked from dotnet/Silk.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrix3X2.cs
More file actions
540 lines (484 loc) · 23.3 KB
/
Copy pathMatrix3X2.cs
File metadata and controls
540 lines (484 loc) · 23.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Globalization;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
namespace Silk.NET.Maths
{
/// <summary>A structure encapsulating a 3x2 matrix.</summary>
[Serializable]
[DataContract]
public struct Matrix3X2<T>
: IEquatable<Matrix3X2<T>>
where T : unmanaged, IFormattable, IComparable<T>, IEquatable<T>
{
private static readonly Matrix3X2<T> _identity = new(
Scalar<T>.One, Scalar<T>.Zero,
Scalar<T>.Zero, Scalar<T>.One,
Scalar<T>.Zero, Scalar<T>.Zero
);
/// <summary>
/// Row 1 of the matrix.
/// </summary>
[IgnoreDataMember]
public Vector2D<T> Row1;
/// <summary>
/// Row 2 of the matrix.
/// </summary>
[IgnoreDataMember]
public Vector2D<T> Row2;
/// <summary>
/// Row 3 of the matrix.
/// </summary>
[IgnoreDataMember]
public Vector2D<T> Row3;
/// <summary>
/// Column 1 of the matrix.
/// </summary>
[IgnoreDataMember]
public Vector3D<T> Column1 => new(Row1.X, Row2.X, Row3.X);
/// <summary>
/// Column 2 of the matrix.
/// </summary>
[IgnoreDataMember]
public Vector3D<T> Column2 => new(Row1.Y, Row2.Y, Row3.Y);
/// <summary>Value at row 1, column 1 of the matrix.</summary>
[DataMember]
public T M11
{
readonly get => Row1.X;
set => Row1.X = value;
}
/// <summary>Value at row 1, column 2 of the matrix.</summary>
[DataMember]
public T M12
{
readonly get => Row1.Y;
set => Row1.Y = value;
}
/// <summary>Value at row 2, column 1 of the matrix.</summary>
[DataMember]
public T M21
{
readonly get => Row2.X;
set => Row2.X = value;
}
/// <summary>Value at row 2, column 2 of the matrix.</summary>
[DataMember]
public T M22
{
readonly get => Row2.Y;
set => Row2.Y = value;
}
/// <summary>Value at row 3, column 1 of the matrix.</summary>
[DataMember]
public T M31
{
readonly get => Row3.X;
set => Row3.X = value;
}
/// <summary>Value at row 3, column 2 of the matrix.</summary>
[DataMember]
public T M32
{
readonly get => Row3.Y;
set => Row3.Y = value;
}
/// <summary>
/// Indexer for the rows of this matrix.
/// </summary>
/// <param name="x">The row to select. Zero based.</param>
public unsafe Vector2D<T> this[int x]
{
get
{
static void VerifyBounds(int i)
{
static void ThrowHelper() => throw new IndexOutOfRangeException();
if (i > 2 || i < 0)
ThrowHelper();
}
VerifyBounds(x);
return Unsafe.Add(ref Row1, x);
}
}
/// <summary>
/// Indexer for the values in this matrix.
/// </summary>
/// <param name="x">The row to select. Zero based.</param>
/// <param name="y">The column to select. Zero based.</param>
public unsafe T this[int x, int y]
{
get
{
var row = this[x];
return row[y];
}
}
/// <summary>Constructs a <see cref="Matrix3X2{T}"/> from the given components.</summary>
public Matrix3X2(T m11, T m12,
T m21, T m22,
T m31, T m32)
{
Row1 = new(m11, m12);
Row2 = new(m21, m22);
Row3 = new(m31, m32);
}
/// <summary>
/// Constructs a <see cref="Matrix3X2{T}"/> from the given rows.
/// </summary>
public Matrix3X2(Vector2D<T> row1, Vector2D<T> row2, Vector2D<T> row3)
{
Row1 = row1;
Row2 = row2;
Row3 = row3;
}
/// <summary>Constructs a <see cref="Matrix3X2{T}"/> from the given <see cref="Matrix4X3{T}"/>.</summary>
/// <param name="value">The source <see cref="Matrix4X3{T}"/>.</param>
public Matrix3X2(Matrix4X3<T> value)
{
Row1 = new(value.M11, value.M12);
Row2 = new(value.M21, value.M22);
Row3 = new(value.M31, value.M32);
}
/// <summary>Constructs a <see cref="Matrix3X2{T}"/> from the given <see cref="Matrix3X4{T}"/>.</summary>
/// <param name="value">The source <see cref="Matrix3X4{T}"/>.</param>
public Matrix3X2(Matrix3X4<T> value)
{
Row1 = new(value.M11, value.M12);
Row2 = new(value.M21, value.M22);
Row3 = new(value.M31, value.M32);
}
/// <summary>Constructs a <see cref="Matrix3X2{T}"/> from the given <see cref="Matrix3X3{T}"/>.</summary>
/// <param name="value">The source <see cref="Matrix3X3{T}"/>.</param>
public Matrix3X2(Matrix3X3<T> value)
{
Row1 = new(value.M11, value.M12);
Row2 = new(value.M21, value.M22);
Row3 = new(value.M31, value.M32);
}
/// <summary>Constructs a <see cref="Matrix3X2{T}"/> from the given <see cref="Matrix2X4{T}"/>.</summary>
/// <param name="value">The source <see cref="Matrix2X4{T}"/>.</param>
public Matrix3X2(Matrix2X4<T> value)
{
Row1 = new(value.M11, value.M12);
Row2 = new(value.M21, value.M22);
Row3 = Vector2D<T>.Zero;
}
/// <summary>Constructs a <see cref="Matrix3X2{T}"/> from the given <see cref="Matrix4X2{T}"/>.</summary>
/// <param name="value">The source <see cref="Matrix4X2{T}"/>.</param>
public Matrix3X2(Matrix4X2<T> value)
{
Row1 = new(value.M11, value.M12);
Row2 = new(value.M21, value.M22);
Row3 = new(value.M31, value.M32);
}
/// <summary>Returns the multiplicative identity matrix.</summary>
public static Matrix3X2<T> Identity => _identity;
/// <summary>Returns whether the matrix is the identity matrix.</summary>
[IgnoreDataMember]
public readonly bool IsIdentity => this == Identity;
/// <summary>Adds each matrix element in value1 with its corresponding element in value2.</summary>
/// <param name="value1">The first source matrix.</param>
/// <param name="value2">The second source matrix.</param>
/// <returns>The matrix containing the summed values.</returns>
public static Matrix3X2<T> operator +(Matrix3X2<T> value1, Matrix3X2<T> value2)
{
return new(value1.Row1 + value2.Row1, value1.Row2 + value2.Row2, value1.Row3 + value2.Row3);
}
/// <summary>Returns a boolean indicating whether the given matrices are equal.</summary>
/// <param name="value1">The first source matrix.</param>
/// <param name="value2">The second source matrix.</param>
/// <returns>True if the matrices are equal; False otherwise.</returns>
public static bool operator ==(Matrix3X2<T> value1, Matrix3X2<T> value2)
{
return (Scalar.Equal(value1.M11, value2.M11)
&& Scalar.Equal(value1.M22, value2.M22) // Check diagonal element first for early out
&& Scalar.Equal(value1.M12, value2.M12)
&& Scalar.Equal(value1.M21, value2.M21)
&& Scalar.Equal(value1.M31, value2.M31)
&& Scalar.Equal(value1.M32, value2.M32));
}
/// <summary>Returns a boolean indicating whether the given matrices are not equal.</summary>
/// <param name="value1">The first source matrix.</param>
/// <param name="value2">The second source matrix.</param>
/// <returns>True if the matrices are not equal; False if they are equal.</returns>
public static bool operator !=(Matrix3X2<T> value1, Matrix3X2<T> value2)
{
return (Scalar.NotEqual(value1.M11, value2.M11)
|| Scalar.NotEqual(value1.M22, value2.M22) // Check diagonal element first for early out
|| Scalar.NotEqual(value1.M12, value2.M12)
|| Scalar.NotEqual(value1.M21, value2.M21)
|| Scalar.NotEqual(value1.M31, value2.M31)
|| Scalar.NotEqual(value1.M32, value2.M32));
}
/// <summary>Multiplies a matrix by another matrix.</summary>
/// <param name="value1">The first source matrix.</param>
/// <param name="value2">The second source matrix.</param>
/// <returns>The result of the multiplication.</returns>
public static unsafe Matrix3X3<T> operator *(Matrix3X2<T> value1, Matrix2X3<T> value2)
{
return new(value1.M11 * value2.Row1 * value1.M12 * value2.Row2,
value1.M21 * value2.Row1 * value1.M22 * value2.Row2,
value1.M31 * value2.Row1 * value1.M32 * value2.Row2);
}
/// <summary>Multiplies a vector by a matrix.</summary>
/// <param name="value1">The vector.</param>
/// <param name="value2">The matrix.</param>
/// <returns>The result of the multiplication.</returns>
public static unsafe Vector2D<T> operator *(Vector3D<T> value1, Matrix3X2<T> value2)
{
return value1.X * value2.Row1 + value1.Y * value2.Row2 + value1.Z * value2.Row3;
}
/// <summary>Multiplies a matrix by another matrix.</summary>
/// <param name="value1">The first source matrix.</param>
/// <param name="value2">The second source matrix.</param>
/// <returns>The result of the multiplication.</returns>
public static unsafe Matrix3X2<T> operator *(Matrix3X2<T> value1, Matrix2X2<T> value2)
{
return new(
value1.M11 * value2.Row1 + value1.M12 * value2.Row2,
value1.M21 * value2.Row1 + value1.M22 * value2.Row2,
value1.M31 * value2.Row1 + value1.M32 * value2.Row2
);
}
/// <summary>Multiplies a matrix by another matrix.</summary>
/// <param name="value1">The first source matrix.</param>
/// <param name="value2">The second source matrix.</param>
/// <returns>The result of the multiplication.</returns>
public static unsafe Matrix3X2<T> operator *(Matrix3X3<T> value1, Matrix3X2<T> value2)
{
return new(
value1.M11 * value2.Row1 + value1.M12 * value2.Row2 + value1.M13 * value2.Row3,
value1.M21 * value2.Row1 + value1.M22 * value2.Row2 + value1.M33 * value2.Row3,
value1.M31 * value2.Row1 + value1.M32 * value2.Row2 + value1.M23 * value2.Row3
);
}
/// <summary>Scales all elements in a matrix by the given scalar factor.</summary>
/// <param name="value1">The source matrix.</param>
/// <param name="value2">The scaling value to use.</param>
/// <returns>The resulting matrix.</returns>
public static Matrix3X2<T> operator *(Matrix3X2<T> value1, T value2)
{
return new(value1.Row1 * value2, value1.Row2 * value2, value1.Row3 * value2);
}
/// <summary>Subtracts each matrix element in value2 from its corresponding element in value1.</summary>
/// <param name="value1">The first source matrix.</param>
/// <param name="value2">The second source matrix.</param>
/// <returns>The matrix containing the resulting values.</returns>
public static Matrix3X2<T> operator -(Matrix3X2<T> value1, Matrix3X2<T> value2)
{
return new(value1.Row1 - value2.Row1, value1.Row2 - value2.Row2, value1.Row3 - value2.Row3);
}
/// <summary>Negates the given matrix by multiplying all values by -1.</summary>
/// <param name="value">The source matrix.</param>
/// <returns>The negated matrix.</returns>
public static Matrix3X2<T> operator -(Matrix3X2<T> value)
{
return new(-value.Row1, -value.Row2, -value.Row3);
}
/// <summary>Returns a boolean indicating whether the given Object is equal to this matrix instance.</summary>
/// <param name="obj">The Object to compare against.</param>
/// <returns>True if the Object is equal to this matrix; False otherwise.</returns>
[MethodImpl((MethodImplOptions) 768)]
public override readonly bool Equals(object? obj)
=> (obj is Matrix3X2<T> other) && Equals(other);
/// <summary>Returns a boolean indicating whether the matrix is equal to the other given matrix.</summary>
/// <param name="other">The other matrix to test equality against.</param>
/// <returns>True if this matrix is equal to other; False otherwise.</returns>
public readonly bool Equals(Matrix3X2<T> other)
{
return this == other;
}
/// <summary>Calculates the determinant for this matrix.
/// The determinant is calculated by expanding the matrix with a third column whose values are (0,0,1).</summary>
/// <returns>The determinant.</returns>
public readonly T GetDeterminant()
{
// There isn't actually any such thing as a determinant for a non-square matrix,
// but this 3x2 type is really just an optimization of a 3x3 where we happen to
// know the rightmost column is always (0, 0, 1). So we expand to 3x3 format:
//
// [ M11, M12, 0 ]
// [ M21, M22, 0 ]
// [ M31, M32, 1 ]
//
// Sum the diagonal products:
// (M11 * M22 * 1) + (M12 * 0 * M31) + (0 * M21 * M32)
//
// Subtract the opposite diagonal products:
// (M31 * M22 * 0) + (M32 * 0 * M11) + (1 * M21 * M12)
//
// Collapse out the constants and oh look, this is just a 2x2 determinant!
return Scalar.Subtract(Scalar.Multiply(M11, M22), Scalar.Multiply(M21, M12));
}
/// <summary>Returns the hash code for this instance.</summary>
/// <returns>The hash code.</returns>
public override readonly int GetHashCode()
{
return HashCode.Combine(M11, M12, M21, M22, M31, M32);
}
/// <summary>Returns a String representing this matrix instance.</summary>
/// <returns>The string representation.</returns>
public override readonly string ToString()
{
return string.Format(CultureInfo.CurrentCulture, "{{ {{M11:{0} M12:{1}}} {{M21:{2} M22:{3}}} {{M31:{4} M32:{5}}} }}",
M11, M12,
M21, M22,
M31, M32);
}
/// <summary>
/// Converts a <see cref="Matrix3X2{T}"/> into one with a <typeparamref name="T"/> of <see cref="Half"/>
/// </summary>
/// <param name="from">The source matrix</param>
/// <returns>The <see cref="Half"/> matrix</returns>
public static explicit operator Matrix3X2<Half>(Matrix3X2<T> from)
=> new(
Scalar.As<T, Half>(from.M11), Scalar.As<T, Half>(from.M12),
Scalar.As<T, Half>(from.M21), Scalar.As<T, Half>(from.M22),
Scalar.As<T, Half>(from.M31), Scalar.As<T, Half>(from.M32)
);
/// <summary>
/// Converts a <see cref="Matrix3X2{T}"/> into one with a <typeparamref name="T"/> of <see cref="float"/>
/// </summary>
/// <param name="from">The source matrix</param>
/// <returns>The <see cref="float"/> matrix</returns>
public static explicit operator Matrix3X2<float>(Matrix3X2<T> from)
=> new(
Scalar.As<T, float>(from.M11), Scalar.As<T, float>(from.M12),
Scalar.As<T, float>(from.M21), Scalar.As<T, float>(from.M22),
Scalar.As<T, float>(from.M31), Scalar.As<T, float>(from.M32)
);
/// <summary>
/// Converts a <see cref="Matrix3X2{T}"/> into a <see cref="System.Numerics.Matrix3x2"/> one.
/// </summary>
/// <param name="from">The source matrix</param>
/// <returns>The <see cref="System.Numerics"/> matrix</returns>
public static explicit operator System.Numerics.Matrix3x2(Matrix3X2<T> from)
=> new(
Scalar.As<T, float>(from.M11), Scalar.As<T, float>(from.M12),
Scalar.As<T, float>(from.M21), Scalar.As<T, float>(from.M22),
Scalar.As<T, float>(from.M31), Scalar.As<T, float>(from.M32)
);
/// <summary>
/// Converts a <see cref="Matrix3X2{T}"/> into one with a <typeparamref name="T"/> of <see cref="double"/>
/// </summary>
/// <param name="from">The source matrix</param>
/// <returns>The <see cref="double"/> matrix</returns>
public static explicit operator Matrix3X2<double>(Matrix3X2<T> from)
=> new(
Scalar.As<T, double>(from.M11), Scalar.As<T, double>(from.M12),
Scalar.As<T, double>(from.M21), Scalar.As<T, double>(from.M22),
Scalar.As<T, double>(from.M31), Scalar.As<T, double>(from.M32)
);
/// <summary>
/// Converts a <see cref="Matrix3X2{T}"/> into one with a <typeparamref name="T"/> of <see cref="decimal"/>
/// </summary>
/// <param name="from">The source matrix</param>
/// <returns>The <see cref="decimal"/> matrix</returns>
public static explicit operator Matrix3X2<decimal>(Matrix3X2<T> from)
=> new(
Scalar.As<T, decimal>(from.M11), Scalar.As<T, decimal>(from.M12),
Scalar.As<T, decimal>(from.M21), Scalar.As<T, decimal>(from.M22),
Scalar.As<T, decimal>(from.M31), Scalar.As<T, decimal>(from.M32)
);
/// <summary>
/// Converts a <see cref="Matrix3X2{T}"/> into one with a <typeparamref name="T"/> of <see cref="sbyte"/>
/// </summary>
/// <param name="from">The source matrix</param>
/// <returns>The <see cref="sbyte"/> matrix</returns>
public static explicit operator Matrix3X2<sbyte>(Matrix3X2<T> from)
=> new(
Scalar.As<T, sbyte>(from.M11), Scalar.As<T, sbyte>(from.M12),
Scalar.As<T, sbyte>(from.M21), Scalar.As<T, sbyte>(from.M22),
Scalar.As<T, sbyte>(from.M31), Scalar.As<T, sbyte>(from.M32)
);
/// <summary>
/// Converts a <see cref="Matrix3X2{T}"/> into one with a <typeparamref name="T"/> of <see cref="byte"/>
/// </summary>
/// <param name="from">The source matrix</param>
/// <returns>The <see cref="byte"/> matrix</returns>
public static explicit operator Matrix3X2<byte>(Matrix3X2<T> from)
=> new(
Scalar.As<T, byte>(from.M11), Scalar.As<T, byte>(from.M12),
Scalar.As<T, byte>(from.M21), Scalar.As<T, byte>(from.M22),
Scalar.As<T, byte>(from.M31), Scalar.As<T, byte>(from.M32)
);
/// <summary>
/// Converts a <see cref="Matrix3X2{T}"/> into one with a <typeparamref name="T"/> of <see cref="ushort"/>
/// </summary>
/// <param name="from">The source matrix</param>
/// <returns>The <see cref="ushort"/> matrix</returns>
public static explicit operator Matrix3X2<ushort>(Matrix3X2<T> from)
=> new(
Scalar.As<T, ushort>(from.M11), Scalar.As<T, ushort>(from.M12),
Scalar.As<T, ushort>(from.M21), Scalar.As<T, ushort>(from.M22),
Scalar.As<T, ushort>(from.M31), Scalar.As<T, ushort>(from.M32)
);
/// <summary>
/// Converts a <see cref="Matrix3X2{T}"/> into one with a <typeparamref name="T"/> of <see cref="short"/>
/// </summary>
/// <param name="from">The source matrix</param>
/// <returns>The <see cref="short"/> matrix</returns>
public static explicit operator Matrix3X2<short>(Matrix3X2<T> from)
=> new(
Scalar.As<T, short>(from.M11), Scalar.As<T, short>(from.M12),
Scalar.As<T, short>(from.M21), Scalar.As<T, short>(from.M22),
Scalar.As<T, short>(from.M31), Scalar.As<T, short>(from.M32)
);
/// <summary>
/// Converts a <see cref="Matrix3X2{T}"/> into one with a <typeparamref name="T"/> of <see cref="uint"/>
/// </summary>
/// <param name="from">The source matrix</param>
/// <returns>The <see cref="uint"/> matrix</returns>
public static explicit operator Matrix3X2<uint>(Matrix3X2<T> from)
=> new(
Scalar.As<T, uint>(from.M11), Scalar.As<T, uint>(from.M12),
Scalar.As<T, uint>(from.M21), Scalar.As<T, uint>(from.M22),
Scalar.As<T, uint>(from.M31), Scalar.As<T, uint>(from.M32)
);
/// <summary>
/// Converts a <see cref="Matrix3X2{T}"/> into one with a <typeparamref name="T"/> of <see cref="int"/>
/// </summary>
/// <param name="from">The source matrix</param>
/// <returns>The <see cref="int"/> matrix</returns>
public static explicit operator Matrix3X2<int>(Matrix3X2<T> from)
=> new(
Scalar.As<T, int>(from.M11), Scalar.As<T, int>(from.M12),
Scalar.As<T, int>(from.M21), Scalar.As<T, int>(from.M22),
Scalar.As<T, int>(from.M31), Scalar.As<T, int>(from.M32)
);
/// <summary>
/// Converts a <see cref="Matrix3X2{T}"/> into one with a <typeparamref name="T"/> of <see cref="ulong"/>
/// </summary>
/// <param name="from">The source matrix</param>
/// <returns>The <see cref="ulong"/> matrix</returns>
public static explicit operator Matrix3X2<ulong>(Matrix3X2<T> from)
=> new(
Scalar.As<T, ulong>(from.M11), Scalar.As<T, ulong>(from.M12),
Scalar.As<T, ulong>(from.M21), Scalar.As<T, ulong>(from.M22),
Scalar.As<T, ulong>(from.M31), Scalar.As<T, ulong>(from.M32)
);
/// <summary>
/// Converts a <see cref="Matrix3X2{T}"/> into one with a <typeparamref name="T"/> of <see cref="long"/>
/// </summary>
/// <param name="from">The source matrix</param>
/// <returns>The <see cref="long"/> matrix</returns>
public static explicit operator Matrix3X2<long>(Matrix3X2<T> from)
=> new(
Scalar.As<T, long>(from.M11), Scalar.As<T, long>(from.M12),
Scalar.As<T, long>(from.M21), Scalar.As<T, long>(from.M22),
Scalar.As<T, long>(from.M31), Scalar.As<T, long>(from.M32)
);
/// <summary>
/// Returns this matrix casted to <typeparamref name="TOther"></typeparamref>
/// </summary>
/// <typeparam name="TOther">The type to cast to</typeparam>
/// <returns>The casted matrix</returns>
public Matrix3X2<TOther> As<TOther>() where TOther : unmanaged, IFormattable, IEquatable<TOther>, IComparable<TOther>
{
return new(Row1.As<TOther>(), Row2.As<TOther>(), Row3.As<TOther>());
}
}
}