daily update on 2024.03.18 by itload youmu

This commit is contained in:
YoumuLiu
2024-03-19 02:41:04 +08:00
parent 15bf989285
commit 0c50c6282e
200 changed files with 7663 additions and 3455 deletions
+95 -61
View File
@@ -1,4 +1,34 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="matrix4x2.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@@ -8,13 +38,28 @@ namespace StgSharp.Math
{
[StructLayout(LayoutKind.Explicit, Size = (16 + 8) * sizeof(float) + sizeof(bool), Pack = 16)]
[StructLayout(LayoutKind.Explicit, Size = ((16 + 8) * sizeof(float)) + sizeof(bool), Pack = 16)]
public struct Matrix4x2
{
[FieldOffset(0)] internal Mat2 mat;
[FieldOffset(8 * sizeof(float))] internal Mat4 transpose;
[FieldOffset((16 + 8) * sizeof(float))] internal bool isTransposed;
internal Matrix4x2(Mat2 mat)
{
this.mat = mat;
}
internal Matrix4x2(
Vector4 c0,
Vector4 c1
)
{
mat.colum0 = c0;
mat.colum1 = c1;
}
public Matrix4x2(
float a00, float a01,
@@ -27,71 +72,82 @@ namespace StgSharp.Math
mat.colum1 = new Vector4(a01, a11, a21, a31);
}
internal Matrix4x2(
Vector4 c0,
Vector4 c1
)
{
mat.colum0 = c0;
mat.colum1 = c1;
}
internal Matrix4x2(Mat2 mat)
{
this.mat = mat;
}
public unsafe float this[int rowNum, int columNum]
{
get
{
if (rowNum > 3 || rowNum < 0)
if ((rowNum > 3) || (rowNum < 0))
{
throw new ArgumentOutOfRangeException(nameof(columNum));
}
if (columNum > 1 || columNum < 0)
if ((columNum > 1) || (columNum < 0))
{
throw new ArgumentOutOfRangeException(nameof(columNum));
}
InternalTranspose();
fixed (float* p = &this.transpose.m00)
{
ulong pbit = (ulong)p
+ (ulong)sizeof(Vector4) * (ulong)rowNum
+ (ulong)sizeof(float) * (ulong)columNum;
ulong pbit = ((ulong)p)
+ (((ulong)sizeof(Vector4)) * ((ulong)rowNum))
+ (((ulong)sizeof(float)) * ((ulong)columNum));
return *(float*)pbit;
}
}
set
{
if (rowNum > 3 || rowNum < 0)
if ((rowNum > 3) || (rowNum < 0))
{
throw new ArgumentOutOfRangeException(nameof(columNum));
}
if (columNum > 1 || columNum < 0)
if ((columNum > 1) || (columNum < 0))
{
throw new ArgumentOutOfRangeException(nameof(columNum));
}
InternalTranspose();
fixed (float* p = &this.transpose.m00)
{
ulong pbit = (ulong)p
+ (ulong)sizeof(Vector4) * (ulong)rowNum
+ (ulong)sizeof(float) * (ulong)columNum;
ulong pbit = ((ulong)p)
+ (((ulong)sizeof(Vector4)) * ((ulong)rowNum))
+ (((ulong)sizeof(float)) * ((ulong)columNum));
*(float*)pbit = value;
}
isTransposed = false;
}
}
public override int GetHashCode()
{
return HashCode.Combine(
mat.colum0.GetHashCode(),
mat.colum1.GetHashCode()
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe Matrix4x2 operator +(Matrix4x2 left, Matrix4x2 right)
internal unsafe void InternalTranspose()
{
if (!isTransposed)
{
fixed (Mat2* source = &this.mat)
{
fixed (Mat4* target = &this.transpose)
{
InternalIO.Transpose2to4_internal(source, target);
}
}
isTransposed = true;
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe Matrix4x2 operator -(Matrix4x2 left, Matrix4x2 right)
{
return new Matrix4x2(
left.mat.colum0 + right.mat.colum0,
left.mat.colum0 + right.mat.colum0
left.mat.colum0 - right.mat.colum0,
left.mat.colum0 - right.mat.colum0
);
}
@@ -104,24 +160,6 @@ namespace StgSharp.Math
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix4x2 operator /(Matrix4x2 mat, float value)
{
return new Matrix4x2(
mat.mat.colum0 / value,
mat.mat.colum1 / value
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe Matrix4x2 operator -(Matrix4x2 left, Matrix4x2 right)
{
return new Matrix4x2(
left.mat.colum0 - right.mat.colum0,
left.mat.colum0 - right.mat.colum0
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix4x2 operator *(Matrix4x2 left, Matrix2x2 right)
{
@@ -192,24 +230,20 @@ namespace StgSharp.Math
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal unsafe void InternalTranspose()
public static Matrix4x2 operator /(Matrix4x2 mat, float value)
{
if (!isTransposed)
{
fixed (Mat2* source = &this.mat)
fixed (Mat4* target = &this.transpose)
{
InternalIO.Transpose2to4_internal(source, target);
}
isTransposed = true;
}
return new Matrix4x2(
mat.mat.colum0 / value,
mat.mat.colum1 / value
);
}
public override int GetHashCode()
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe Matrix4x2 operator +(Matrix4x2 left, Matrix4x2 right)
{
return HashCode.Combine(
mat.colum0.GetHashCode(),
mat.colum1.GetHashCode()
return new Matrix4x2(
left.mat.colum0 + right.mat.colum0,
left.mat.colum0 + right.mat.colum0
);
}