daily update on 20230807 by nitload youmu

This commit is contained in:
Nitload
2023-08-07 22:12:37 +08:00
parent 0601a6dcce
commit f9f339405e
16 changed files with 573 additions and 355 deletions
+106 -81
View File
@@ -3,102 +3,127 @@ using System.Runtime.InteropServices;
namespace StgSharp.Math
{
[StructLayout(LayoutKind.Explicit)]
public struct matrix2x3 : IEquatable<matrix2x3>
public class Matrix2x3
{
[FieldOffset(0)]
public Vec3d row1;
[FieldOffset(12)]
public Vec3d row2;
internal M128Map _map;
public matrix2x3(Vec3d r1, Vec3d r2)
{
row1 = r1;
row2 = r2;
}
internal IntPtr _colum0Ptr;
internal IntPtr _colum1Ptr;
internal IntPtr _colum2Ptr;
public matrix2x3(
float r11, float r12, float r13,
float r21, float r22, float r23
private bool _isTransposed;
private Matrix3x2 _transpose;
public Matrix2x3(
float a00, float a01, float a02,
float a10, float a11, float a12
)
{
row1 = new Vec3d(r11, r12, r13);
row2 = new Vec3d(r21, r22, r23);
_colum0Ptr = internalIO.load_internal(a00,a10,0,0);
_colum0Ptr = internalIO.load_internal(a01,a11,0,0);
_colum0Ptr = internalIO.load_internal(a02,a12,0,0);
_transpose = new Matrix3x2(this);
}
public override bool Equals(object obj)
internal Matrix2x3(
IntPtr colum0Ptr,
IntPtr colum1Ptr,
IntPtr colum2Ptr
)
{
if (obj == null)
_colum0Ptr = colum0Ptr;
_colum1Ptr = colum1Ptr;
_colum2Ptr = colum2Ptr;
_transpose = new Matrix3x2(this);
}
public Matrix2x3(Matrix3x2 transpose)
{
_transpose = transpose;
}
public unsafe Matrix3x2 Transpose(TransposeMode transposeMode)
{
if (_isTransposed)
{
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;
(*(M128*)_transpose._colum0Ptr).single_2 = (*(M128*)_colum2Ptr).single_0;
(*(M128*)_transpose._colum1Ptr).single_2 = (*(M128*)_colum2Ptr).single_1;
_isTransposed = true;
}
else if (obj.GetType() != typeof(matrix2x3))
switch (transposeMode)
{
return false;
case TransposeMode.New:
return new Matrix3x2(
_transpose._colum0Ptr,
_transpose._colum1Ptr
);
break;
case TransposeMode.Copy:
return _transpose;
break;
default:
throw new Exception();
break;
}
}
public static Matrix2x3 operator +(Matrix2x3 matrix1, Matrix2x3 matrix2)
{
return new Matrix2x3(
internalIO.addps_internal(matrix1._colum0Ptr,matrix2._colum0Ptr),
internalIO.addps_internal(matrix1._colum1Ptr,matrix2._colum1Ptr),
internalIO.addps_internal(matrix1._colum2Ptr,matrix2._colum2Ptr)
);
}
public static Matrix2x3 operator -(Matrix2x3 matrix1, Matrix2x3 matrix2)
{
return new Matrix2x3(
internalIO.subps_internal(matrix1._colum0Ptr, matrix2._colum0Ptr),
internalIO.subps_internal(matrix1._colum1Ptr, matrix2._colum1Ptr),
internalIO.subps_internal(matrix1._colum2Ptr, matrix2._colum2Ptr)
);
}
public static Matrix2x3 operator *(Matrix2x3 matrix, float value)
{
return new Matrix2x3(
internalIO.mulps_const_internal(matrix._colum0Ptr, value),
internalIO.mulps_const_internal(matrix._colum1Ptr, value),
internalIO.mulps_const_internal(matrix._colum2Ptr, value)
);
}
public static Matrix2x3 operator /(Matrix2x3 matrix, float value)
{
return new Matrix2x3(
internalIO.divps_const_internal(matrix._colum0Ptr, value),
internalIO.divps_const_internal(matrix._colum1Ptr, value),
internalIO.divps_const_internal(matrix._colum2Ptr, value)
);
}
~Matrix2x3()
{
if (_map == null)
{
internalIO.deinitM128_internal(_colum0Ptr);
internalIO.deinitM128_internal(_colum1Ptr);
internalIO.deinitM128_internal(_colum2Ptr);
}
else
{
return this.Equals((Vec3d)obj);
}
}
public override int GetHashCode()
{
return HashCode.Combine(row1, row2);
}
public override string ToString()
{
return $"{row1}\n{row2}";
}
bool IEquatable<matrix2x3>.Equals(matrix2x3 other)
{
if (this.GetHashCode() != other.GetHashCode())
{
return false;
}
else
{
return
this.row1 == other.row1
&& this.row2 == other.row2;
}
}
public static matrix2x3 operator +(matrix2x3 matrix1, matrix2x3 matrix2)
{
return new matrix2x3(
matrix1.row1 + matrix2.row1,
matrix1.row2 + matrix2.row2
);
}
public static matrix2x3 operator -(matrix2x3 matrix1, matrix2x3 matrix2)
{
return new matrix2x3(
matrix1.row1 - matrix2.row1,
matrix1.row2 - matrix2.row2
);
}
public static matrix2x3 operator *(matrix2x3 array, float x)
{
return new matrix2x3(
array.row1 * x,
array.row2 * x
);
}
public static matrix2x3 operator /(matrix2x3 array, float x)
{
return new matrix2x3(
array.row1 / x,
array.row2 / x
);
}
}
}