Files
stgsharp/源代码/StgSharp/Vector/Matrix2x3.cs
T

108 lines
2.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Security.Cryptography.X509Certificates;
using System.Text;
namespace StgSharp.Math
{
[StructLayout(LayoutKind.Explicit)]
public struct Matrix2x3:IEquatable<Matrix2x3>
{
[FieldOffset(0)]
public Vec3D row1;
[FieldOffset(12)]
public Vec3D row2;
public Matrix2x3(Vec3D r1, Vec3D r2)
{
row1 = r1;
row2 = r2;
}
public Matrix2x3(
float r11, float r12, float r13,
float r21, float r22, float r23
)
{
row1 = new Vec3D(r11, r12, r13);
row2 = new Vec3D(r21, r22, r23);
}
public override bool Equals(object obj)
{
if (obj == null)
{
return false;
}
else if (obj.GetType() != typeof(Matrix2x3))
{
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}";
}
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
);
}
}
}