daily update on 20230301 by nitload youmu, file struct cahnged and more vec func added

This commit is contained in:
Nitload
2023-03-02 01:30:46 +08:00
parent d09105c9c1
commit bb71567e51
594 changed files with 368 additions and 2601 deletions
+100
View File
@@ -0,0 +1,100 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
namespace StgSharp.Math
{
[StructLayout(LayoutKind.Explicit)]
public struct Array2x2:IEquatable<Array2x2>
{
[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<Array2x2>.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
);
}
}
}
+108
View File
@@ -0,0 +1,108 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
namespace StgSharp.Math
{
[StructLayout(LayoutKind.Explicit)]
public struct Array2x3:IEquatable<Array2x3>
{
[FieldOffset(0)]
public Vec3D row1;
[FieldOffset(12)]
public Vec3D row2;
public Array2x3(Vec3D r1, Vec3D r2)
{
row1 = r1;
row2 = r2;
}
public override bool Equals(object obj)
{
if (obj == null)
{
return false;
}
else if (obj.GetType() != typeof(Array2x3))
{
return false;
}
else
{
return this.Equals((Vec3D)obj);
}
}
public override int GetHashCode()
{
return HashCode.Combine(row1, row2);
}
public override string ToString()
{
return $"{row1}\n{row2}";
}
bool IEquatable<Array2x3>.Equals(Array2x3 other)
{
if (this.GetHashCode() != other.GetHashCode())
{
return false;
}
else
{
return
this.row1 == other.row1
&& this.row2 == other.row2;
}
}
public static Array2x3 operator +(Array2x3 array1, Array2x3 array2)
{
return new Array2x3(
array1.row1 + array2.row1,
array1.row2 + array2.row2
);
}
public static Array2x3 operator -(Array2x3 array1, Array2x3 array2)
{
return new Array2x3(
array1.row1 - array2.row1,
array1.row2 - array2.row2
);
}
public static Array2x3 operator *(Array2x3 array, float x)
{
return new Array2x3(
array.row1 * x,
array.row2 * x
) ;
}
public static Array2x3 operator /(Array2x3 array, float x)
{
return new Array2x3(
array.row1 / x,
array.row2 / x
);
}
public static unsafe Array2x2 operator *(Array2x3 array1, Array3x2 array2)
{
float* p1 = &array1.row1.X;
float* p2 = &array2.row2.X;
return new Array2x2(
*(p1 + 0) * *(p2 + 0) + *(p1 + 1) * *(p2 + 2) + *(p1 + 2) * *(p2 + 4),
*(p1 + 0) * *(p2 + 1) + *(p1 + 1) * *(p2 + 3) + *(p1 + 2) * *(p2 + 5),
*(p1 + 3) * *(p2 + 0) + *(p1 + 4) * *(p2 + 2) + *(p1 + 5) * *(p2 + 4),
*(p1 + 3) * *(p2 + 1) + *(p1 + 4) * *(p2 + 3) + *(p1 + 5) * *(p2 + 5)
);
}
}
}
+85
View File
@@ -0,0 +1,85 @@
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)
);
}
}
}
+161
View File
@@ -0,0 +1,161 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security.Cryptography.X509Certificates;
using System.Text;
namespace StgSharp.Math
{
[StructLayout(LayoutKind.Explicit)]
public struct Array3x3:IEquatable<Array3x3>
{
[FieldOffset(0)]
public Vec3D row1;
[FieldOffset(12)]
public Vec3D row2;
[FieldOffset(24)]
public Vec3D row3;
public Array3x3(Vec3D r0,Vec3D r1,Vec3D r2)
{
row1 = r0;
row2 = r1;
row3 = r2;
}
public Array3x3(
float a11,float a12,float a13,
float a21,float a22,float a23,
float a31,float a32,float a33
)
{
row1 = new Vec3D(a11, a12, a13);
row2 = new Vec3D(a21, a22, a23);
row3 = new Vec3D(a31, a32, a33);
}
public override int GetHashCode()
{
return HashCode.Combine(row1,row2,row3);
}
bool IEquatable<Array3x3>.Equals(Array3x3 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(Array3x3))
{
return false;
}
else
{
return this.Equals((Array3x3)obj);
}
}
public override string ToString()
{
return $"{row1}\n{row2}\n{row3}";
}
public static bool operator ==(Array3x3 array1, Array3x3 array2)
{
return array1.Equals(array2);
}
public static bool operator !=(Array3x3 array1, Array3x3 array2)
{
return !array1.Equals(array2);
}
public static Array3x3 operator +(Array3x3 array1, Array3x3 array2)
{
return new Array3x3(
array1.row1.X + array2.row1.X,
array1.row1.Y + array2.row1.Y,
array1.row1.Z + array2.row1.Z,
array1.row2.X + array2.row2.X,
array1.row2.Y + array2.row2.Y,
array1.row2.Z + array2.row2.Z,
array1.row3.X + array2.row3.X,
array1.row3.Y + array2.row3.Y,
array1.row3.Z + array2.row3.Z
);
}
public static Array3x3 operator -(Array3x3 array1, Array3x3 array2)
{
return new Array3x3(
array1.row1.X - array2.row1.X,
array1.row1.Y - array2.row1.Y,
array1.row1.Z - array2.row1.Z,
array1.row2.X - array2.row2.X,
array1.row2.Y - array2.row2.Y,
array1.row2.Z - array2.row2.Z,
array1.row3.X - array2.row3.X,
array1.row3.Y - array2.row3.Y,
array1.row3.Z - array2.row3.Z
);
}
public static unsafe Array3x3 operator *(Array3x3 array1,Array3x3 array2)
{
float* p1 = &array1.row1.X;
float* p2 = &array2.row1.X;
return new Array3x3(
*(p1 + 0) * *(p2 + 0) + *(p1 + 1) * *(p2 + 3) + *(p1 + 2) * *(p2 + 6),
*(p1 + 0) * *(p2 + 1) + *(p1 + 1) * *(p2 + 4) + *(p1 + 2) * *(p2 + 7),
*(p1 + 0) * *(p2 + 2) + *(p1 + 1) * *(p2 + 5) + *(p1 + 2) * *(p2 + 8),
*(p1 + 3) * *(p2 + 0) + *(p1 + 4) * *(p2 + 3) + *(p1 + 5) * *(p2 + 6),
*(p1 + 3) * *(p2 + 1) + *(p1 + 4) * *(p2 + 4) + *(p1 + 5) * *(p2 + 7),
*(p1 + 3) * *(p2 + 2) + *(p1 + 4) * *(p2 + 5) + *(p1 + 5) * *(p2 + 8),
*(p1 + 6) * *(p2 + 0) + *(p1 + 7) * *(p2 + 3) + *(p1 + 2) * *(p2 + 6),
*(p1 + 6) * *(p2 + 1) + *(p1 + 7) * *(p2 + 4) + *(p1 + 2) * *(p2 + 7),
*(p1 + 6) * *(p2 + 2) + *(p1 + 7) * *(p2 + 5) + *(p1 + 2) * *(p2 + 8)
);
}
public static Array3x3 operator *(Array3x3 array, float x)
{
return new Array3x3(
array.row1 * x,
array.row2 * x,
array.row3 * x
);
}
public static Array3x3 operator /(Array3x3 array, float x)
{
return new Array3x3(
array.row1/x,
array.row2/x,
array.row3/x
);
}
}
}
+24
View File
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Math
{
public static unsafe partial class VectorCalc
{
public static float Cross(Vec2D vec1, Vec2D vec2)
{
return vec1.X * vec2.Y - vec1.Y * vec2.X;
}
public static Vec3D Cross(Vec3D vec1, Vec3D vec2)
{
return new Vec3D(
vec1.Y * vec2.Z - vec1.Z * vec2.Y,
vec1.X * vec2.Z - vec1.Z * vec2.X,
vec1.X * vec2.Y - vec1.Y * vec2.X
);
}
}
}
+39
View File
@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Math
{
public static unsafe partial class VectorCalc
{
public static float Det(Array2x2 array)
{
return Cross(array.row1,array.row2);
}
public static unsafe float Det(Array3x3 array)
{
float* p = &array.row1.X;
Array2x2 array1 = new Array2x2(
*(p + 4), *(p + 5),
*(p + 7), *(p + 8)
);
Array2x2 array2 = new Array2x2(
*(p + 3), *(p + 5),
*(p + 6), *(p + 8)
);
Array2x2 array3 = new Array2x2(
*(p + 3), *(p + 4),
*(p + 6), *(p + 7)
);
return
*p * Det(array1)
- *(p + 1) * Det(array2)
+ *(p + 2) * Det(array3)
;
}
}
}
+26
View File
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Math
{
public static unsafe partial class VectorCalc
{
public static float GetAngle(Vec2D vec1, Vec2D vec2)
{
return Calc.ACos(
vec1 * vec2
/ (vec1.GetLength() * vec2.GetLength())
);
}
public static float GetAngle(Vec3D vec1, Vec3D vec2)
{
return Calc.ACos(
vec1 * vec2
/ (vec1.GetLength() * vec2.GetLength())
);
}
}
}
+27
View File
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Math
{
public static unsafe partial class VectorCalc
{
public static float GetLength(this Vec3D vec)
{
return Calc.Sqrt(
vec.X * vec.X +
vec.Y * vec.Y +
vec.Z * vec.Z
);
}
public static float GetLength(this Vec2D vec)
{
return Calc.Sqrt(
vec.X * vec.X +
vec.Y * vec.Y
);
}
}
}
+11
View File
@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Math
{
public static unsafe partial class VectorCalc
{
}
}
+103
View File
@@ -0,0 +1,103 @@
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Runtime;
using System.Runtime.InteropServices;
using System.Text;
namespace StgSharp.Math
{
[StructLayout(LayoutKind.Explicit)]
public struct Vec2D:IEquatable<Vec2D>
{
[FieldOffset(0)]
public float X;
[FieldOffset(sizeof(float))]
public float Y;
public Vec2D(float x,float y)
{
X = x;
Y = y;
}
public bool Equals(Vec2D other)
{
if (this.GetHashCode() != other.GetHashCode())
{
return false;
}
else
{
return this.X == other.X && this.Y == other.Y;
}
}
public override bool Equals(object obj)
{
if (obj == null)
{
return false;
}
else if (obj.GetType() != typeof(Vec2D))
{
return false;
}
else
{
return this.Equals((Vec2D)obj);
}
}
public override int GetHashCode()
{
return HashCode.Combine(X, Y);
}
public override string ToString()
{
return $"{this.X}\t{this.Y}";
}
public static bool operator ==(Vec2D vec1, Vec2D vec2)
{
return vec1.X==vec2.X && vec1.Y==vec2.Y;
}
public static bool operator !=(Vec2D vec1, Vec2D vec2)
{
return !(vec1.X == vec2.X && vec1.Y == vec2.Y);
}
public static Vec2D operator +(Vec2D vec1, Vec2D vec2)
{
return new Vec2D(vec1.X + vec2.X, vec1.Y + vec2.Y);
}
public static Vec2D operator -(Vec2D vec1, Vec2D vec2)
{
return new Vec2D(vec1.X + vec2.X, vec1.Y + vec2.Y);
}
public static float operator *(Vec2D vec1, Vec2D vec2)
{
return vec1.X * vec2.X + vec1.Y*vec2.Y;
}
public static Vec2D operator *(Vec2D vec, float x)
{
return new Vec2D(vec.X * x, vec.Y * x);
}
public static Vec2D operator /(Vec2D vec, float x)
{
return new Vec2D(vec.X/x, vec.Y/x);
}
public Vec3D to3D()
{
return new Vec3D(this.X, this.Y, 0.0f);
}
}
}
+124
View File
@@ -0,0 +1,124 @@
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Runtime.InteropServices;
using System.Text;
namespace StgSharp.Math
{
[StructLayout(LayoutKind.Explicit)]
public struct Vec3D : IEquatable<Vec3D>
{
[FieldOffset(0)]
public float X;
[FieldOffset(4)]
public float Y;
[FieldOffset(8)]
public float Z;
public Vec3D(float x, float y, float z)
{
X = x;
Y = y;
Z = z;
}
bool IEquatable<Vec3D>.Equals(Vec3D other)
{
if (this.GetHashCode() != other.GetHashCode())
{
return false;
}
else
{
return this.X == other.X
&& this.Y == other.Y
&& this.Z == other.Z;
}
}
public override bool Equals(object obj)
{
if (obj == null)
{
return false;
}
else if (obj.GetType() != typeof(Vec3D))
{
return false;
}
else
{
return this.Equals((Vec3D)obj);
}
}
public override int GetHashCode()
{
return HashCode.Combine(X, Y, Z);
}
public override string ToString()
{
return $"{X}\t{Y}\t{Z}";
}
public static bool operator ==(Vec3D vec1,Vec3D vec2)
{
return vec1.X == vec2.X
&& vec1.Y == vec2.Y
&& vec1.Z == vec2.Z;
}
public static bool operator !=(Vec3D vec1, Vec3D vec2)
{
return !(vec1.X == vec2.X
&& vec1.Y == vec2.Y
&& vec1.Z == vec2.Z);
}
public static Vec3D operator +(Vec3D vec1, Vec3D vec2)
{
return new Vec3D(
vec1.X + vec2.X,
vec1.Y + vec2.Y,
vec1.Z + vec2.Z
);
}
public static Vec3D operator -(Vec3D vec1, Vec3D vec2)
{
return new Vec3D(
vec1.X - vec2.X,
vec1.Y - vec2.Y,
vec1.Z - vec2.Z
);
}
public static float operator *(Vec3D vec1, Vec3D vec2)
{
return
vec1.X * vec2.X
+ vec1.Y + vec2.Y
+ vec1.Z + vec2.Z;
}
public static Vec3D operator *(Vec3D vec, float x)
{
return new Vec3D(
vec.X * x,
vec.Y * x,
vec.Z * x
);
}
public static Vec3D operator /(Vec3D vec, float x)
{
return new Vec3D(
vec.X / x,
vec.Y / x,
vec.Z / x
);
}
}
}
+132
View File
@@ -0,0 +1,132 @@
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using System.Security.Cryptography.X509Certificates;
using System.Text;
namespace StgSharp.Math
{
[StructLayout(LayoutKind.Explicit)]
public struct Vec4D:IEquatable<Vec4D>
{
[FieldOffset(0)]
public float X;
[FieldOffset(4)]
public float Y;
[FieldOffset(8)]
public float Z;
[FieldOffset(12)]
public float W;
[FieldOffset(0)]
public Vec2D Point1;
[FieldOffset(8)]
public Vec2D Point2;
public Vec4D(float x,float y,float z,float w)
{
Point1 = new Vec2D();
Point2 = new Vec2D();
X = x;
Y = y;
Z = z;
W = w;
}
public override bool Equals(object obj)
{
if (obj == null)
{
return false;
}
else if(obj.GetType() != typeof(Vec4D))
{
return false;
}
else
{
return this == (Vec4D)obj;
}
}
bool IEquatable<Vec4D>.Equals(Vec4D other)
{
if (this.GetHashCode() != other.GetHashCode())
{
return false;
}
else
{
return
this.Point1 == other.Point1
&& this.Point2 == other.Point2;
}
}
public override int GetHashCode()
{
return HashCode.Combine(X, Y, Z, W);
}
public override string ToString()
{
return $"{X}\t{Y}\t{Y}\t{Y}";
}
public static bool operator ==(Vec4D vec1, Vec4D vec2)
{
return vec1.Equals(vec2);
}
public static bool operator !=(Vec4D vec1, Vec4D vec2)
{
return !vec1.Equals(vec2);
}
public static Vec4D operator +(Vec4D vec1, Vec4D vec2)
{
return new Vec4D(
vec1.X + vec2.X,
vec1.Y + vec2.Y,
vec1.Z + vec2.Z,
vec1.W + vec2.W
);
}
public static Vec4D operator -(Vec4D vec1, Vec4D vec2)
{
return new Vec4D(
vec1.X - vec2.X,
vec1.Y - vec2.Y,
vec1.Z - vec2.Z,
vec1.W - vec2.W
);
}
public static float operator *(Vec4D vec1, Vec4D vec2)
{
return
vec1.X * vec2.X
+ vec1.Y * vec2.Y
+ vec1.Z * vec2.Z
+ vec1.W * vec2.W;
}
public static Vec4D operator *(Vec4D vec, float x)
{
return new Vec4D(vec.X * x, vec.Y * x, vec.Z * x, vec.W * x ) ;
}
public static Vec4D operator /(Vec4D vec, float x)
{
return new Vec4D(vec.X / x, vec.Y / x, vec.Z / x, vec.W / x);
}
}
}