Merge from branch giga

This commit is contained in:
Nitload
2025-08-31 10:42:51 +08:00
parent 1fc687f7d0
commit 1a0ccdd8cb
1619 changed files with 2812 additions and 733136 deletions
@@ -31,6 +31,7 @@
using StgSharp.Graphics;
using StgSharp.Graphics.OpenGL;
using StgSharp.Graphics.ShaderEdit;
using StgSharp.HighPerformance;
using StgSharp.Mathematics;
using System;
@@ -155,9 +156,7 @@ namespace StgSharp.Graphics
public void SetViewDirection(Vec3 position, Vec3 target, Vec3 up)
{
Vec3 direction = position - target;
if ((position.reg == cameraAtt.colum3.reg) &&
(this.up == up) &&
(cameraAtt.colum2.reg == direction.reg)) {
if ((position.reg == cameraAtt.colum3.reg) && (this.up == up) && (cameraAtt.colum2.reg == direction.reg)) {
return;
}
if (direction.GetLength() == 0)
@@ -187,11 +186,7 @@ namespace StgSharp.Graphics
InternalYaw();
}
public void SetViewRange(
Radius fovRadius,
Vec2 size,
Vec2 offset,
(float front, float back) dephRange)
public void SetViewRange(Radius fovRadius, Vec2 size, Vec2 offset, (float front, float back) dephRange)
{
float
distance = _target.GetLength(),
@@ -260,6 +255,7 @@ namespace StgSharp.Graphics
internal void InternalPitch()
{
/*
_isLookAtAvailable = false;
Matrix32 partialCoord = new Matrix32(cameraAtt.colum1.vec, cameraAtt.colum2.vec);
@@ -272,10 +268,12 @@ namespace StgSharp.Graphics
rotationAtt.colum1.reg = partialCoord.colum0.reg;
rotationAtt.colum2.reg = partialCoord.colum1.reg;
rotationAtt.isTransposed = false;
/**/
}
internal void InternalRow()
{
/*
_isLookAtAvailable = false;
Matrix32 partialCoord = new Matrix32(cameraAtt.colum0.vec, cameraAtt.colum1.vec);
@@ -288,10 +286,12 @@ namespace StgSharp.Graphics
rotationAtt.colum0.reg = partialCoord.colum0.reg;
rotationAtt.colum1.reg = partialCoord.colum1.reg;
rotationAtt.isTransposed = false;
*/
}
internal void InternalYaw()
{
/*
_isLookAtAvailable = false;
Matrix32 partialCoord = new Matrix32(cameraAtt.colum0.vec, cameraAtt.colum2.vec);
@@ -303,6 +303,7 @@ namespace StgSharp.Graphics
rotationAtt.colum0.reg = partialCoord.colum0.reg;
rotationAtt.colum2.reg = partialCoord.colum1.reg;
rotationAtt.isTransposed = false;
*/
}
#endregion
+165 -21
View File
@@ -29,47 +29,191 @@
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
using StgSharp.HighPerformance;
using StgSharp.HighPerformance.Memory;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using hlsfHandle = StgSharp.HighPerformance.Memory.HybridLayerSegregatedFitAllocationHandle;
using hlsfAllocator = global::StgSharp.HighPerformance.Memory.HybridLayerSegregatedFitAllocator;
using hlsfHandle = global::StgSharp.HighPerformance.Memory.HybridLayerSegregatedFitAllocationHandle;
namespace StgSharp.Mathematics
{
public abstract unsafe partial class Matrix<T> where T: unmanaged, INumber<T>
{
public abstract ref float this[int column, int row]
private protected readonly int t_count = 16 / sizeof(T);
private protected readonly int t_size = sizeof(T);
private protected Matrix() { }
public abstract ref T this[int column, int row]
{
get;
}
public abstract MatrixKernel* GetMatrixKernel(int column, int row);
public abstract unsafe Matrix<T> this[ReadOnlySpan<MatrixIndex> column, ReadOnlySpan<MatrixIndex> row]
{
get;
set;
}
public static hlsfAllocator? DefaultAllocator
{
get
{
ArgumentNullException.ThrowIfNull(field, nameof(DefaultAllocator));
return null;
}
set;
} = null;
public int ColumnLength { get; init; }
public int RowLength { get; init; }
public static MatrixAllocation DefaultAllocation { get; set; } = MatrixAllocation.GC;
protected int KernelColumnLength { get; init; }
protected int KernelRowLength { get; init; }
public static Matrix<T> FromDefault(int columnLength, int rowLength)
{
return DefaultAllocation switch
{
MatrixAllocation.GC => FromGC(columnLength, rowLength),
MatrixAllocation.HLSF => FromHlsf(columnLength, rowLength, DefaultAllocator!),
_ => throw new NotSupportedException("This allocation is not supported."),
};
}
public static Matrix<T> FromGC(int columnLength, int rowLength)
{
return new GCMatrix<T>(columnLength, rowLength);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix<T> FromHlsf(int columnLength, int rowLength, hlsfAllocator allocator)
{
return new HlsfMatrix<T>(columnLength, rowLength, allocator);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public abstract MatrixSegmentEnumeration GetColumnEnumeration();
public abstract ref MatrixKernel GetMatrixKernel(int column, int row);
public abstract MatrixSegmentEnumeration GetRowEnumeration();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public abstract MatrixSegmentEnumeration GetSequentialEnumeration();
[Obsolete("This method does not contain boarder check, so be careful on size or use indexer instead.", false)]
public abstract T* UnsafeIndex(int column, int row);
public abstract ref T UnsafeIndex(int column, int row);
}
private unsafe class HlsfMatrix<T> : Matrix<T> where T : unmanaged, INumber<T>
{
public override ref float this[int column, int row] => throw new NotImplementedException();
public override unsafe MatrixKernel* GetMatrixKernel(int column, int row)
private protected void AssertIndex(int column, int row)
{
throw new NotImplementedException();
if (column < 0 || column >= ColumnLength) {
throw new ArgumentOutOfRangeException(nameof(column));
}
if (row < 0 || row >= RowLength) {
throw new ArgumentOutOfRangeException(nameof(row));
}
}
public override unsafe T* UnsafeIndex(int column, int row)
public readonly unsafe ref struct MatrixSegmentEnumeration(
MatrixKernel* source,
int stride,
int size,
int secondaryStride,
int secondarySize)
{
throw new NotImplementedException();
private readonly MatrixKernel* _source = source;
private readonly int _secondarySize = secondarySize;
private readonly int _secondaryStride = secondaryStride;
private readonly int _size = size;
private readonly int _stride = stride;
public Enumerator GetEnumerator()
{
return new Enumerator(in this);
}
public ref struct Enumerator(in MatrixSegmentEnumeration enumeration)
{
private MatrixKernel* _current = enumeration._source - enumeration._stride;
private readonly MatrixKernel* _end = enumeration._source + enumeration._size;
private readonly int _secondarySize = enumeration._secondarySize;
private readonly int _secondaryStride = enumeration._secondaryStride;
private readonly int _stride = enumeration._stride;
public readonly Segment Current
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => new(_current, _secondarySize, _secondaryStride);
}
public bool MoveNext()
{
_current += _stride;
return _current < _end;
}
}
}
public readonly unsafe ref struct Segment(MatrixKernel* source, int size, int stride)
{
private readonly MatrixKernel* _source = source;
private readonly int _size = size;
private readonly int _stride = stride;
public ref MatrixKernel this[int index]
{
get
{
if (index < 0 || index >= _size) {
throw new ArgumentOutOfRangeException(nameof(index));
}
return ref _source[index * _stride];
}
}
public Enumerator GetEnumerator()
{
return new Enumerator(_source, _size, _stride);
}
public ref struct Enumerator(MatrixKernel* source, int count, int stride)
{
private readonly MatrixKernel* _end = source + (count * stride);
private readonly int _stride = stride;
public MatrixKernel* Current
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private set;
} = source - stride;
public bool MoveNext()
{
Current += _stride;
return Current < _end;
}
}
}
}
}
@@ -1,177 +0,0 @@
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// file="Matrix22.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 StgSharp.Internal.Intrinsic;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace StgSharp.Mathematics
{
[StructLayout(LayoutKind.Explicit, Size = (2 * 2 * 4 * sizeof(float)) + sizeof(bool), Pack = 16)]
public struct Matrix22 : IMatrix<Matrix22>
{
[FieldOffset(2 * 2 * 4 * sizeof(float))]
internal bool isTransposed = false;
[FieldOffset(0)]
internal ColumnSet2 _mat;
[FieldOffset(2 * 4 * sizeof(float))]
internal ColumnSet2 _transpose;
internal Matrix22(ColumnSet2 mat)
{
this._mat = mat;
}
internal Matrix22(Vector4 c0, Vector4 c1)
{
Unsafe.SkipInit(out this);
isTransposed = false;
_mat.colum0 = c0;
_mat.colum1 = c1;
}
public Matrix22()
{
Unsafe.SkipInit(out this);
isTransposed = false;
}
public Matrix22(float a00, float a01, float a10, float a11)
{
Unsafe.SkipInit(out this);
isTransposed = false;
_mat.colum0 = new Vector4(a00, a10, 0, 0);
_mat.colum1 = new Vector4(a01, a11, 0, 0);
}
public Matrix22 Transpose
{
get
{
InternalTranspose();
return new Matrix22(this._transpose);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public float Det()
{
return (_mat.m00 * _mat.m11) - (_mat.m10 * _mat.m01);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void InternalTranspose()
{
if (!isTransposed)
{
_transpose = _mat;
float cache = _transpose.m10;
_transpose.m10 = _transpose.m01;
_transpose.m01 = cache;
isTransposed = true;
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe Matrix22 operator -(Matrix22 left, Matrix22 right)
{
Matrix22 ret = new Matrix22();
InternalIO.Intrinsic.sub_mat_2(&left._mat, &right._mat, &ret._mat);
return ret;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix22 operator *(Matrix22 mat, float value)
{
return new Matrix22(mat._mat.colum0 * value, mat._mat.colum1 * value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix22 operator *(Matrix22 left, Matrix22 right)
{
left.InternalTranspose();
return new Matrix22(
Vector4.Dot(left._transpose.colum0, right._mat.colum0),
Vector4.Dot(left._transpose.colum0, right._mat.colum1),
Vector4.Dot(left._transpose.colum1, right._mat.colum0),
Vector4.Dot(left._transpose.colum1, right._mat.colum1));
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix23 operator *(Matrix22 left, Matrix23 right)
{
left.InternalTranspose();
return new Matrix23(
Vector4.Dot(left._transpose.colum0, right._mat.colum0),
Vector4.Dot(left._transpose.colum0, right._mat.colum1),
Vector4.Dot(left._transpose.colum0, right._mat.colum2),
Vector4.Dot(left._transpose.colum1, right._mat.colum0),
Vector4.Dot(left._transpose.colum1, right._mat.colum1),
Vector4.Dot(left._transpose.colum1, right._mat.colum2));
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix24 operator *(Matrix22 left, Matrix24 right)
{
left.InternalTranspose();
return new Matrix24(
Vector4.Dot(left._transpose.colum0, right.mat.colum0),
Vector4.Dot(left._transpose.colum0, right.mat.colum1),
Vector4.Dot(left._transpose.colum0, right.mat.colum2),
Vector4.Dot(left._transpose.colum0, right.mat.colum3),
Vector4.Dot(left._transpose.colum1, right.mat.colum0),
Vector4.Dot(left._transpose.colum1, right.mat.colum1),
Vector4.Dot(left._transpose.colum1, right.mat.colum2),
Vector4.Dot(left._transpose.colum1, right.mat.colum3));
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix22 operator /(Matrix22 mat, float value)
{
return new Matrix22(mat._mat.colum0 / value, mat._mat.colum1 / value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe Matrix22 operator +(Matrix22 left, Matrix22 right)
{
Matrix22 ret = new Matrix22();
InternalIO.Intrinsic.add_mat_2(&left._mat, &right._mat, &ret._mat);
return ret;
}
}
}
@@ -1,195 +0,0 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Matrix23.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 StgSharp.Internal.Intrinsic;
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace StgSharp.Mathematics
{
[StructLayout(
LayoutKind.Explicit,
Size = ( ( 3 + 2 ) * 4 * sizeof( float ) ) + sizeof( bool ),
Pack = 16 )]
public struct Matrix23 : IMatrix<Matrix23>
{
[FieldOffset( 5 * 4 * sizeof( float ) )] internal bool isTransposed = false;
[FieldOffset( 3 * 4 * sizeof( float ) )] internal ColumnSet2 _transpose;
[FieldOffset( 0 )] internal ColumnSet3 _mat;
internal Matrix23( Vector4 c0, Vector4 c1, Vector4 c2 )
{
_mat.colum0 = c0;
_mat.colum1 = c1;
_mat.colum2 = c2;
}
public Matrix23()
{
Unsafe.SkipInit( out _mat );
Unsafe.SkipInit( out _transpose );
}
public Matrix23( float a00, float a01, float a02, float a10, float a11, float a12 )
{
_mat.colum0 = new Vector4( a00, a10, 0, 0 );
_mat.colum1 = new Vector4( a01, a11, 0, 0 );
_mat.colum2 = new Vector4( a02, a12, 0, 0 );
}
public unsafe float this[ int rowNum, int columNum ]
{
get
{
if( ( rowNum > 1 ) || ( rowNum < 0 ) ) {
throw new ArgumentOutOfRangeException( nameof( columNum ) );
}
if( ( columNum > 2 ) || ( 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 ) );
return *( float* )pbit;
}
}
set
{
if( ( rowNum > 1 ) || ( rowNum < 0 ) ) {
throw new ArgumentOutOfRangeException( nameof( columNum ) );
}
if( ( columNum > 2 ) || ( 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 ) );
*( float* )pbit = value;
}
isTransposed = false;
}
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
internal unsafe void InternalTranspose()
{
if( !isTransposed )
{
fixed( ColumnSet3* source = &this._mat )
{
fixed( ColumnSet2* target = &this._transpose ) {
InternalIO.Intrinsic.transpose32( source, target );
}
}
isTransposed = true;
}
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static unsafe Matrix23 operator -( Matrix23 left, Matrix23 right )
{
Matrix23 ret = new Matrix23();
InternalIO.Intrinsic.sub_mat_3( &left._mat, &right._mat, &ret._mat );
return ret;
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static Matrix23 operator *( Matrix23 mat, float value )
{
return new Matrix23(
mat._mat.colum0 * value, mat._mat.colum1 * value, mat._mat.colum2 * value );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static Matrix22 operator *( Matrix23 left, Matrix32 right )
{
left.InternalTranspose();
return new Matrix22(
Vector4.Dot( left._transpose.colum0, right.mat.colum0 ),
Vector4.Dot( left._transpose.colum0, right.mat.colum1 ),
Vector4.Dot( left._transpose.colum0, right.mat.colum0 ),
Vector4.Dot( left._transpose.colum0, right.mat.colum1 ) );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static Matrix23 operator *( Matrix23 left, Matrix33 right )
{
left.InternalTranspose();
return new Matrix23(
Vector4.Dot( left._transpose.colum0, right.mat.colum0 ),
Vector4.Dot( left._transpose.colum0, right.mat.colum1 ),
Vector4.Dot( left._transpose.colum0, right.mat.colum2 ),
Vector4.Dot( left._transpose.colum0, right.mat.colum0 ),
Vector4.Dot( left._transpose.colum0, right.mat.colum1 ),
Vector4.Dot( left._transpose.colum0, right.mat.colum2 ) );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static Matrix24 operator *( Matrix23 left, Matrix34 right )
{
left.InternalTranspose();
return new Matrix24(
Vector4.Dot( left._transpose.colum0, right.mat.colum0 ),
Vector4.Dot( left._transpose.colum0, right.mat.colum1 ),
Vector4.Dot( left._transpose.colum0, right.mat.colum2 ),
Vector4.Dot( left._transpose.colum0, right.mat.colum3 ),
Vector4.Dot( left._transpose.colum0, right.mat.colum0 ),
Vector4.Dot( left._transpose.colum0, right.mat.colum1 ),
Vector4.Dot( left._transpose.colum0, right.mat.colum2 ),
Vector4.Dot( left._transpose.colum0, right.mat.colum3 ) );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static Matrix23 operator /( Matrix23 mat, float value )
{
return new Matrix23(
mat._mat.colum0 / value, mat._mat.colum1 / value, mat._mat.colum2 / value );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static unsafe Matrix23 operator +( Matrix23 left, Matrix23 right )
{
Matrix23 ret = new Matrix23();
InternalIO.Intrinsic.add_mat_3( &left._mat, &right._mat, &ret._mat );
return ret;
}
}
}
@@ -1,223 +0,0 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Matrix24.cs"
// Project: World
// 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 StgSharp.Internal.Intrinsic;
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace StgSharp.Mathematics
{
[StructLayout(
LayoutKind.Explicit,
Size = ( ( 4 + 2 ) * 4 * sizeof( float ) ) + sizeof( bool ),
Pack = 16 )]
public struct Matrix24 : IMatrix<Matrix24>
{
[FieldOffset( 6 * 4 * sizeof( float ) )] internal bool isTransposed;
[FieldOffset( 4 * 4 * sizeof( float ) )] internal ColumnSet2 transpose;
[FieldOffset( 0 )] internal ColumnSet4 mat;
[FieldOffset( 0 )] public Vec2 Colum0;
[FieldOffset( 16 )] public Vec2 Colum1;
[FieldOffset( 32 )] public Vec2 Colum2;
[FieldOffset( 48 )] public Vec2 Colum3;
internal Matrix24( Vector4 c0, Vector4 c1, Vector4 c2, Vector4 c3 )
{
Unsafe.SkipInit( out this );
isTransposed = false;
mat.colum0 = c0;
mat.colum1 = c1;
mat.colum2 = c2;
mat.colum3 = c3;
}
public Matrix24()
{
Unsafe.SkipInit( out this );
isTransposed = false;
}
public Matrix24(
float a00,
float a01,
float a02,
float a03,
float a10,
float a11,
float a12,
float a13 )
{
Unsafe.SkipInit( out this );
isTransposed = false;
mat.colum0 = new Vector4( a00, a10, 0, 0 );
mat.colum1 = new Vector4( a01, a11, 0, 0 );
mat.colum2 = new Vector4( a02, a12, 0, 0 );
mat.colum3 = new Vector4( a03, a13, 0, 0 );
}
public unsafe float this[ int rowNum, int columNum ]
{
get
{
if( ( rowNum > 1 ) || ( rowNum < 0 ) ) {
throw new ArgumentOutOfRangeException( nameof( columNum ) );
}
if( ( columNum > 3 ) || ( 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 ) );
return *( float* )pbit;
}
}
set
{
if( ( rowNum > 1 ) || ( rowNum < 0 ) ) {
throw new ArgumentOutOfRangeException( nameof( columNum ) );
}
if( ( columNum > 3 ) || ( 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 ) );
*( float* )pbit = value;
}
isTransposed = false;
}
}
public override string ToString()
{
InternalTranspose();
return $"{$"[{mat.m00},{mat.m01},{mat.m02},{mat.m03}],"}{$"[{mat.m10},{mat.m11},{mat.m12},{mat.m13}]"}";
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
internal unsafe void InternalTranspose()
{
if( !isTransposed ) {
fixed( ColumnSet4* source = &this.mat ) {
fixed( ColumnSet2* target = &this.transpose ) {
InternalIO.Intrinsic.transpose42( source, target );
}
}
isTransposed = true;
}
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static unsafe Matrix24 operator -(
Matrix24 left,
Matrix24 right )
{
Matrix24 ret = new Matrix24();
InternalIO.Intrinsic.sub_mat_4( &left.mat, &right.mat, &ret.mat );
return ret;
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static Matrix24 operator *( Matrix24 mat, float value )
{
return new Matrix24(
mat.mat.colum0 * value, mat.mat.colum1 * value,
mat.mat.colum2 * value, mat.mat.colum3 * value );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static Matrix22 operator *( Matrix24 left, Matrix42 right )
{
left.InternalTranspose();
return new Matrix22(
Vector4.Dot( left.transpose.colum0, right.mat.colum0 ),
Vector4.Dot( left.transpose.colum0, right.mat.colum1 ),
Vector4.Dot( left.transpose.colum1, right.mat.colum0 ),
Vector4.Dot( left.transpose.colum1, right.mat.colum1 ) );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static Matrix23 operator *( Matrix24 left, Matrix43 right )
{
left.InternalTranspose();
return new Matrix23(
Vector4.Dot( left.transpose.colum0, right.mat.colum0 ),
Vector4.Dot( left.transpose.colum0, right.mat.colum1 ),
Vector4.Dot( left.transpose.colum0, right.mat.colum2 ),
Vector4.Dot( left.transpose.colum1, right.mat.colum0 ),
Vector4.Dot( left.transpose.colum1, right.mat.colum1 ),
Vector4.Dot( left.transpose.colum1, right.mat.colum2 ) );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static Matrix24 operator *( Matrix24 left, Matrix44 right )
{
left.InternalTranspose();
return new Matrix24(
Vector4.Dot( left.transpose.colum0, right.mat.colum0 ),
Vector4.Dot( left.transpose.colum0, right.mat.colum1 ),
Vector4.Dot( left.transpose.colum0, right.mat.colum2 ),
Vector4.Dot( left.transpose.colum0, right.mat.colum3 ),
Vector4.Dot( left.transpose.colum1, right.mat.colum0 ),
Vector4.Dot( left.transpose.colum1, right.mat.colum1 ),
Vector4.Dot( left.transpose.colum1, right.mat.colum2 ),
Vector4.Dot( left.transpose.colum1, right.mat.colum3 ) );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static Matrix24 operator /( Matrix24 mat, float value )
{
return new Matrix24(
mat.mat.colum0 / value, mat.mat.colum1 / value,
mat.mat.colum2 / value, mat.mat.colum3 / value );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static unsafe Matrix24 operator +(
Matrix24 left,
Matrix24 right )
{
Matrix24 ret = new Matrix24();
InternalIO.Intrinsic.add_mat_4( &left.mat, &right.mat, &ret.mat );
return ret;
}
}
}
@@ -1,215 +0,0 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Matrix32.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 StgSharp.Internal.Intrinsic;
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace StgSharp.Mathematics
{
[StructLayout(
LayoutKind.Explicit,
Size = ( 5 * 4 * sizeof( float ) ) + sizeof( bool ),
Pack = 16 )]
public struct Matrix32 : IMatrix<Matrix32>
{
[FieldOffset( 5 * 4 * sizeof( float ) )] internal bool isTransposed;
[FieldOffset( 0 )] internal ColumnSet2 mat;
[FieldOffset( 2 * 4 * sizeof( float ) )] internal ColumnSet3 transpose;
[FieldOffset( 0 )] internal Vec3 colum0;
[FieldOffset( 4 * 4 )] internal Vec3 colum1;
internal Matrix32( Vector4 c0, Vector4 c1 )
{
Unsafe.SkipInit( out this );
isTransposed = false;
mat.colum0 = c0;
mat.colum1 = c1;
}
public Matrix32()
{
Unsafe.SkipInit( out this );
isTransposed = false;
}
public unsafe Matrix32( float a00, float a01, float a10, float a11, float a20, float a21 )
{
Unsafe.SkipInit( out this );
isTransposed = false;
mat.colum0 = new Vector4( a00, a10, a20, 0 );
mat.colum1 = new Vector4( a01, a11, a21, 0 );
}
public unsafe float this[ int rowNum, int columNum ]
{
get
{
if( ( rowNum > 2 ) || ( rowNum < 0 ) ) {
throw new ArgumentOutOfRangeException( nameof( columNum ) );
}
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 ) );
return *( float* )pbit;
}
}
set
{
if( ( rowNum > 2 ) || ( rowNum < 0 ) ) {
throw new ArgumentOutOfRangeException( nameof( columNum ) );
}
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 ) );
*( float* )pbit = value;
}
isTransposed = false;
}
}
public Vec3 VerticalVecMultiply( Vec2 vec )
{
return ( colum0 * vec.X ) + ( colum1 * vec.Y );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
internal unsafe void InternalTranspose()
{
if( !isTransposed )
{
fixed( ColumnSet2* source = &this.mat )
{
fixed( ColumnSet3* target = &this.transpose ) {
InternalIO.Intrinsic.transpose23( source, target );
}
}
isTransposed = true;
}
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static Matrix32 operator -( Matrix32 left, Matrix32 right )
{
return new Matrix32(
left.mat.colum0 - right.mat.colum0, left.mat.colum1 - right.mat.colum1 );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static Matrix32 operator *( Matrix32 mat, float value )
{
return new Matrix32( mat.mat.colum0 * value, mat.mat.colum1 * value );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static Matrix32 operator *( Matrix32 left, Matrix22 right )
{
left.InternalTranspose();
return new Matrix32(
Vector4.Dot( left.transpose.colum0, right._mat.colum0 ),
Vector4.Dot( left.transpose.colum0, right._mat.colum1 ),
Vector4.Dot( left.transpose.colum1, right._mat.colum0 ),
Vector4.Dot( left.transpose.colum1, right._mat.colum1 ),
Vector4.Dot( left.transpose.colum2, right._mat.colum0 ),
Vector4.Dot( left.transpose.colum2, right._mat.colum1 ) );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static Matrix33 operator *( Matrix32 left, Matrix23 right )
{
left.InternalTranspose();
return new Matrix33(
Vector4.Dot( left.transpose.colum0, right._mat.colum0 ),
Vector4.Dot( left.transpose.colum0, right._mat.colum1 ),
Vector4.Dot( left.transpose.colum0, right._mat.colum2 ),
Vector4.Dot( left.transpose.colum1, right._mat.colum0 ),
Vector4.Dot( left.transpose.colum1, right._mat.colum1 ),
Vector4.Dot( left.transpose.colum1, right._mat.colum2 ),
Vector4.Dot( left.transpose.colum2, right._mat.colum0 ),
Vector4.Dot( left.transpose.colum2, right._mat.colum1 ),
Vector4.Dot( left.transpose.colum2, right._mat.colum2 ) );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static Matrix34 operator *( Matrix32 left, Matrix24 right )
{
left.InternalTranspose();
return new Matrix34(
Vector4.Dot( left.transpose.colum0, right.mat.colum0 ),
Vector4.Dot( left.transpose.colum0, right.mat.colum1 ),
Vector4.Dot( left.transpose.colum0, right.mat.colum2 ),
Vector4.Dot( left.transpose.colum0, right.mat.colum3 ),
Vector4.Dot( left.transpose.colum1, right.mat.colum0 ),
Vector4.Dot( left.transpose.colum1, right.mat.colum1 ),
Vector4.Dot( left.transpose.colum1, right.mat.colum2 ),
Vector4.Dot( left.transpose.colum1, right.mat.colum3 ),
Vector4.Dot( left.transpose.colum2, right.mat.colum0 ),
Vector4.Dot( left.transpose.colum2, right.mat.colum1 ),
Vector4.Dot( left.transpose.colum2, right.mat.colum2 ),
Vector4.Dot( left.transpose.colum2, right.mat.colum3 ) );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static Matrix32 operator /( Matrix32 mat, float value )
{
return new Matrix32( mat.mat.colum0 / value, mat.mat.colum1 / value );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static unsafe Matrix32 operator +( Matrix32 left, Matrix32 right )
{
Matrix32 ret = new Matrix32();
InternalIO.Intrinsic.add_mat_2( &left.mat, &right.mat, &ret.mat );
return ret;
}
}
}
@@ -1,240 +0,0 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Matrix33.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 StgSharp.Internal.Intrinsic;
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace StgSharp.Mathematics
{
[StructLayout(
LayoutKind.Explicit,
Size = ( 6 * 4 * sizeof( float ) ) + sizeof( bool ),
Pack = 16 )]
public struct Matrix33 : IMatrix<Matrix33>
{
[FieldOffset( 6 * 4 * sizeof( float ) )] internal bool isTransposed;
[FieldOffset( 0 )] internal ColumnSet3 mat;
[FieldOffset( 3 * 4 * sizeof( float ) )] internal ColumnSet3 transpose;
[FieldOffset( 0 * 4 * sizeof( float ) )] public Vec3 Colum0;
[FieldOffset( 1 * 4 * sizeof( float ) )] public Vec3 Colum1;
[FieldOffset( 2 * 4 * sizeof( float ) )] public Vec3 Colum2;
internal Matrix33( Vector4 c0, Vector4 c1, Vector4 c2 )
{
Unsafe.SkipInit( out this );
isTransposed = false;
mat.colum0 = c0;
mat.colum1 = c1;
mat.colum2 = c2;
}
public Matrix33()
{
Unsafe.SkipInit( out this );
isTransposed = false;
}
public Matrix33(
float a00,
float a01,
float a02,
float a10,
float a11,
float a12,
float a20,
float a21,
float a22 )
{
Unsafe.SkipInit( out this );
isTransposed = false;
mat.colum0 = new Vector4( a00, a10, a20, 0 );
mat.colum1 = new Vector4( a01, a11, a21, 0 );
mat.colum2 = new Vector4( a02, a12, a22, 0 );
}
public unsafe float this[ int rowNum, int columNum ]
{
get
{
if( ( rowNum > 2 ) || ( rowNum < 0 ) ) {
throw new ArgumentOutOfRangeException( nameof( columNum ) );
}
if( ( columNum > 2 ) || ( 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 ) );
return *( float* )pbit;
}
}
set
{
if( ( rowNum > 2 ) || ( rowNum < 0 ) ) {
throw new ArgumentOutOfRangeException( nameof( columNum ) );
}
if( ( columNum > 2 ) || ( columNum < 0 ) ) {
InternalIO.InternalWriteLog(
$"Attempt to write unused space in {GetType().Name} {nameof(mat)}",
LogType.Error );
}
InternalTranspose();
fixed( float* p = &this.transpose.m00 )
{
ulong pbit = ( ( ulong )p ) + ( ( ( ulong )sizeof( Vector4 ) ) * ( ( ulong )rowNum ) ) + ( ( ( ulong )sizeof( float ) ) * ( ( ulong )columNum ) );
*( float* )pbit = value;
}
isTransposed = false;
}
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public unsafe float Det()
{
fixed( ColumnSet3* mat = &this.mat ) {
return InternalIO.Intrinsic.det_mat_3( mat, ( ColumnSet3* )0 );
}
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
internal unsafe void InternalTranspose()
{
if( !isTransposed )
{
fixed( ColumnSet3* source = &this.mat, target = &this.transpose ) {
InternalIO.Intrinsic.transpose33( source, target );
}
isTransposed = true;
}
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static unsafe Matrix33 operator -( Matrix33 left, Matrix33 right )
{
Matrix33 ret = new Matrix33();
InternalIO.Intrinsic.sub_mat_3( &left.mat, &right.mat, &ret.mat );
return ret;
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static Matrix33 operator *( Matrix33 mat, float value )
{
return new Matrix33(
mat.mat.colum0 * value, mat.mat.colum1 * value, mat.mat.colum2 * value );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static Vec3 operator *( Matrix33 left, Vec3 right )
{
left.InternalTranspose();
return new Vec3(
Vector4.Dot( left.transpose.colum0, right.reg.AsVector4() ),
Vector4.Dot( left.transpose.colum1, right.reg.AsVector4() ),
Vector4.Dot( left.transpose.colum2, right.reg.AsVector4() ) );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static Matrix32 operator *( Matrix33 left, Matrix32 right )
{
left.InternalTranspose();
return new Matrix32(
Vector4.Dot( left.transpose.colum0, right.mat.colum0 ),
Vector4.Dot( left.transpose.colum0, right.mat.colum1 ),
Vector4.Dot( left.transpose.colum1, right.mat.colum0 ),
Vector4.Dot( left.transpose.colum1, right.mat.colum1 ),
Vector4.Dot( left.transpose.colum2, right.mat.colum0 ),
Vector4.Dot( left.transpose.colum2, right.mat.colum1 ) );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static Matrix33 operator *( Matrix33 left, Matrix33 right )
{
left.InternalTranspose();
return new Matrix33(
Vector4.Dot( left.transpose.colum0, right.mat.colum0 ),
Vector4.Dot( left.transpose.colum0, right.mat.colum1 ),
Vector4.Dot( left.transpose.colum0, right.mat.colum2 ),
Vector4.Dot( left.transpose.colum1, right.mat.colum0 ),
Vector4.Dot( left.transpose.colum1, right.mat.colum1 ),
Vector4.Dot( left.transpose.colum1, right.mat.colum2 ),
Vector4.Dot( left.transpose.colum2, right.mat.colum0 ),
Vector4.Dot( left.transpose.colum2, right.mat.colum1 ),
Vector4.Dot( left.transpose.colum2, right.mat.colum2 ) );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static Matrix34 operator *( Matrix33 left, Matrix34 right )
{
left.InternalTranspose();
return new Matrix34(
Vector4.Dot( left.transpose.colum0, right.mat.colum0 ),
Vector4.Dot( left.transpose.colum0, right.mat.colum1 ),
Vector4.Dot( left.transpose.colum0, right.mat.colum2 ),
Vector4.Dot( left.transpose.colum0, right.mat.colum3 ),
Vector4.Dot( left.transpose.colum1, right.mat.colum0 ),
Vector4.Dot( left.transpose.colum1, right.mat.colum1 ),
Vector4.Dot( left.transpose.colum1, right.mat.colum2 ),
Vector4.Dot( left.transpose.colum1, right.mat.colum3 ),
Vector4.Dot( left.transpose.colum2, right.mat.colum0 ),
Vector4.Dot( left.transpose.colum2, right.mat.colum1 ),
Vector4.Dot( left.transpose.colum2, right.mat.colum2 ),
Vector4.Dot( left.transpose.colum2, right.mat.colum3 ) );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static Matrix33 operator /( Matrix33 mat, float value )
{
return new Matrix33(
mat.mat.colum0 / value, mat.mat.colum1 / value, mat.mat.colum2 / value );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static unsafe Matrix33 operator +( Matrix33 left, Matrix33 right )
{
Matrix33 ret = new Matrix33();
InternalIO.Intrinsic.add_mat_3( &left.mat, &right.mat, &ret.mat );
return ret;
}
}
}
@@ -1,240 +0,0 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Matrix34.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 StgSharp.Internal.Intrinsic;
using System;
using System.Drawing;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace StgSharp.Mathematics
{
[StructLayout(
LayoutKind.Explicit,
Size = ( 7 * 4 * sizeof( float ) ) + sizeof( bool ),
Pack = 16 )]
public struct Matrix34 : IMatrix<Matrix34>
{
[FieldOffset( 7 * 4 * sizeof( float ) )] internal bool isTransposed;
[FieldOffset( 4 * 4 * sizeof( float ) )] internal ColumnSet3 transpose;
[FieldOffset( 0 )] internal ColumnSet4 mat;
[FieldOffset( 0 * 4 * sizeof( float ) )] public Vec3 Colum0;
[FieldOffset( 1 * 4 * sizeof( float ) )] public Vec3 Colum1;
[FieldOffset( 2 * 4 * sizeof( float ) )] public Vec3 Colum2;
[FieldOffset( 3 * 4 * sizeof( float ) )] public Vec3 Colum3;
internal Matrix34( ColumnSet4 mat )
{
Unsafe.SkipInit( out this );
isTransposed = false;
this.mat = mat;
}
internal Matrix34( Vector4 c0, Vector4 c1, Vector4 c2, Vector4 c3 )
{
Unsafe.SkipInit( out this );
isTransposed = false;
mat.colum0 = c0;
mat.colum1 = c1;
mat.colum2 = c2;
mat.colum3 = c3;
}
public Matrix34()
{
Unsafe.SkipInit( out this );
isTransposed = false;
}
public Matrix34(
float a00,
float a01,
float a02,
float a03,
float a10,
float a11,
float a12,
float a13,
float a20,
float a21,
float a22,
float a23 )
{
Unsafe.SkipInit( out this );
isTransposed = false;
mat.colum0 = new Vector4( a00, a10, a20, 0 );
mat.colum0 = new Vector4( a01, a11, a21, 0 );
mat.colum0 = new Vector4( a02, a12, a22, 0 );
mat.colum0 = new Vector4( a03, a13, a23, 0 );
}
public unsafe float this[ int rowNum, int columNum ]
{
get
{
if( ( rowNum > 2 ) || ( rowNum < 0 ) ) {
throw new ArgumentOutOfRangeException( nameof( columNum ) );
}
if( ( columNum > 3 ) || ( 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 ) );
return *( float* )pbit;
}
}
set
{
if( ( rowNum > 2 ) || ( rowNum < 0 ) ) {
throw new ArgumentOutOfRangeException( nameof( columNum ) );
}
if( ( columNum > 3 ) || ( 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 ) );
*( float* )pbit = value;
}
isTransposed = false;
}
}
internal unsafe void InternalTranspose()
{
if( !isTransposed )
{
fixed( ColumnSet4* source = &this.mat )
{
fixed( ColumnSet3* target = &this.transpose ) {
InternalIO.Intrinsic.transpose43( source, target );
}
}
isTransposed = true;
}
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static unsafe Matrix34 operator -( Matrix34 left, Matrix34 right )
{
Matrix34 ret = new Matrix34();
InternalIO.Intrinsic.sub_mat_4( &left.mat, &right.mat, &ret.mat );
return ret;
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static Matrix34 operator *( Matrix34 mat, float value )
{
return new Matrix34(
mat.mat.colum0 * value, mat.mat.colum1 * value, mat.mat.colum2 * value,
mat.mat.colum3 * value );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static Matrix32 operator *( Matrix34 left, Matrix42 right )
{
left.InternalTranspose();
return new Matrix32(
Vector4.Dot( left.transpose.colum0, right.mat.colum0 ),
Vector4.Dot( left.transpose.colum0, right.mat.colum1 ),
Vector4.Dot( left.transpose.colum1, right.mat.colum0 ),
Vector4.Dot( left.transpose.colum1, right.mat.colum1 ),
Vector4.Dot( left.transpose.colum2, right.mat.colum0 ),
Vector4.Dot( left.transpose.colum2, right.mat.colum1 ) );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static Matrix33 operator *( Matrix34 left, Matrix43 right )
{
left.InternalTranspose();
return new Matrix33(
Vector4.Dot( left.transpose.colum0, right.mat.colum0 ),
Vector4.Dot( left.transpose.colum0, right.mat.colum1 ),
Vector4.Dot( left.transpose.colum0, right.mat.colum2 ),
Vector4.Dot( left.transpose.colum1, right.mat.colum0 ),
Vector4.Dot( left.transpose.colum1, right.mat.colum1 ),
Vector4.Dot( left.transpose.colum1, right.mat.colum2 ),
Vector4.Dot( left.transpose.colum2, right.mat.colum0 ),
Vector4.Dot( left.transpose.colum2, right.mat.colum1 ),
Vector4.Dot( left.transpose.colum2, right.mat.colum2 ) );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static Matrix34 operator *( Matrix34 left, Matrix44 right )
{
left.InternalTranspose();
return new Matrix34(
Vector4.Dot( left.transpose.colum0, right.mat.colum0 ),
Vector4.Dot( left.transpose.colum0, right.mat.colum1 ),
Vector4.Dot( left.transpose.colum0, right.mat.colum2 ),
Vector4.Dot( left.transpose.colum0, right.mat.colum3 ),
Vector4.Dot( left.transpose.colum1, right.mat.colum0 ),
Vector4.Dot( left.transpose.colum1, right.mat.colum1 ),
Vector4.Dot( left.transpose.colum1, right.mat.colum2 ),
Vector4.Dot( left.transpose.colum1, right.mat.colum3 ),
Vector4.Dot( left.transpose.colum2, right.mat.colum0 ),
Vector4.Dot( left.transpose.colum2, right.mat.colum1 ),
Vector4.Dot( left.transpose.colum2, right.mat.colum2 ),
Vector4.Dot( left.transpose.colum2, right.mat.colum3 ) );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static Matrix34 operator /( Matrix34 mat, float value )
{
return new Matrix34(
mat.mat.colum0 / value, mat.mat.colum1 / value, mat.mat.colum2 / value,
mat.mat.colum3 / value );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static unsafe Matrix34 operator +( Matrix34 left, Matrix34 right )
{
Matrix34 ret = new Matrix34();
InternalIO.Intrinsic.add_mat_4( &left.mat, &right.mat, &ret.mat );
return ret;
}
}
}
@@ -1,240 +0,0 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Matrix42.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 StgSharp.Internal.Intrinsic;
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace StgSharp.Mathematics
{
[StructLayout(
LayoutKind.Explicit,
Size = ( ( 16 + 8 ) * sizeof( float ) ) + sizeof( bool ),
Pack = 16 )]
public struct Matrix42 : IMatrix<Matrix42>
{
[FieldOffset( ( 16 + 8 ) * sizeof( float ) )] internal bool isTransposed;
[FieldOffset( 0 )] internal ColumnSet2 mat;
[FieldOffset( 8 * sizeof( float ) )] internal ColumnSet4 transpose;
internal Matrix42( ColumnSet2 mat )
{
Unsafe.SkipInit( out this );
isTransposed = false;
this.mat = mat;
}
internal Matrix42( Vector4 c0, Vector4 c1 )
{
Unsafe.SkipInit( out this );
isTransposed = false;
mat.colum0 = c0;
mat.colum1 = c1;
}
public Matrix42()
{
Unsafe.SkipInit( out this );
isTransposed = false;
}
public Matrix42(
float a00,
float a01,
float a10,
float a11,
float a20,
float a21,
float a30,
float a31 )
{
Unsafe.SkipInit( out this );
isTransposed = false;
mat.colum0 = new Vector4( a00, a10, a20, a30 );
mat.colum1 = new Vector4( a01, a11, a21, a31 );
}
public unsafe float this[ int rowNum, int columNum ]
{
get
{
if( ( rowNum > 3 ) || ( rowNum < 0 ) ) {
throw new ArgumentOutOfRangeException( nameof( columNum ) );
}
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 ) );
return *( float* )pbit;
}
}
set
{
if( ( rowNum > 3 ) || ( rowNum < 0 ) ) {
throw new ArgumentOutOfRangeException( nameof( columNum ) );
}
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 ) );
*( float* )pbit = value;
}
isTransposed = false;
}
}
public override int GetHashCode()
{
return HashCode.Combine( mat.colum0.GetHashCode(), mat.colum1.GetHashCode() );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
internal unsafe void InternalTranspose()
{
if( !isTransposed )
{
fixed( ColumnSet2* source = &this.mat )
{
fixed( ColumnSet4* target = &this.transpose ) {
InternalIO.Intrinsic.transpose24( source, target );
}
}
isTransposed = true;
}
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static unsafe Matrix42 operator -( Matrix42 left, Matrix42 right )
{
Matrix42 ret = new Matrix42();
InternalIO.Intrinsic.sub_mat_2( &left.mat, &right.mat, &ret.mat );
return ret;
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static Matrix42 operator *( Matrix42 mat, float value )
{
return new Matrix42( mat.mat.colum0 * value, mat.mat.colum1 * value );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static Matrix42 operator *( Matrix42 left, Matrix22 right )
{
left.InternalTranspose();
return new Matrix42(
Vector4.Dot( left.transpose.colum0, right._mat.colum0 ),
Vector4.Dot( left.transpose.colum0, right._mat.colum1 ),
Vector4.Dot( left.transpose.colum1, right._mat.colum0 ),
Vector4.Dot( left.transpose.colum1, right._mat.colum1 ),
Vector4.Dot( left.transpose.colum2, right._mat.colum0 ),
Vector4.Dot( left.transpose.colum2, right._mat.colum1 ),
Vector4.Dot( left.transpose.colum3, right._mat.colum0 ),
Vector4.Dot( left.transpose.colum3, right._mat.colum1 ) );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static Matrix43 operator *( Matrix42 left, Matrix23 right )
{
left.InternalTranspose();
return new Matrix43(
Vector4.Dot( left.transpose.colum0, right._mat.colum0 ),
Vector4.Dot( left.transpose.colum0, right._mat.colum1 ),
Vector4.Dot( left.transpose.colum0, right._mat.colum2 ),
Vector4.Dot( left.transpose.colum1, right._mat.colum0 ),
Vector4.Dot( left.transpose.colum1, right._mat.colum1 ),
Vector4.Dot( left.transpose.colum1, right._mat.colum2 ),
Vector4.Dot( left.transpose.colum2, right._mat.colum0 ),
Vector4.Dot( left.transpose.colum2, right._mat.colum1 ),
Vector4.Dot( left.transpose.colum2, right._mat.colum2 ),
Vector4.Dot( left.transpose.colum3, right._mat.colum0 ),
Vector4.Dot( left.transpose.colum3, right._mat.colum1 ),
Vector4.Dot( left.transpose.colum3, right._mat.colum2 ) );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static Matrix44 operator *( Matrix42 left, Matrix24 right )
{
left.InternalTranspose();
return new Matrix44(
Vector4.Dot( left.transpose.colum0, right.mat.colum0 ),
Vector4.Dot( left.transpose.colum0, right.mat.colum1 ),
Vector4.Dot( left.transpose.colum0, right.mat.colum2 ),
Vector4.Dot( left.transpose.colum0, right.mat.colum2 ),
Vector4.Dot( left.transpose.colum1, right.mat.colum0 ),
Vector4.Dot( left.transpose.colum1, right.mat.colum1 ),
Vector4.Dot( left.transpose.colum1, right.mat.colum2 ),
Vector4.Dot( left.transpose.colum1, right.mat.colum2 ),
Vector4.Dot( left.transpose.colum2, right.mat.colum0 ),
Vector4.Dot( left.transpose.colum2, right.mat.colum1 ),
Vector4.Dot( left.transpose.colum2, right.mat.colum2 ),
Vector4.Dot( left.transpose.colum2, right.mat.colum2 ),
Vector4.Dot( left.transpose.colum3, right.mat.colum0 ),
Vector4.Dot( left.transpose.colum3, right.mat.colum1 ),
Vector4.Dot( left.transpose.colum3, right.mat.colum2 ),
Vector4.Dot( left.transpose.colum3, right.mat.colum2 ) );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static Matrix42 operator /( Matrix42 mat, float value )
{
return new Matrix42( mat.mat.colum0 / value, mat.mat.colum1 / value );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static unsafe Matrix42 operator +( Matrix42 left, Matrix42 right )
{
Matrix42 ret = new Matrix42();
InternalIO.Intrinsic.add_mat_2( &left.mat, &right.mat, &ret.mat );
return ret;
}
}
}
@@ -1,267 +0,0 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Matrix43.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 StgSharp.Internal.Intrinsic;
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security.AccessControl;
namespace StgSharp.Mathematics
{
[StructLayout(
layoutKind: LayoutKind.Explicit,
Size = ( 7 * 4 * sizeof( float ) ) + sizeof( bool ),
Pack = 16 )]
public struct Matrix43 : IEquatable<Matrix43>, IMatrix<Matrix43>
{
[FieldOffset( 7 * 4 * sizeof( float ) )]
internal bool isTransposed;
[FieldOffset( 0 )]
internal ColumnSet3 mat;
[FieldOffset( 3 * 4 * sizeof( float ) )]
internal ColumnSet4 transpose;
internal Matrix43( Vector4 c0, Vector4 c1, Vector4 c2 )
{
Unsafe.SkipInit( out this );
isTransposed = false;
mat.colum0 = c0;
mat.colum1 = c1;
mat.colum2 = c2;
}
public Matrix43()
{
Unsafe.SkipInit( out this );
isTransposed = false;
}
public Matrix43(
float a00,
float a01,
float a02,
float a10,
float a11,
float a12,
float a20,
float a21,
float a22,
float a30,
float a31,
float a32 )
{
Unsafe.SkipInit( out this );
isTransposed = false;
mat.colum0 = new Vector4( a00, a10, a20, a30 );
mat.colum1 = new Vector4( a01, a11, a21, a31 );
mat.colum2 = new Vector4( a02, a12, a22, a32 );
}
public unsafe float this[ int rowNum, int columNum ]
{
get
{
if( ( rowNum > 3 ) || ( rowNum < 0 ) ) {
throw new ArgumentOutOfRangeException( nameof( columNum ) );
}
if( ( columNum > 2 ) || ( 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 ) );
return *( float* )pbit;
}
}
set
{
if( ( rowNum > 3 ) || ( rowNum < 0 ) ) {
throw new ArgumentOutOfRangeException( nameof( columNum ) );
}
if( ( columNum > 2 ) || ( 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 ) );
*( float* )pbit = value;
}
isTransposed = false;
}
}
public override bool Equals( object? obj )
{
return ( obj is Matrix43 x ) && Equals( x );
}
public bool Equals( Matrix43 other )
{
return EqualityComparer<ColumnSet3>.Default.Equals( mat, other.mat );
}
public override int GetHashCode()
{
return HashCode.Combine(
mat.colum0.GetHashCode(), mat.colum1.GetHashCode(), mat.colum2.GetHashCode() );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
internal unsafe void InternalTranspose()
{
if( !isTransposed )
{
fixed( ColumnSet3* source = &this.mat )
{
fixed( ColumnSet4* target = &this.transpose ) {
InternalIO.Intrinsic.transpose34( source, target );
}
}
isTransposed = true;
}
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static Matrix43 operator -( Matrix43 left, Matrix43 right )
{
return new Matrix43(
left.mat.colum0 - right.mat.colum0, left.mat.colum1 - right.mat.colum1,
left.mat.colum2 - right.mat.colum2 );
}
public static bool operator !=( Matrix43 left, Matrix43 right )
{
return !( left == right );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static unsafe Matrix43 operator *( Matrix43 mat, float value )
{
return new Matrix43(
mat.mat.colum0 * value, mat.mat.colum1 * value, mat.mat.colum2 * value );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static Matrix42 operator *( Matrix43 left, Matrix32 right )
{
left.InternalTranspose();
return new Matrix42(
Vector4.Dot( left.transpose.colum0, right.mat.colum0 ),
Vector4.Dot( left.transpose.colum0, right.mat.colum1 ),
Vector4.Dot( left.transpose.colum1, right.mat.colum0 ),
Vector4.Dot( left.transpose.colum1, right.mat.colum1 ),
Vector4.Dot( left.transpose.colum2, right.mat.colum0 ),
Vector4.Dot( left.transpose.colum2, right.mat.colum1 ),
Vector4.Dot( left.transpose.colum3, right.mat.colum0 ),
Vector4.Dot( left.transpose.colum3, right.mat.colum1 ) );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static Matrix43 operator *( Matrix43 left, Matrix33 right )
{
left.InternalTranspose();
return new Matrix43(
Vector4.Dot( left.transpose.colum0, right.mat.colum0 ),
Vector4.Dot( left.transpose.colum0, right.mat.colum1 ),
Vector4.Dot( left.transpose.colum0, right.mat.colum2 ),
Vector4.Dot( left.transpose.colum1, right.mat.colum0 ),
Vector4.Dot( left.transpose.colum1, right.mat.colum1 ),
Vector4.Dot( left.transpose.colum1, right.mat.colum2 ),
Vector4.Dot( left.transpose.colum2, right.mat.colum0 ),
Vector4.Dot( left.transpose.colum2, right.mat.colum1 ),
Vector4.Dot( left.transpose.colum2, right.mat.colum2 ),
Vector4.Dot( left.transpose.colum3, right.mat.colum0 ),
Vector4.Dot( left.transpose.colum3, right.mat.colum1 ),
Vector4.Dot( left.transpose.colum3, right.mat.colum2 ) );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static Matrix44 operator *( Matrix43 left, Matrix34 right )
{
left.InternalTranspose();
return new Matrix44(
Vector4.Dot( left.transpose.colum0, right.mat.colum0 ),
Vector4.Dot( left.transpose.colum0, right.mat.colum1 ),
Vector4.Dot( left.transpose.colum0, right.mat.colum2 ),
Vector4.Dot( left.transpose.colum0, right.mat.colum3 ),
Vector4.Dot( left.transpose.colum1, right.mat.colum0 ),
Vector4.Dot( left.transpose.colum1, right.mat.colum1 ),
Vector4.Dot( left.transpose.colum1, right.mat.colum2 ),
Vector4.Dot( left.transpose.colum1, right.mat.colum3 ),
Vector4.Dot( left.transpose.colum2, right.mat.colum0 ),
Vector4.Dot( left.transpose.colum2, right.mat.colum1 ),
Vector4.Dot( left.transpose.colum2, right.mat.colum2 ),
Vector4.Dot( left.transpose.colum2, right.mat.colum3 ),
Vector4.Dot( left.transpose.colum3, right.mat.colum0 ),
Vector4.Dot( left.transpose.colum3, right.mat.colum1 ),
Vector4.Dot( left.transpose.colum3, right.mat.colum2 ),
Vector4.Dot( left.transpose.colum3, right.mat.colum3 ) );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static Matrix43 operator /( Matrix43 mat, float value )
{
return new Matrix43(
mat.mat.colum0 / value, mat.mat.colum1 / value, mat.mat.colum2 / value );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static unsafe Matrix43 operator +( Matrix43 left, Matrix43 right )
{
Matrix43 ret = new Matrix43();
InternalIO.Intrinsic.add_mat_3( &left.mat, &right.mat, &ret.mat );
return ret;
}
public static bool operator ==( Matrix43 left, Matrix43 right )
{
return left.Equals( right );
}
}
}
+109 -167
View File
@@ -1,33 +1,33 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Matrix44.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
// -----------------------------------------------------------------------
// file="Matrix44.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:
// 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 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.
// 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 StgSharp.Internal.Intrinsic;
using System;
@@ -39,32 +39,29 @@ using System.Runtime.InteropServices;
namespace StgSharp.Mathematics
{
[StructLayout(
LayoutKind.Explicit,
Size = ( 2 * 16 * sizeof( float ) ) + sizeof( bool ),
Pack = 16 )]
[StructLayout(LayoutKind.Explicit, Size = (2 * 16 * sizeof(float)) + sizeof(bool), Pack = 16)]
public unsafe struct Matrix44 : IEquatable<Matrix44>, IMatrix<Matrix44>
{
[FieldOffset( 2 * 64 * sizeof( float ) )] internal bool isTransposed;
[FieldOffset(2 * 64 * sizeof(float))] internal bool isTransposed;
[FieldOffset( 0 )] internal ColumnSet4 mat;
[FieldOffset( 16 * sizeof( float ) )] internal ColumnSet4 transpose;
[FieldOffset( 0 * sizeof( float ) )] internal Vec4 colum0;
[FieldOffset( 4 * sizeof( float ) )] internal Vec4 colum1;
[FieldOffset( 8 * sizeof( float ) )] internal Vec4 colum2;
[FieldOffset( 12 * sizeof( float ) )] internal Vec4 colum3;
[FieldOffset(0)] internal ColumnSet4 mat;
[FieldOffset(16 * sizeof(float))] internal ColumnSet4 transpose;
[FieldOffset(0 * sizeof(float))] internal Vec4 colum0;
[FieldOffset(4 * sizeof(float))] internal Vec4 colum1;
[FieldOffset(8 * sizeof(float))] internal Vec4 colum2;
[FieldOffset(12 * sizeof(float))] internal Vec4 colum3;
internal Matrix44( ColumnSet4 mat )
internal Matrix44(ColumnSet4 mat)
{
Unsafe.SkipInit( out this );
Unsafe.SkipInit(out this);
isTransposed = false;
this.mat = mat;
}
internal Matrix44( Vector4 vec0, Vector4 vec1, Vector4 vec2, Vector4 vec3 )
internal Matrix44(Vector4 vec0, Vector4 vec1, Vector4 vec2, Vector4 vec3)
{
Unsafe.SkipInit( out this );
Unsafe.SkipInit(out this);
isTransposed = false;
mat.colum0 = vec0;
mat.colum1 = vec1;
@@ -74,7 +71,7 @@ namespace StgSharp.Mathematics
public Matrix44()
{
Unsafe.SkipInit( out this );
Unsafe.SkipInit(out this);
isTransposed = false;
}
@@ -94,52 +91,52 @@ namespace StgSharp.Mathematics
float a30,
float a31,
float a32,
float a33 )
float a33)
{
Unsafe.SkipInit( out this );
Unsafe.SkipInit(out this);
isTransposed = false;
mat.colum0 = new Vector4( a00, a10, a20, a30 );
mat.colum1 = new Vector4( a01, a11, a21, a31 );
mat.colum2 = new Vector4( a02, a12, a22, a32 );
mat.colum3 = new Vector4( a03, a13, a23, a33 );
mat.colum0 = new Vector4(a00, a10, a20, a30);
mat.colum1 = new Vector4(a01, a11, a21, a31);
mat.colum2 = new Vector4(a02, a12, a22, a32);
mat.colum3 = new Vector4(a03, a13, a23, a33);
}
public unsafe float this[ int rowNum, int columNum ]
public unsafe float this[int rowNum, int columNum]
{
get
{
#if DEBUG
if( ( rowNum > 3 ) || ( rowNum < 0 ) )
if (rowNum is > 3 or < 0)
{
throw new ArgumentOutOfRangeException( nameof( columNum ) );
throw new ArgumentOutOfRangeException(nameof(columNum));
}
if( ( columNum > 3 ) || ( columNum < 0 ) ) {
throw new ArgumentOutOfRangeException( nameof( columNum ) );
if (columNum is > 3 or < 0) {
throw new ArgumentOutOfRangeException(nameof(columNum));
}
#endif
InternalTranspose();
fixed( float* p = &this.transpose.m00 )
fixed (float* p = &this.transpose.m00)
{
ulong pbit = ( ( ulong )p ) + ( ( ( ulong )sizeof( Vector4 ) ) * ( ( ulong )rowNum ) ) + ( ( ( ulong )sizeof( float ) ) * ( ( ulong )columNum ) );
return *( float* )pbit;
ulong pBit = ((ulong)p) + (((ulong)sizeof(Vector4)) * ((ulong)rowNum)) + (((ulong)sizeof(float)) * ((ulong)columNum));
return *(float*)pBit;
}
}
set
{
#if DEBUG
if( ( rowNum > 3 ) || ( rowNum < 0 ) )
if (rowNum is > 3 or < 0)
{
throw new ArgumentOutOfRangeException( nameof( columNum ) );
throw new ArgumentOutOfRangeException(nameof(columNum));
}
if( ( columNum > 3 ) || ( columNum < 0 ) ) {
throw new ArgumentOutOfRangeException( nameof( columNum ) );
if (columNum is > 3 or < 0) {
throw new ArgumentOutOfRangeException(nameof(columNum));
}
#endif
InternalTranspose();
fixed( float* p = &this.transpose.m00 )
fixed (float* p = &this.transpose.m00)
{
ulong pbit = ( ( ulong )p ) + ( ( ( ulong )sizeof( Vector4 ) ) * ( ( ulong )rowNum ) ) + ( ( ( ulong )sizeof( float ) ) * ( ( ulong )columNum ) );
*( float* )pbit = value;
ulong pbit = ((ulong)p) + (((ulong)sizeof(Vector4)) * ((ulong)rowNum)) + (((ulong)sizeof(float)) * ((ulong)columNum));
*(float*)pbit = value;
}
isTransposed = false;
}
@@ -150,80 +147,41 @@ namespace StgSharp.Mathematics
get
{
InternalTranspose();
return new Matrix44( this.transpose );
return new Matrix44(this.transpose);
}
}
public static Matrix44 Unit => new Matrix44(
1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 );
public static Matrix44 Unit => new Matrix44(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
public static Matrix44 WNegativeUnit => new Matrix44(
1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, -1 );
public static Matrix44 WNegativeUnit => new Matrix44(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, -1);
public static Matrix44 XNegativeUnit => new Matrix44(
-1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 );
public static Matrix44 XNegativeUnit => new Matrix44(-1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
public static Matrix44 YNegativeUnit => new Matrix44(
1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 );
public static Matrix44 YNegativeUnit => new Matrix44(1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
public static Matrix44 ZNegativeUnit => new Matrix44(
1, 0, 0, 0, 0, 1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1 );
public static Matrix44 ZNegativeUnit => new Matrix44(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1);
[MethodImpl( MethodImplOptions.AggressiveInlining )]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe float Det()
{
InternalTranspose();
fixed( ColumnSet4* _this = &mat, _trans = &transpose ) {
return InternalIO.Intrinsic.det_mat_4( _this, _trans );
}
return 0;
}
public override bool Equals( object? obj )
public override bool Equals(object? obj)
{
return ( obj is Matrix44 x ) && Equals( x );
return (obj is Matrix44 x) && Equals(x);
}
public bool Equals( Matrix44 other )
public bool Equals(Matrix44 other)
{
return mat.Equals( other.mat );
return mat.Equals(other.mat);
}
public override int GetHashCode()
{
return HashCode.Combine(
mat.colum0.GetHashCode(), mat.colum1.GetHashCode(), mat.colum2.GetHashCode(),
mat.colum3.GetHashCode() );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public unsafe Matrix42 Multiple( in Matrix42 right )
{
InternalTranspose();
Matrix42 ans = new Matrix42();
fixed( ColumnSet4* lptr = &transpose )
{
fixed( Vector4* rptr = &right.mat.colum0 ) {
InternalIO.Intrinsic.dot_42( lptr, rptr, &ans.mat.colum0 );
}
}
return ans;
}
public unsafe Matrix43 Multiple( in Matrix43 right )
{
InternalTranspose();
Matrix43 ans = new Matrix43();
fixed( Vector4* rptr = &right.mat.colum0 )
{
fixed( ColumnSet4* lptr = &transpose ) {
InternalIO.Intrinsic.dot_43( lptr, rptr, &ans.mat.colum0 );
}
}
return ans;
mat.colum3.GetHashCode());
}
public override string ToString()
@@ -232,94 +190,78 @@ namespace StgSharp.Mathematics
return $"{transpose.colum0}{transpose.colum1}{transpose.colum2}{transpose.colum3}";
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal unsafe void InternalTranspose()
{
if( !isTransposed )
if (!isTransposed)
{
fixed( ColumnSet4* source = &mat, target = &transpose ) {
InternalIO.Intrinsic.transpose44( source, target );
fixed (ColumnSet4* source = &mat, target = &transpose)
{
// InternalIO.Intrinsic.transpose44(source, target);
}
isTransposed = true;
}
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static unsafe Matrix44 operator -( Matrix44 left, Matrix44 right )
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe Matrix44 operator -(Matrix44 left, Matrix44 right)
{
return new Matrix44(
right.mat.colum0 - left.mat.colum0, right.mat.colum1 - left.mat.colum1,
right.mat.colum2 - left.mat.colum2, right.mat.colum3 - left.mat.colum3 );
right.mat.colum2 - left.mat.colum2, right.mat.colum3 - left.mat.colum3);
}
public static bool operator !=( Matrix44 left, Matrix44 right )
public static bool operator !=(Matrix44 left, Matrix44 right)
{
return !( left == right );
return !(left == right);
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static unsafe Matrix44 operator *( Matrix44 mat, float value )
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe Matrix44 operator *(Matrix44 mat, float value)
{
return new Matrix44(
mat.mat.colum0 * value, mat.mat.colum1 * value, mat.mat.colum2 * value,
mat.mat.colum3 * value );
mat.mat.colum3 * value);
}
[Obsolete(
"The operand may cause performance loss, use Matrix.Multiple() method instead.",
false )]
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static unsafe Matrix42 operator *( Matrix44 left, Matrix42 right )
{
return left.Multiple( right );
}
[Obsolete(
"The operand may cause performance loss, use Matrix.Multiple() method instead.",
false )]
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static Matrix43 operator *( Matrix44 left, Matrix43 right )
{
return left.Multiple( in right );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static Matrix44 operator *( Matrix44 left, Matrix44 right )
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix44 operator *(Matrix44 left, Matrix44 right)
{
left.InternalTranspose();
return new Matrix44(
Vector4.Dot( left.transpose.colum0, right.mat.colum0 ),
Vector4.Dot( left.transpose.colum0, right.mat.colum1 ),
Vector4.Dot( left.transpose.colum0, right.mat.colum2 ),
Vector4.Dot( left.transpose.colum0, right.mat.colum3 ),
Vector4.Dot(left.transpose.colum0, right.mat.colum0),
Vector4.Dot(left.transpose.colum0, right.mat.colum1),
Vector4.Dot(left.transpose.colum0, right.mat.colum2),
Vector4.Dot(left.transpose.colum0, right.mat.colum3),
Vector4.Dot( left.transpose.colum1, right.mat.colum0 ),
Vector4.Dot( left.transpose.colum1, right.mat.colum1 ),
Vector4.Dot( left.transpose.colum1, right.mat.colum2 ),
Vector4.Dot( left.transpose.colum1, right.mat.colum3 ),
Vector4.Dot(left.transpose.colum1, right.mat.colum0),
Vector4.Dot(left.transpose.colum1, right.mat.colum1),
Vector4.Dot(left.transpose.colum1, right.mat.colum2),
Vector4.Dot(left.transpose.colum1, right.mat.colum3),
Vector4.Dot( left.transpose.colum2, right.mat.colum0 ),
Vector4.Dot( left.transpose.colum2, right.mat.colum1 ),
Vector4.Dot( left.transpose.colum2, right.mat.colum2 ),
Vector4.Dot( left.transpose.colum2, right.mat.colum3 ),
Vector4.Dot(left.transpose.colum2, right.mat.colum0),
Vector4.Dot(left.transpose.colum2, right.mat.colum1),
Vector4.Dot(left.transpose.colum2, right.mat.colum2),
Vector4.Dot(left.transpose.colum2, right.mat.colum3),
Vector4.Dot( left.transpose.colum3, right.mat.colum0 ),
Vector4.Dot( left.transpose.colum3, right.mat.colum1 ),
Vector4.Dot( left.transpose.colum3, right.mat.colum2 ),
Vector4.Dot( left.transpose.colum3, right.mat.colum3 ) );
Vector4.Dot(left.transpose.colum3, right.mat.colum0),
Vector4.Dot(left.transpose.colum3, right.mat.colum1),
Vector4.Dot(left.transpose.colum3, right.mat.colum2),
Vector4.Dot(left.transpose.colum3, right.mat.colum3));
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static unsafe Matrix44 operator +( Matrix44 left, Matrix44 right )
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe Matrix44 operator +(Matrix44 left, Matrix44 right)
{
Matrix44 ret = new Matrix44();
InternalIO.Intrinsic.add_mat_4( &left.mat, &right.mat, &ret.mat );
// InternalIO.Intrinsic.add_mat_4(&left.mat, &right.mat, &ret.mat);
return ret;
}
public static bool operator ==( Matrix44 left, Matrix44 right )
public static bool operator ==(Matrix44 left, Matrix44 right)
{
return left.Equals( right );
return left.Equals(right);
}
}
@@ -1,96 +0,0 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="MatrixIndexLabel.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.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Mathematics
{
public readonly struct MatrixIndexLabel
{
private readonly bool _isRange;
public readonly Range R;
internal MatrixIndexLabel(Index i)
{
_isRange = false;
R = new Range(i, Index.End);
}
internal MatrixIndexLabel(Range r)
{
_isRange = true;
R = r;
}
public (int offset,int legnth) GetOffsetAndLength(int CountOfCollection)
{
return _isRange ?
R.GetOffsetAndLength(CountOfCollection) : (R.Start.GetOffset(CountOfCollection), 1);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int Length(int CountOfCollection)
{
return _isRange ? R.GetOffsetAndLength(CountOfCollection).Length : 1;
}
public int Offset(int CountOfCollection)
{
return _isRange ?
R.GetOffsetAndLength(CountOfCollection).Offset : R.Start
.GetOffset(CountOfCollection);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator MatrixIndexLabel(Index i)
{
return new MatrixIndexLabel(i);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator MatrixIndexLabel(Range r)
{
return new MatrixIndexLabel(r);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator MatrixIndexLabel(int i)
{
return new MatrixIndexLabel(i);
}
}
}
@@ -1,97 +0,0 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="VecAny.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.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Mathematics
{
[CollectionBuilder(typeof(VecAnyBuilder), nameof(VecAnyBuilder.Build))]
public class VecAny : IEnumerable<float>
{
private float[] _values;
internal VecAny(ReadOnlySpan<float> values)
{
_values = values.ToArray();
}
public VecAny(int size)
{
if (size <= 0) {
throw new ArgumentOutOfRangeException(
nameof(size), "Size must be greater than zero.");
}
_values = new float[size];
}
public VecAny? this[ReadOnlySpan<MatrixIndexLabel> span]
{
get
{
if (span.Length == 0) {
return null;
}
int size = 0;
foreach (MatrixIndexLabel label in span) {
size += label.Length(_values.Length);
}
return new VecAny(size);
}
}
public IEnumerator<float> GetEnumerator()
{
return ((IEnumerable<float>)_values).GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return _values.GetEnumerator();
}
}
public class VecAnyBuilder
{
public static VecAny Build(ReadOnlySpan<float> span)
{
return new VecAny(span);
}
}
}