daily update on 20230807 by nitload youmu
This commit is contained in:
@@ -3,92 +3,85 @@ using System.Runtime.InteropServices;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
public struct matrix3x2 : IEquatable<matrix3x2>
|
||||
public class Matrix3x2
|
||||
{
|
||||
[FieldOffset(0)]
|
||||
public vec2d row1;
|
||||
[FieldOffset(8)]
|
||||
public vec2d row2;
|
||||
[FieldOffset(16)]
|
||||
public vec2d row3;
|
||||
internal M128Map _map;
|
||||
|
||||
public matrix3x2(vec2d r1, vec2d r2, vec2d r3)
|
||||
{
|
||||
row1 = r1;
|
||||
row2 = r2;
|
||||
row3 = r3;
|
||||
}
|
||||
internal IntPtr _colum0Ptr;
|
||||
internal IntPtr _colum1Ptr;
|
||||
|
||||
public matrix3x2(
|
||||
float a11, float a12,
|
||||
float a21, float a22,
|
||||
float a31, float a32
|
||||
private bool _isTransposed;
|
||||
private Matrix2x3 _transpose;
|
||||
|
||||
public Matrix3x2(
|
||||
float a00,float a01,
|
||||
float a10,float a11,
|
||||
float a20,float a21
|
||||
)
|
||||
{
|
||||
row1 = new vec2d(a11, a12);
|
||||
row2 = new vec2d(a21, a22);
|
||||
row3 = new vec2d(a31, a32);
|
||||
_colum0Ptr = internalIO.load_internal(a00,a10,a20,0);
|
||||
_colum0Ptr = internalIO.load_internal(a01,a11,a21,0);
|
||||
|
||||
_transpose = new Matrix2x3(this);
|
||||
}
|
||||
|
||||
bool IEquatable<matrix3x2>.Equals(matrix3x2 other)
|
||||
internal Matrix3x2(
|
||||
IntPtr colum0Ptr,
|
||||
IntPtr colum1Ptr
|
||||
)
|
||||
{
|
||||
if (this.GetHashCode() != other.GetHashCode())
|
||||
_colum0Ptr = colum0Ptr;
|
||||
_colum1Ptr = colum1Ptr;
|
||||
|
||||
_transpose = new Matrix2x3(this);
|
||||
}
|
||||
|
||||
internal Matrix3x2(Matrix2x3 transpose)
|
||||
{
|
||||
_transpose = transpose;
|
||||
}
|
||||
|
||||
public unsafe Matrix2x3 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._colum2Ptr).single_0 = (*(M128*)_colum0Ptr).single_2;
|
||||
|
||||
(*(M128*)_transpose._colum0Ptr).single_1 = (*(M128*)_colum1Ptr).single_0;
|
||||
(*(M128*)_transpose._colum1Ptr).single_1 = (*(M128*)_colum1Ptr).single_1;
|
||||
(*(M128*)_transpose._colum2Ptr).single_1 = (*(M128*)_colum1Ptr).single_2;
|
||||
|
||||
_isTransposed = true;
|
||||
|
||||
}
|
||||
else
|
||||
switch (transposeMode)
|
||||
{
|
||||
return
|
||||
this.row1 == other.row1
|
||||
&& this.row2 == other.row2
|
||||
&& this.row3 == other.row3
|
||||
;
|
||||
case TransposeMode.New:
|
||||
return new Matrix2x3(
|
||||
_transpose._colum0Ptr,
|
||||
_transpose._colum0Ptr,
|
||||
_transpose._colum0Ptr
|
||||
);
|
||||
break;
|
||||
case TransposeMode.Copy:
|
||||
return _transpose;
|
||||
break;
|
||||
default:
|
||||
throw new Exception();
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
~Matrix3x2()
|
||||
{
|
||||
if (obj == null)
|
||||
if (_map==null)
|
||||
{
|
||||
return false;
|
||||
internalIO.deinitM128_internal(_colum0Ptr);
|
||||
internalIO.deinitM128_internal(_colum1Ptr);
|
||||
}
|
||||
else if (obj.GetType() != typeof(matrix3x2))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.Equals((matrix3x2)obj);
|
||||
}
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(row1, row2, row3);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{row1}\n{row2}\n{row3}";
|
||||
}
|
||||
|
||||
public static matrix3x2 operator +(matrix3x2 matrix1, matrix3x2 matrix2)
|
||||
{
|
||||
return new matrix3x2(
|
||||
matrix1.row1 + matrix2.row1,
|
||||
matrix1.row2 + matrix2.row2,
|
||||
matrix1.row3 + matrix2.row3
|
||||
);
|
||||
}
|
||||
|
||||
public static matrix3x2 operator -(matrix3x2 matrix1, matrix3x2 matrix2)
|
||||
{
|
||||
return new matrix3x2(
|
||||
matrix1.row1 - matrix2.row1,
|
||||
matrix1.row2 - matrix2.row2,
|
||||
matrix1.row3 - matrix2.row3
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user