97 lines
2.2 KiB
C#
97 lines
2.2 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 matrix2x2Int:IEquatable<matrix2x2>
|
|
{
|
|
[FieldOffset(0)]
|
|
public vec2dInt row1;
|
|
[FieldOffset(8)]
|
|
public vec2dInt row2;
|
|
|
|
|
|
public matrix2x2Int(vec2d c0, vec2d c1)
|
|
{
|
|
row1 = c0;
|
|
row2 = c1;
|
|
}
|
|
|
|
public matrix2x2Int(
|
|
int a11,
|
|
int a12,
|
|
int a21,
|
|
int a22
|
|
)
|
|
{
|
|
row1 = new vec2dInt(a11, a12);
|
|
row2 = new vec2dInt(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 matrix2x2Int operator +(matrix2x2Int matrix1 , matrix2x2Int matrix2)
|
|
{
|
|
return new matrix2x2Int(
|
|
matrix1.row1 + matrix2.row1,
|
|
matrix1.row2 + matrix2.row2
|
|
);
|
|
}
|
|
|
|
public static matrix2x2Int operator -(matrix2x2Int matrix1, matrix2x2Int matrix2)
|
|
{
|
|
return new matrix2x2Int(
|
|
matrix1.row1 - matrix2.row1,
|
|
matrix1.row2 - matrix2.row2
|
|
);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|