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

143 lines
3.6 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 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 array1, Matrix2x3 array2)
{
return new Matrix2x3(
array1.row1 + array2.row1,
array1.row2 + array2.row2
);
}
public static Matrix2x3 operator -(Matrix2x3 array1, Matrix2x3 array2)
{
return new Matrix2x3(
array1.row1 - array2.row1,
array1.row2 - array2.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
);
}
public static unsafe Matrix2x2 operator *(Matrix2x3 array1, Matrix3x2 array2)
{
float* p1 = &array1.row1.X;
float* p2 = &array2.row2.X;
Vec2D a11 = new Vec2D(*(p1 + 0), *(p1 + 1));
Vec2D a12 = new Vec2D(*(p1 + 2), 0);
Vec2D a21 = new Vec2D(*(p1 + 3), *(p1 + 4));
Vec2D a22 = new Vec2D(*(p1 + 5), 0);
Colum2D b11 = new Colum2D(*(p2 + 0), *(p2 + 2));
Colum2D b12 = new Colum2D(*(p2 + 1), *(p2 + 3));
Colum2D b21 = new Colum2D(*(p2 + 4), 0);
Colum2D b22 = new Colum2D(*(p2 + 5), 0);
var s1 = a21 + a22;
var s2 = s1 - a11;
var s3 = a11 - a21;
var s4 = a12 - s2;
var t1 = b12 - b11;
var t2 = b22 - t1;
var t3 = b22 - b12;
var t4 = t2 - b21;
var m1 = a11 * b11;
var m2 = a12 * b11;
var m3 = s4 * b22;
var m4 = a22 * t4;
var m5 = s1 * t1;
var m6 = s2 * t2;
var m7 = s3 * t3;
var u1 = m1 + m2;
var u2 = m1 + m6;
var u3 = u2 + m7;
var u4 = u2 + m5;
var u5 = u4 + m3;
var u6 = u3 - m4;
var u7 = u3 + m5;
return new Matrix2x2(
);
}
}
}