Daily update on 20230806 by nitload youmu
This commit is contained in:
@@ -3,139 +3,133 @@ using System.Runtime.InteropServices;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
public struct matrix3x3 : IEquatable<matrix3x3>
|
||||
public class Matrix3x3
|
||||
{
|
||||
[FieldOffset(0)]
|
||||
public Vec3d row1;
|
||||
[FieldOffset(12)]
|
||||
public Vec3d row2;
|
||||
[FieldOffset(24)]
|
||||
public Vec3d row3;
|
||||
internal M128Map map;
|
||||
|
||||
public matrix3x3(Vec3d r0, Vec3d r1, Vec3d r2)
|
||||
{
|
||||
row1 = r0;
|
||||
row2 = r1;
|
||||
row3 = r2;
|
||||
}
|
||||
internal IntPtr _colum0Ptr;
|
||||
internal IntPtr _colum1Ptr;
|
||||
internal IntPtr _colum2Ptr;
|
||||
|
||||
public matrix3x3(
|
||||
float a11, float a12, float a13,
|
||||
float a21, float a22, float a23,
|
||||
float a31, float a32, float a33
|
||||
private bool _isDisposed;
|
||||
private Matrix3x3 _transpose;
|
||||
|
||||
public Matrix3x3(
|
||||
float a00, float a01, float a02,
|
||||
float a10, float a11, float a12,
|
||||
float a20, float a21, float a22
|
||||
)
|
||||
{
|
||||
row1 = new Vec3d(a11, a12, a13);
|
||||
row2 = new Vec3d(a21, a22, a23);
|
||||
row3 = new Vec3d(a31, a32, a33);
|
||||
_colum0Ptr = internalIO.load_internal(a00,a10,a20,0);
|
||||
_colum1Ptr = internalIO.load_internal(a01,a11,a21,0);
|
||||
_colum2Ptr = internalIO.load_internal(a02,a12,a22,0);
|
||||
|
||||
_transpose = new Matrix3x3(this);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
internal Matrix3x3(Matrix3x3 transpose)
|
||||
{
|
||||
return HashCode.Combine(row1, row2, row3);
|
||||
_transpose = transpose;
|
||||
}
|
||||
|
||||
bool IEquatable<matrix3x3>.Equals(matrix3x3 other)
|
||||
internal Matrix3x3(
|
||||
IntPtr colum0Ptr,
|
||||
IntPtr colum1Ptr,
|
||||
IntPtr colum2Ptr
|
||||
)
|
||||
{
|
||||
if (this.GetHashCode() != other.GetHashCode())
|
||||
_colum0Ptr= colum0Ptr;
|
||||
_colum1Ptr= colum1Ptr;
|
||||
_colum2Ptr= colum2Ptr;
|
||||
|
||||
_transpose = new Matrix3x3(this);
|
||||
}
|
||||
|
||||
public unsafe Matrix3x3 Transpose(TransposeMode transposeMode)
|
||||
{
|
||||
if (!_isDisposed)
|
||||
{
|
||||
return false;
|
||||
(*(M128*)_transpose._colum0Ptr).single_0 = (*(M128*)_colum0Ptr).single_0;
|
||||
(*(M128*)_transpose._colum0Ptr).single_1 = (*(M128*)_colum1Ptr).single_0;
|
||||
(*(M128*)_transpose._colum0Ptr).single_2 = (*(M128*)_colum2Ptr).single_0;
|
||||
|
||||
(*(M128*)_transpose._colum1Ptr).single_0 = (*(M128*)_colum0Ptr).single_1;
|
||||
(*(M128*)_transpose._colum1Ptr).single_1 = (*(M128*)_colum1Ptr).single_1;
|
||||
(*(M128*)_transpose._colum1Ptr).single_2 = (*(M128*)_colum2Ptr).single_1;
|
||||
|
||||
(*(M128*)_transpose._colum2Ptr).single_0 = (*(M128*)_colum0Ptr).single_2;
|
||||
(*(M128*)_transpose._colum2Ptr).single_1 = (*(M128*)_colum1Ptr).single_2;
|
||||
(*(M128*)_transpose._colum2Ptr).single_2 = (*(M128*)_colum2Ptr).single_2;
|
||||
|
||||
_isDisposed = true;
|
||||
}
|
||||
else
|
||||
|
||||
switch (transposeMode)
|
||||
{
|
||||
return
|
||||
this.row1 == other.row1
|
||||
&& this.row2 == other.row2
|
||||
&& this.row3 == other.row3;
|
||||
case TransposeMode.New:
|
||||
return new Matrix3x3(
|
||||
internalIO.load_cpy_internal(_transpose._colum0Ptr),
|
||||
internalIO.load_cpy_internal(_transpose._colum1Ptr),
|
||||
internalIO.load_cpy_internal(_transpose._colum2Ptr)
|
||||
);
|
||||
break;
|
||||
case TransposeMode.Copy:
|
||||
return _transpose;
|
||||
break;
|
||||
default:
|
||||
throw new Exception();
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
public static Matrix3x3 operator +(Matrix3x3 matrix1, Matrix3x3 matrix2)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (obj.GetType() != typeof(matrix3x3))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.Equals((matrix3x3)obj);
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{row1}\n{row2}\n{row3}";
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static bool operator ==(matrix3x3 matrix1, matrix3x3 matrix2)
|
||||
{
|
||||
return matrix1.Equals(matrix2);
|
||||
}
|
||||
|
||||
public static bool operator !=(matrix3x3 matrix1, matrix3x3 matrix2)
|
||||
{
|
||||
return !matrix1.Equals(matrix2);
|
||||
}
|
||||
|
||||
public static matrix3x3 operator +(matrix3x3 matrix1, matrix3x3 matrix2)
|
||||
{
|
||||
return new matrix3x3(
|
||||
matrix1.row1.X + matrix2.row1.X,
|
||||
matrix1.row1.Y + matrix2.row1.Y,
|
||||
matrix1.row1.Z + matrix2.row1.Z,
|
||||
|
||||
matrix1.row2.X + matrix2.row2.X,
|
||||
matrix1.row2.Y + matrix2.row2.Y,
|
||||
matrix1.row2.Z + matrix2.row2.Z,
|
||||
|
||||
matrix1.row3.X + matrix2.row3.X,
|
||||
matrix1.row3.Y + matrix2.row3.Y,
|
||||
matrix1.row3.Z + matrix2.row3.Z
|
||||
return new Matrix3x3(
|
||||
internalIO.addps_internal(matrix1._colum0Ptr,matrix2._colum0Ptr),
|
||||
internalIO.addps_internal(matrix1._colum1Ptr,matrix2._colum1Ptr),
|
||||
internalIO.addps_internal(matrix1._colum2Ptr,matrix2._colum2Ptr)
|
||||
);
|
||||
}
|
||||
|
||||
public static matrix3x3 operator -(matrix3x3 matrix1, matrix3x3 matrix2)
|
||||
public static Matrix3x3 operator -(Matrix3x3 matrix1, Matrix3x3 matrix2)
|
||||
{
|
||||
return new matrix3x3(
|
||||
matrix1.row1.X - matrix2.row1.X,
|
||||
matrix1.row1.Y - matrix2.row1.Y,
|
||||
matrix1.row1.Z - matrix2.row1.Z,
|
||||
|
||||
matrix1.row2.X - matrix2.row2.X,
|
||||
matrix1.row2.Y - matrix2.row2.Y,
|
||||
matrix1.row2.Z - matrix2.row2.Z,
|
||||
|
||||
matrix1.row3.X - matrix2.row3.X,
|
||||
matrix1.row3.Y - matrix2.row3.Y,
|
||||
matrix1.row3.Z - matrix2.row3.Z
|
||||
return new Matrix3x3(
|
||||
internalIO.subps_internal(matrix1._colum0Ptr,matrix2._colum0Ptr),
|
||||
internalIO.subps_internal(matrix1._colum1Ptr,matrix2._colum1Ptr),
|
||||
internalIO.subps_internal(matrix1._colum2Ptr,matrix2._colum2Ptr)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static matrix3x3 operator *(matrix3x3 array, float x)
|
||||
public static Matrix3x3 operator *(Matrix3x3 matrix, float value)
|
||||
{
|
||||
return new matrix3x3(
|
||||
array.row1 * x,
|
||||
array.row2 * x,
|
||||
array.row3 * x
|
||||
return new Matrix3x3(
|
||||
internalIO.mulps_const_internal(matrix._colum0Ptr,value),
|
||||
internalIO.mulps_const_internal(matrix._colum1Ptr,value),
|
||||
internalIO.mulps_const_internal(matrix._colum2Ptr,value)
|
||||
);
|
||||
}
|
||||
|
||||
public static matrix3x3 operator /(matrix3x3 array, float x)
|
||||
public static Matrix3x3 operator /(Matrix3x3 matrix, float value)
|
||||
{
|
||||
return new matrix3x3(
|
||||
array.row1 / x,
|
||||
array.row2 / x,
|
||||
array.row3 / x
|
||||
return new Matrix3x3(
|
||||
internalIO.divps_const_internal(matrix._colum0Ptr, value),
|
||||
internalIO.divps_const_internal(matrix._colum1Ptr, value),
|
||||
internalIO.divps_const_internal(matrix._colum2Ptr, value)
|
||||
);
|
||||
}
|
||||
|
||||
~Matrix3x3()
|
||||
{
|
||||
if (map==null)
|
||||
{
|
||||
internalIO.deinitM128_internal(_colum0Ptr);
|
||||
internalIO.deinitM128_internal(_colum1Ptr);
|
||||
internalIO.deinitM128_internal(_colum2Ptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user