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

98 lines
2.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
namespace StgSharp.Math
{
[StructLayout(LayoutKind.Explicit)]
public struct Matrix3x2:IEquatable<Matrix3x2>
{
[FieldOffset(0)]
public Vec2D row1;
[FieldOffset(8)]
public Vec2D row2;
[FieldOffset(16)]
public Vec2D row3;
public Matrix3x2(Vec2D r1,Vec2D r2,Vec2D r3)
{
row1= r1;
row2= r2;
row3= r3;
}
public Matrix3x2(
float a11, float a12,
float a21, float a22,
float a31, float a32
)
{
row1 = new Vec2D(a11, a12);
row2 = new Vec2D(a21, a22);
row3 = new Vec2D(a31, a32);
}
bool IEquatable<Matrix3x2>.Equals(Matrix3x2 other)
{
if (this.GetHashCode() != other.GetHashCode())
{
return false;
}
else
{
return
this.row1 == other.row1
&& this.row2 == other.row2
&& this.row3 == other.row3
;
}
}
public override bool Equals(object obj)
{
if (obj == null)
{
return false;
}
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
);
}
}
}