Daily update on 20230806 by nitload youmu

This commit is contained in:
Nitload
2023-08-06 22:33:17 +08:00
parent b3785e35af
commit 0601a6dcce
39 changed files with 1387 additions and 856 deletions
+80 -61
View File
@@ -3,91 +3,110 @@ using System.Runtime.InteropServices;
namespace StgSharp.Math
{
[StructLayout(LayoutKind.Explicit)]
public struct matrix2x2 : IEquatable<matrix2x2>
public class Matrix2x2
{
[FieldOffset(0)]
public vec2d row1;
[FieldOffset(8)]
public vec2d row2;
internal M128Map _map;
internal IntPtr _colum0Ptr;
internal IntPtr _colum1Ptr;
public matrix2x2(vec2d c0, vec2d c1)
{
row1 = c0;
row2 = c1;
}
private bool _isTranpsed;
private Matrix2x2 _transpose;
public matrix2x2(
float a11,
float a12,
float a21,
float a22
public Matrix2x2(
float a00, float a01,
float a10, float a11
)
{
row1 = new vec2d(a11, a12);
row2 = new vec2d(a21, a22);
_colum0Ptr = internalIO.load_internal(a00, a10, 0, 0);
_colum0Ptr = internalIO.load_internal(a01, a11, 0, 0);
_transpose = new Matrix2x2(this);
}
bool IEquatable<matrix2x2>.Equals(matrix2x2 other)
internal Matrix2x2(
IntPtr colum0Ptr,
IntPtr colum1Ptr
)
{
if (this.GetHashCode() != other.GetHashCode())
_colum0Ptr = colum0Ptr;
_colum1Ptr = colum1Ptr;
}
internal Matrix2x2(Matrix2x2 transpose)
{
_transpose = transpose;
}
public unsafe Matrix2x2 Transpose(TransposeMode transposeMode)
{
if (_isTranpsed)
{
return false;
(*(M128*)_transpose._colum0Ptr).single_0 = (*(M128*)_colum0Ptr).single_0;
(*(M128*)_transpose._colum1Ptr).single_0 = (*(M128*)_colum0Ptr).single_1;
(*(M128*)_transpose._colum0Ptr).single_1 = (*(M128*)_colum1Ptr).single_0;
(*(M128*)_transpose._colum1Ptr).single_1 = (*(M128*)_colum1Ptr).single_1;
}
else
switch (transposeMode)
{
return
this.row1 == other.row1
&& this.row2 == other.row2;
case TransposeMode.New:
return new Matrix2x2(
internalIO.load_cpy_internal(_transpose._colum0Ptr),
internalIO.load_cpy_internal(_transpose._colum1Ptr)
);
break;
case TransposeMode.Copy:
return _transpose;
break;
default:
throw new Exception();
break;
}
}
public override bool Equals(object obj)
public static Matrix2x2 operator +(Matrix2x2 matrix1, Matrix2x2 matrix2)
{
if (obj == null)
{
return false;
}
else if (obj.GetType() != typeof(matrix2x2))
{
return false;
}
else
{
return this.Equals((Vec3d)obj);
}
}
public override int GetHashCode()
{
return HashCode.Combine(row1, row2);
}
public override string ToString()
{
return $"{row1}\n{row2}";
}
public static matrix2x2 operator +(matrix2x2 matrix1, matrix2x2 matrix2)
{
return new matrix2x2(
matrix1.row1 + matrix2.row1,
matrix1.row2 + matrix2.row2
return new Matrix2x2(
internalIO.addps_internal(matrix1._colum0Ptr, matrix2._colum0Ptr),
internalIO.addps_internal(matrix1._colum1Ptr, matrix2._colum1Ptr)
);
}
public static matrix2x2 operator -(matrix2x2 matrix1, matrix2x2 matrix2)
public static Matrix2x2 operator -(Matrix2x2 matrix1, Matrix2x2 matrix2)
{
return new matrix2x2(
matrix1.row1 - matrix2.row1,
matrix1.row2 - matrix2.row2
return new Matrix2x2(
internalIO.subps_internal(matrix1._colum0Ptr, matrix2._colum0Ptr),
internalIO.subps_internal(matrix1._colum1Ptr, matrix2._colum1Ptr)
);
}
public static Matrix2x2 operator *(Matrix2x2 matrix1, float value)
{
return new Matrix2x2(
internalIO.mulps_const_internal(matrix1._colum0Ptr, value),
internalIO.mulps_const_internal(matrix1._colum1Ptr, value)
);
}
public static Matrix2x2 operator /(Matrix2x2 matrix1, float value)
{
return new Matrix2x2(
internalIO.divps_const_internal(matrix1._colum0Ptr, value),
internalIO.divps_const_internal(matrix1._colum1Ptr, value)
);
}
~Matrix2x2()
{
if (_map == null)
{
internalIO.deinitM128_internal(_colum0Ptr);
internalIO.deinitM128_internal(_colum1Ptr);
}
}
}
}