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

86 lines
2.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
namespace StgSharp.Math
{
[StructLayout(LayoutKind.Explicit)]
public struct Array3x2:IEquatable<Array3x2>
{
[FieldOffset(0)]
public Vec2D row1;
[FieldOffset(8)]
public Vec2D row2;
[FieldOffset(16)]
public Vec2D row3;
public Array3x2(Vec2D r1,Vec2D r2,Vec2D r3)
{
row1= r1;
row2= r2;
row3= r3;
}
bool IEquatable<Array3x2>.Equals(Array3x2 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(Array3x2))
{
return false;
}
else
{
return this.Equals((Array3x2)obj);
}
}
public override int GetHashCode()
{
return HashCode.Combine(row1, row2, row3);
}
public override string ToString()
{
return $"{row1}\n{row2}\n{row3}";
}
public static unsafe Array3x3 operator *(Array3x2 array1, Array2x3 array2)
{
float* p1 = &array1.row1.X;
float* p2 = &array2.row2.X;
return new Array3x3(
*(p1 + 0) * *(p2 + 0) + *(p1 + 1) * *(p2 + 3),
*(p1 + 0) * *(p2 + 1) + *(p1 + 1) * *(p2 + 4),
*(p1 + 0) * *(p2 + 2) + *(p1 + 1) * *(p2 + 5),
*(p1 + 2) * *(p2 + 0) + *(p1 + 3) * *(p2 + 3),
*(p1 + 2) * *(p2 + 1) + *(p1 + 3) * *(p2 + 4),
*(p1 + 2) * *(p2 + 2) + *(p1 + 3) * *(p2 + 5),
*(p1 + 4) * *(p2 + 0) + *(p1 + 5) * *(p2 + 3),
*(p1 + 4) * *(p2 + 1) + *(p1 + 5) * *(p2 + 4),
*(p1 + 4) * *(p2 + 2) + *(p1 + 5) * *(p2 + 5)
);
}
}
}