using System; using System.Collections.Generic; using System.Runtime.InteropServices; using System.Text; namespace StgSharp.Math { [StructLayout(LayoutKind.Explicit)] public struct Array2x2:IEquatable { [FieldOffset(0)] public Vec2D row1; [FieldOffset(8)] public Vec2D row2; public Array2x2(Vec2D c0, Vec2D c1) { row1 = c0; row2 = c1; } public Array2x2( float a11, float a12, float a21, float a22 ) { row1 = new Vec2D(a11, a12); row2 = new Vec2D(a21, a22); } bool IEquatable.Equals(Array2x2 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(Array2x2)) { return false; } else { return this.Equals((Vec3D)obj); } } public static unsafe Array2x2 operator *(Array2x2 array1, Array2x2 array2) { float* p = &array1.row1.X; Vec2D colum1 = new Vec2D( *p , *(p + 2) ); Vec2D colum2 = new Vec2D( *(p + 1), *(p + 3) ); return new Array2x2( colum1 * array2.row1, colum2 * array2.row1, colum1 * array2.row2, colum2 * array2.row2 ); } public static Array2x2 operator +(Array2x2 array1, Array2x2 array2) { return new Array2x2( array1.row1 + array2.row1, array1.row2 + array2.row2 ); } public static Array2x2 operator -(Array2x2 array1, Array2x2 array2) { return new Array2x2( array1.row1 - array2.row1, array1.row2 - array2.row2 ); } } }