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

97 lines
2.1 KiB
C#

using System;
using System.Collections.Generic;
using System.IO.Compression;
using System.Runtime.InteropServices;
using System.Text;
namespace StgSharp.Math
{
[StructLayout(LayoutKind.Explicit)]
public struct Matrix2x2:IEquatable<Matrix2x2>
{
[FieldOffset(0)]
public Vec2D row1;
[FieldOffset(8)]
public Vec2D row2;
public Matrix2x2(Vec2D c0, Vec2D c1)
{
row1 = c0;
row2 = c1;
}
public Matrix2x2(
float a11,
float a12,
float a21,
float a22
)
{
row1 = new Vec2D(a11, a12);
row2 = new Vec2D(a21, a22);
}
bool IEquatable<Matrix2x2>.Equals(Matrix2x2 other)
{
if (this.GetHashCode() != other.GetHashCode())
{
return false;
}
else
{
return
this.row1 == other.row1
&& this.row2 == other.row2;
}
}
public override bool Equals(object obj)
{
if (obj == null)
{
return false;
}
else if (obj.GetType() != typeof(Matrix2x2))
{
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}";
}
public static Matrix2x2 operator +(Matrix2x2 matrix1 , Matrix2x2 matrix2)
{
return new Matrix2x2(
matrix1.row1 + matrix2.row1,
matrix1.row2 + matrix2.row2
);
}
public static Matrix2x2 operator -(Matrix2x2 matrix1, Matrix2x2 matrix2)
{
return new Matrix2x2(
matrix1.row1 - matrix2.row1,
matrix1.row2 - matrix2.row2
);
}
}
}