New IO structure, unexpexted error in C code

This commit is contained in:
Nitload
2023-06-22 03:33:24 +08:00
parent 50b4965e54
commit ee8132c149
172 changed files with 1344 additions and 4023 deletions
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Math
namespace StgSharp.Math
{
internal class Cordination
+3 -7
View File
@@ -1,15 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Math
namespace StgSharp.Math
{
public static unsafe partial class Vector
{
public static float Det(matrix2x2 array)
{
return Cross(array.row1,array.row2);
return Cross(array.row1, array.row2);
}
public static unsafe float Det(matrix3x3 array)
@@ -29,7 +25,7 @@ namespace StgSharp.Math
*(p + 6), *(p + 7)
);
return
return
*p * Det(matrix1)
- *(p + 1) * Det(matrix2)
+ *(p + 2) * Det(matrix3)
@@ -1,15 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Math
namespace StgSharp.Math
{
public static unsafe partial class Vector
{
public static float GetAngle(vec2d vec1, vec2d vec2)
{
return Calc.ACos(
vec1 .multiple(vec2)
vec1.multiple(vec2)
/ (vec1.GetLength() * vec2.GetLength())
);
}
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Math
namespace StgSharp.Math
{
public static unsafe partial class Vector
{
@@ -18,7 +14,7 @@ namespace StgSharp.Math
public static float GetLength(this vec2d vec)
{
return Calc.Sqrt(
vec.X * vec.X +
vec.X * vec.X +
vec.Y * vec.Y
);
}
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Math
namespace StgSharp.Math
{
public static unsafe partial class Vector
{
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Security.Cryptography.X509Certificates;
using System.Text;
namespace StgSharp.Math
namespace StgSharp.Math
{
public static unsafe partial class VectorCalc
{
@@ -131,7 +126,7 @@ namespace StgSharp.Math
*(p1 + 2) * *(p2 + 0) + *(p1 + 3) * *(p2 + 1)
);
}
/// <summary>
///
/// </summary>
@@ -373,8 +368,8 @@ namespace StgSharp.Math
var c2 = a1.multiple(b12) + a2.multiple(b22);
return new matrix2x4(
new vec4d(c1.row1,c2.row1),
new vec4d(c1.row2,c2.row2)
new vec4d(c1.row1, c2.row1),
new vec4d(c1.row2, c2.row2)
);
}
@@ -448,11 +443,11 @@ namespace StgSharp.Math
float* p2 = &matrix2.row1.X;
return new matrix2x3(
getMatrixMember(p1,p2), getMatrixMember(p1, p2+1), getMatrixMember(p1, p2+2),
getMatrixMember(p1+4, p2), getMatrixMember(p1+4, p2+1), getMatrixMember(p1+4, p2 + 2)
getMatrixMember(p1, p2), getMatrixMember(p1, p2 + 1), getMatrixMember(p1, p2 + 2),
getMatrixMember(p1 + 4, p2), getMatrixMember(p1 + 4, p2 + 1), getMatrixMember(p1 + 4, p2 + 2)
);
}
/// <summary>
@@ -464,19 +459,19 @@ namespace StgSharp.Math
public static unsafe matrix2x4 multiple(this matrix2x4 matrix1, matrix4x4 matrix2)
{
matrix2x2 a1 = new matrix2x2(matrix1.row1.Point1,matrix1.row2.Point1);
matrix2x2 a1 = new matrix2x2(matrix1.row1.Point1, matrix1.row2.Point1);
matrix2x2 a2 = new matrix2x2(matrix1.row1.Point2, matrix1.row2.Point2);
matrix2x2 b11 = new matrix2x2(matrix2.row1.Point1, matrix2.row2.Point1);
matrix2x2 b12 = new matrix2x2(matrix2.row1.Point2, matrix2.row2.Point2);
matrix2x2 b21 = new matrix2x2(matrix2.row3.Point1, matrix2.row4.Point1);
matrix2x2 b22 = new matrix2x2(matrix2.row3.Point2, matrix2.row4.Point2);
var c1 = a1.multiple(b11) + a2.multiple(b21);
var c2 = a1.multiple(b12) + a2.multiple(b22);
return new matrix2x4(
new vec4d(c1.row1, c2.row1),
new vec4d(c1.row1, c2.row1),
new vec4d(c1.row2, c2.row2));
}
@@ -533,9 +528,9 @@ namespace StgSharp.Math
float* p3 = &m11.row1.X;
return new matrix3x3(
*(p3 + 0), *(p3 + 1),m12.X,
*(p3 + 2), *(p3 + 3),m12.Y,
m21.X, m21.Y, m22
*(p3 + 0), *(p3 + 1), m12.X,
*(p3 + 2), *(p3 + 3), m12.Y,
m21.X, m21.Y, m22
);
}
@@ -547,7 +542,7 @@ namespace StgSharp.Math
/// <returns></returns>
public static unsafe matrix3x4 multiple(this matrix3x2 matrix1, matrix2x4 matrix2)
{
var a1 = new matrix2x2(matrix1.row1,matrix1.row2);
var a1 = new matrix2x2(matrix1.row1, matrix1.row2);
var a2 = matrix1.row3;
var b1 = new matrix2x2(matrix2.row1.Point1, matrix2.row2.Point1);
@@ -589,13 +584,13 @@ namespace StgSharp.Math
var a21 = new vec2d(*(p1 + 6), *(p1 + 7));
var a22 = *(p1 + 8);
var b1 = new matrix2x2(matrix2.row1,matrix2.row2);
var b1 = new matrix2x2(matrix2.row1, matrix2.row2);
var b2 = matrix2.row3;
var c1 = a11.multiple(b1) + a12.multiple(b2);
var c2 = a21.multiple(b1) + b2 * a22;
return new matrix3x2(c1.row1,c1.row2,c2);
return new matrix3x2(c1.row1, c1.row2, c2);
}
/// <summary>
@@ -655,9 +650,9 @@ namespace StgSharp.Math
return new matrix3x4(
new vec4d(c11.row1,c12.row1),
new vec4d(c11.row2,c12.row2),
new vec4d(c21,c22)
new vec4d(c11.row1, c12.row1),
new vec4d(c11.row2, c12.row2),
new vec4d(c21, c22)
);
}
@@ -693,7 +688,7 @@ namespace StgSharp.Math
var c1 = a11.multiple(b1) + a12.multiple(b2);
var c2 = a21.multiple(b1) + a22.multiple(b2);
return new matrix3x2(c1.row1,c1.row2,c2);
return new matrix3x2(c1.row1, c1.row2, c2);
}
/// <summary>
@@ -750,8 +745,8 @@ namespace StgSharp.Math
float* p1 = &matrix1.row1.X;
float* p2 = &matrix2.row1.X;
var a11 = new matrix2x2(matrix1.row1.Point1,matrix1.row2.Point1);
var a12 = new matrix2x2(matrix1.row1.Point2,matrix1.row2.Point2);
var a11 = new matrix2x2(matrix1.row1.Point1, matrix1.row2.Point1);
var a12 = new matrix2x2(matrix1.row1.Point2, matrix1.row2.Point2);
var a21 = matrix1.row3.Point1;
var a22 = matrix1.row3.Point2;
@@ -766,10 +761,10 @@ namespace StgSharp.Math
var c4 = a21.multiple(b12) + a22.multiple(b22);
return new matrix3x4(
new vec4d(c1.row1,c2.row1),
new vec4d(c1.row2,c2.row2),
new vec4d(c3,c4)
) ;
new vec4d(c1.row1, c2.row1),
new vec4d(c1.row2, c2.row2),
new vec4d(c3, c4)
);
}
@@ -813,10 +808,10 @@ namespace StgSharp.Math
var u7 = u3 + m5;
return new matrix4x2(
new vec2d(u1.X,u5.X),
new vec2d(u1.Y,u5.Y),
new vec2d(u6.X,u7.X),
new vec2d(u6.Y,u7.Y)
new vec2d(u1.X, u5.X),
new vec2d(u1.Y, u5.Y),
new vec2d(u6.X, u7.X),
new vec2d(u6.Y, u7.Y)
);
}
@@ -839,10 +834,10 @@ namespace StgSharp.Math
float* pc2 = &c21.row1.X;
return new matrix4x3(
*(pc1 + 0), *(pc1 + 1),c12.X,
*(pc1 + 2), *(pc1 + 3),c12.Y,
*(pc2 + 0), *(pc2 + 1),c22.X,
*(pc2 + 2), *(pc2 + 3),c22.Y
*(pc1 + 0), *(pc1 + 1), c12.X,
*(pc1 + 2), *(pc1 + 3), c12.Y,
*(pc2 + 0), *(pc2 + 1), c22.X,
*(pc2 + 2), *(pc2 + 3), c22.Y
);
}
@@ -917,7 +912,7 @@ namespace StgSharp.Math
var c1 = a11.multiple(b1) + a12.multiple(b2);
var c2 = a21.multiple(b1) + a22.multiple(b2);
return new matrix4x2(c1.row1,c1.row2,c2.row1,c2.row2);
return new matrix4x2(c1.row1, c1.row2, c2.row1, c2.row2);
}
@@ -945,10 +940,10 @@ namespace StgSharp.Math
float* p4 = &c21.row1.X;
return new matrix4x3(
*(p3 + 0), *(p3 + 1),c12.X,
*(p3 + 2), *(p3 + 3),c12.Y,
*(p4 + 0), *(p4 + 1),c22.X,
*(p4 + 2), *(p4 + 3),c22.Y
*(p3 + 0), *(p3 + 1), c12.X,
*(p3 + 2), *(p3 + 3), c12.Y,
*(p4 + 0), *(p4 + 1), c22.X,
*(p4 + 2), *(p4 + 3), c22.Y
);
}
@@ -962,7 +957,7 @@ namespace StgSharp.Math
var a21 = new matrix2x2(*(p1 + 6), *(p1 + 7), *(p1 + 9), *(p1 + 10));
var a22 = new colum2(*(p1 + 8), *(p1 + 11));
var b11 = new matrix2x2 (*(p2 + 0), *(p2 + 1), *(p2 + 4), *(p2 + 5));
var b11 = new matrix2x2(*(p2 + 0), *(p2 + 1), *(p2 + 4), *(p2 + 5));
var b12 = new matrix2x2(*(p2 + 2), *(p2 + 3), *(p2 + 6), *(p2 + 7));
var b21 = matrix2.row3.Point1;
var b22 = matrix2.row3.Point2;
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;
namespace StgSharp.Math
namespace StgSharp.Math
{
public static unsafe partial class Vector
{
@@ -12,14 +7,14 @@ namespace StgSharp.Math
return new vec3d(vec.X, vec.Y, 0.0f);
}
public static vec4d To4D(this vec2d Vec)
public static vec4d To4D(this vec2d Vec)
{
return new vec4d(Vec.X, Vec.Y, 0, 0);
return new vec4d(Vec.X, Vec.Y, 0, 0);
}
public static vec4d To4D(this vec3d vec)
public static vec4d To4D(this vec3d vec)
{
return new vec4d(vec.X, vec.Y, vec.Z, 0);
return new vec4d(vec.X, vec.Y, vec.Z, 0);
}
public static vec2d To2D(vec3d vec, CordinatePlain plain)
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Math
namespace StgSharp.Math
{
public static unsafe partial class Vector
{
+7 -9
View File
@@ -1,22 +1,20 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
namespace StgSharp.Math
{
[StructLayout(LayoutKind.Explicit)]
public struct colum2:IEquatable<colum2>
public struct colum2 : IEquatable<colum2>
{
[FieldOffset(0)]
public float X;
[FieldOffset(4)]
public float Y;
public colum2(float x,float y)
public colum2(float x, float y)
{
X= x;
Y= y;
X = x;
Y = y;
}
public override bool Equals(object obj)
@@ -49,7 +47,7 @@ namespace StgSharp.Math
public override int GetHashCode()
{
return HashCode.Combine(X,Y);
return HashCode.Combine(X, Y);
}
public override string ToString()
@@ -57,7 +55,7 @@ namespace StgSharp.Math
return $"{X}\n{Y}";
}
public static colum2 operator +(colum2 c1,colum2 c2)
public static colum2 operator +(colum2 c1, colum2 c2)
{
return new colum2(
c1.X + c2.X,
@@ -75,7 +73,7 @@ namespace StgSharp.Math
public static colum2 operator *(colum2 colum, float x)
{
return new colum2(colum.X * x,colum.Y * x);
return new colum2(colum.X * x, colum.Y * x);
}
public static colum2 operator /(colum2 colum, float x)
-2
View File
@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
namespace StgSharp.Math
{
+1 -4
View File
@@ -1,13 +1,10 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Runtime.InteropServices;
using System.Text;
namespace StgSharp.Math
{
[StructLayout(LayoutKind.Explicit)]
public struct colum4:IEquatable<colum4>
public struct colum4 : IEquatable<colum4>
{
[FieldOffset(0)]
public float X;
+6 -9
View File
@@ -1,13 +1,10 @@
using System;
using System.Collections.Generic;
using System.IO.Compression;
using System.Runtime.InteropServices;
using System.Text;
namespace StgSharp.Math
{
[StructLayout(LayoutKind.Explicit)]
public struct matrix2x2:IEquatable<matrix2x2>
public struct matrix2x2 : IEquatable<matrix2x2>
{
[FieldOffset(0)]
public vec2d row1;
@@ -64,7 +61,7 @@ namespace StgSharp.Math
public override int GetHashCode()
{
return HashCode.Combine(row1,row2);
return HashCode.Combine(row1, row2);
}
public override string ToString()
@@ -72,7 +69,7 @@ namespace StgSharp.Math
return $"{row1}\n{row2}";
}
public static matrix2x2 operator +(matrix2x2 matrix1 , matrix2x2 matrix2)
public static matrix2x2 operator +(matrix2x2 matrix1, matrix2x2 matrix2)
{
return new matrix2x2(
matrix1.row1 + matrix2.row1,
@@ -88,9 +85,9 @@ namespace StgSharp.Math
);
}
}
}
+4 -7
View File
@@ -1,13 +1,10 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Security.Cryptography.X509Certificates;
using System.Text;
namespace StgSharp.Math
{
[StructLayout(LayoutKind.Explicit)]
public struct matrix2x3:IEquatable<matrix2x3>
public struct matrix2x3 : IEquatable<matrix2x3>
{
[FieldOffset(0)]
public vec3d row1;
@@ -63,7 +60,7 @@ namespace StgSharp.Math
}
else
{
return
return
this.row1 == other.row1
&& this.row2 == other.row2;
}
@@ -90,7 +87,7 @@ namespace StgSharp.Math
return new matrix2x3(
array.row1 * x,
array.row2 * x
) ;
);
}
public static matrix2x3 operator /(matrix2x3 array, float x)
@@ -101,7 +98,7 @@ namespace StgSharp.Math
);
}
}
}
+6 -8
View File
@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
namespace StgSharp.Math
{
@@ -14,7 +12,7 @@ namespace StgSharp.Math
[FieldOffset(16)]
public vec4d row2;
public matrix2x4( vec4d r1, vec4d r2)
public matrix2x4(vec4d r1, vec4d r2)
{
row1 = r1;
row2 = r2;
@@ -25,8 +23,8 @@ namespace StgSharp.Math
float a21, float a22, float a23, float a24
)
{
row1 = new vec4d(a11,a12,a13,a14);
row2 = new vec4d(a21,a22,a23,a24);
row1 = new vec4d(a11, a12, a13, a14);
row2 = new vec4d(a21, a22, a23, a24);
}
public bool Equals(matrix2x4 other)
@@ -68,12 +66,12 @@ namespace StgSharp.Math
return $"{this.row1}\n{this.row2}";
}
public static matrix2x4 operator +(matrix2x4 matrix1 ,matrix2x4 matrix2)
public static matrix2x4 operator +(matrix2x4 matrix1, matrix2x4 matrix2)
{
return new matrix2x4(
matrix1.row1 + matrix2.row1,
matrix1.row2 + matrix2.row2
) ;
);
}
public static matrix2x4 operator -(matrix2x4 matrix1, matrix2x4 matrix2)
@@ -100,6 +98,6 @@ namespace StgSharp.Math
);
}
}
}
+5 -7
View File
@@ -1,12 +1,10 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
namespace StgSharp.Math
{
[StructLayout(LayoutKind.Explicit)]
public struct matrix3x2:IEquatable<matrix3x2>
public struct matrix3x2 : IEquatable<matrix3x2>
{
[FieldOffset(0)]
public vec2d row1;
@@ -15,11 +13,11 @@ namespace StgSharp.Math
[FieldOffset(16)]
public vec2d row3;
public matrix3x2(vec2d r1,vec2d r2,vec2d r3)
public matrix3x2(vec2d r1, vec2d r2, vec2d r3)
{
row1= r1;
row2= r2;
row3= r3;
row1 = r1;
row2 = r2;
row3 = r3;
}
public matrix3x2(
+19 -22
View File
@@ -1,13 +1,10 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
namespace StgSharp.Math
{
[StructLayout(LayoutKind.Explicit)]
public struct matrix3x3:IEquatable<matrix3x3>
public struct matrix3x3 : IEquatable<matrix3x3>
{
[FieldOffset(0)]
public vec3d row1;
@@ -16,7 +13,7 @@ namespace StgSharp.Math
[FieldOffset(24)]
public vec3d row3;
public matrix3x3(vec3d r0,vec3d r1,vec3d r2)
public matrix3x3(vec3d r0, vec3d r1, vec3d r2)
{
row1 = r0;
row2 = r1;
@@ -24,9 +21,9 @@ namespace StgSharp.Math
}
public matrix3x3(
float a11,float a12,float a13,
float a21,float a22,float a23,
float a31,float a32,float a33
float a11, float a12, float a13,
float a21, float a22, float a23,
float a31, float a32, float a33
)
{
row1 = new vec3d(a11, a12, a13);
@@ -36,12 +33,12 @@ namespace StgSharp.Math
public override int GetHashCode()
{
return HashCode.Combine(row1,row2,row3);
return HashCode.Combine(row1, row2, row3);
}
bool IEquatable<matrix3x3>.Equals(matrix3x3 other)
{
if (this.GetHashCode()!=other.GetHashCode())
if (this.GetHashCode() != other.GetHashCode())
{
return false;
}
@@ -75,7 +72,7 @@ namespace StgSharp.Math
return $"{row1}\n{row2}\n{row3}";
}
public static bool operator ==(matrix3x3 matrix1, matrix3x3 matrix2)
{
@@ -90,16 +87,16 @@ namespace StgSharp.Math
public static matrix3x3 operator +(matrix3x3 matrix1, matrix3x3 matrix2)
{
return new matrix3x3(
matrix1.row1.X + matrix2.row1.X,
matrix1.row1.Y + matrix2.row1.Y,
matrix1.row1.X + matrix2.row1.X,
matrix1.row1.Y + matrix2.row1.Y,
matrix1.row1.Z + matrix2.row1.Z,
matrix1.row2.X + matrix2.row2.X,
matrix1.row2.Y + matrix2.row2.Y,
matrix1.row2.X + matrix2.row2.X,
matrix1.row2.Y + matrix2.row2.Y,
matrix1.row2.Z + matrix2.row2.Z,
matrix1.row3.X + matrix2.row3.X,
matrix1.row3.Y + matrix2.row3.Y,
matrix1.row3.X + matrix2.row3.X,
matrix1.row3.Y + matrix2.row3.Y,
matrix1.row3.Z + matrix2.row3.Z
);
}
@@ -121,7 +118,7 @@ namespace StgSharp.Math
);
}
public static matrix3x3 operator *(matrix3x3 array, float x)
{
@@ -129,15 +126,15 @@ namespace StgSharp.Math
array.row1 * x,
array.row2 * x,
array.row3 * x
);
);
}
public static matrix3x3 operator /(matrix3x3 array, float x)
{
return new matrix3x3(
array.row1/x,
array.row2/x,
array.row3/x
array.row1 / x,
array.row2 / x,
array.row3 / x
);
}
}
+8 -12
View File
@@ -1,14 +1,10 @@
using StgSharp.Math;
using System;
using System.Collections.Generic;
using System;
using System.Runtime.InteropServices;
using System.Security.Cryptography.X509Certificates;
using System.Text;
namespace StgSharp.Math
{
[StructLayout(LayoutKind.Explicit)]
public struct matrix3x4:IEquatable<matrix3x4>
public struct matrix3x4 : IEquatable<matrix3x4>
{
[FieldOffset(0)]
public vec4d row1;
@@ -18,7 +14,7 @@ namespace StgSharp.Math
public vec4d row3;
public matrix3x4(
vec4d r1,vec4d r2,vec4d r3
vec4d r1, vec4d r2, vec4d r3
)
{
this.row1 = r1;
@@ -32,9 +28,9 @@ namespace StgSharp.Math
float a31, float a32, float a33, float a34
)
{
row1 = new vec4d(a11,a12,a13,a14);
row2 = new vec4d(a21,a22,a23,a24);
row3 = new vec4d(a31,a32,a33,a34);
row1 = new vec4d(a11, a12, a13, a14);
row2 = new vec4d(a21, a22, a23, a24);
row3 = new vec4d(a31, a32, a33, a34);
}
public override bool Equals(object obj)
@@ -69,7 +65,7 @@ namespace StgSharp.Math
public override int GetHashCode()
{
return HashCode.Combine(this.row1,this.row2,this.row3);
return HashCode.Combine(this.row1, this.row2, this.row3);
}
public override string ToString()
@@ -77,7 +73,7 @@ namespace StgSharp.Math
return $"{this.row1}\n{this.row2}\n{this.row3}";
}
}
}
+2 -4
View File
@@ -1,12 +1,10 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
namespace StgSharp.Math
{
[StructLayout(LayoutKind.Explicit)]
public struct matrix4x2:IEquatable<matrix4x2>
public struct matrix4x2 : IEquatable<matrix4x2>
{
[FieldOffset(0)]
public vec2d row1;
@@ -79,6 +77,6 @@ namespace StgSharp.Math
}
}
}
}
+3 -5
View File
@@ -1,13 +1,11 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
namespace StgSharp.Math
{
[StructLayout(LayoutKind.Explicit)]
public struct matrix4x3:IEquatable<matrix4x3>
public struct matrix4x3 : IEquatable<matrix4x3>
{
[FieldOffset(0)]
public vec3d row1;
@@ -41,7 +39,7 @@ namespace StgSharp.Math
{
return false;
}
else
else
{
return this.Equals((matrix4x3)obj);
}
@@ -72,6 +70,6 @@ namespace StgSharp.Math
return base.ToString();
}
}
}
+5 -7
View File
@@ -1,12 +1,10 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
namespace StgSharp.Math
{
[StructLayout(LayoutKind.Explicit)]
public struct matrix4x4:IEquatable<matrix4x4>
public struct matrix4x4 : IEquatable<matrix4x4>
{
[FieldOffset(0)]
public vec4d row1;
@@ -17,7 +15,7 @@ namespace StgSharp.Math
[FieldOffset(48)]
public vec4d row4;
public matrix4x4( vec4d r1,vec4d r2,vec4d r3,vec4d r4)
public matrix4x4(vec4d r1, vec4d r2, vec4d r3, vec4d r4)
{
row1 = r1;
row2 = r2;
@@ -98,10 +96,10 @@ namespace StgSharp.Math
);
}
}
}
+6 -10
View File
@@ -1,22 +1,18 @@
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>
public struct vec2d : IEquatable<vec2d>
{
[FieldOffset(0)]
public float X;
[FieldOffset(sizeof(float))]
public float Y;
public vec2d(float x,float y)
public vec2d(float x, float y)
{
X = x;
Y = y;
@@ -62,7 +58,7 @@ namespace StgSharp.Math
public static bool operator ==(vec2d vec1, vec2d vec2)
{
return vec1.X==vec2.X && vec1.Y==vec2.Y;
return vec1.X == vec2.X && vec1.Y == vec2.Y;
}
public static bool operator !=(vec2d vec1, vec2d vec2)
@@ -87,13 +83,13 @@ namespace StgSharp.Math
public static vec2d operator /(vec2d vec, float x)
{
return new vec2d(vec.X/x, vec.Y/x);
return new vec2d(vec.X / x, vec.Y / x);
}
public static implicit operator float[](vec2d vec)
{
return new float[2] {vec.X,vec.Y };
return new float[2] { vec.X, vec.Y };
}
}
}
+9 -12
View File
@@ -1,12 +1,9 @@
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Runtime.InteropServices;
using System.Text;
namespace StgSharp.Math
{
[StructLayout(LayoutKind.Explicit,Size =12,Pack =16)]
[StructLayout(LayoutKind.Explicit, Size = 12, Pack = 16)]
public struct vec3d : IEquatable<vec3d>
{
[FieldOffset(0)]
@@ -31,7 +28,7 @@ namespace StgSharp.Math
}
else
{
return this.X == other.X
return this.X == other.X
&& this.Y == other.Y
&& this.Z == other.Z;
}
@@ -63,17 +60,17 @@ namespace StgSharp.Math
return $"{X}\t{Y}\t{Z}";
}
public static bool operator ==(vec3d vec1,vec3d vec2)
public static bool operator ==(vec3d vec1, vec3d vec2)
{
return vec1.X == vec2.X
&& vec1.Y == vec2.Y
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
return !(vec1.X == vec2.X
&& vec1.Y == vec2.Y
&& vec1.Z == vec2.Z);
}
@@ -97,7 +94,7 @@ namespace StgSharp.Math
public static float operator *(vec3d vec1, vec3d vec2)
{
return
return
vec1.X * vec2.X
+ vec1.Y + vec2.Y
+ vec1.Z + vec2.Z;
@@ -112,7 +109,7 @@ namespace StgSharp.Math
);
}
public static vec3d operator *( float x, vec3d vec)
public static vec3d operator *(float x, vec3d vec)
{
return new vec3d(
vec.X * x,
+26 -31
View File
@@ -1,15 +1,10 @@
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>
public struct vec4d : IEquatable<vec4d>
{
[FieldOffset(0)]
public float X;
@@ -20,16 +15,16 @@ namespace StgSharp.Math
[FieldOffset(12)]
public float W;
[FieldOffset(0)]
public vec2d Point1;
[FieldOffset(8)]
public vec2d Point2;
public vec4d(float a1,float a2,float a3,float a4)
public vec4d(float a1, float a2, float a3, float a4)
{
Point1= default(vec2d);
Point2= default(vec2d);
Point1 = default(vec2d);
Point2 = default(vec2d);
X = a1;
Y = a2;
@@ -48,34 +43,34 @@ namespace StgSharp.Math
W = (float)a4;
}
public vec4d(vec2d p1,vec2d p2)
public vec4d(vec2d p1, vec2d p2)
{
X= 0;
Y= 0;
X = 0;
Y = 0;
Z = 0;
W = 0;
Point1= p1;
Point1 = p1;
Point2 = p2;
}
public override bool Equals(object obj)
{
if (obj == null)
{
return false;
}
else if(obj.GetType() != typeof( vec4d))
else if (obj.GetType() != typeof(vec4d))
{
return false;
}
else
{
return this == ( vec4d)obj;
return this == (vec4d)obj;
}
}
bool IEquatable< vec4d>.Equals( vec4d other)
bool IEquatable<vec4d>.Equals(vec4d other)
{
if (this.GetHashCode() != other.GetHashCode())
{
@@ -100,19 +95,19 @@ namespace StgSharp.Math
return $"{X}\t{Y}\t{Z}\t{W}";
}
public static bool operator ==( vec4d vec1, vec4d vec2)
public static bool operator ==(vec4d vec1, vec4d vec2)
{
return vec1.Equals(vec2);
}
public static bool operator !=( vec4d vec1, vec4d vec2)
public static bool operator !=(vec4d vec1, vec4d vec2)
{
return !vec1.Equals(vec2);
}
public static vec4d operator +( vec4d vec1, vec4d vec2)
public static vec4d operator +(vec4d vec1, vec4d vec2)
{
return new vec4d(
return new vec4d(
vec1.X + vec2.X,
vec1.Y + vec2.Y,
vec1.Z + vec2.Z,
@@ -120,9 +115,9 @@ namespace StgSharp.Math
);
}
public static vec4d operator -( vec4d vec1, vec4d vec2)
public static vec4d operator -(vec4d vec1, vec4d vec2)
{
return new vec4d(
return new vec4d(
vec1.X - vec2.X,
vec1.Y - vec2.Y,
vec1.Z - vec2.Z,
@@ -130,7 +125,7 @@ namespace StgSharp.Math
);
}
public static float operator *( vec4d vec1, vec4d vec2)
public static float operator *(vec4d vec1, vec4d vec2)
{
return
vec1.X * vec2.X
@@ -139,14 +134,14 @@ namespace StgSharp.Math
+ vec1.W * vec2.W;
}
public static vec4d operator *( vec4d vec, float x)
public static vec4d operator *(vec4d vec, float x)
{
return new vec4d(vec.X * x, vec.Y * x, vec.Z * x, vec.W * x ) ;
return new vec4d(vec.X * x, vec.Y * x, vec.Z * x, vec.W * x);
}
public static vec4d operator /( vec4d vec, float x)
public static vec4d operator /(vec4d vec, float x)
{
return new vec4d(vec.X / x, vec.Y / x, vec.Z / x, vec.W / x);
return new vec4d(vec.X / x, vec.Y / x, vec.Z / x, vec.W / x);
}
public static implicit operator float[](vec4d vec)
+1 -3
View File
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Math
{
@@ -69,7 +67,7 @@ namespace StgSharp.Math
v = y + y * u;
}/**/
v = sign * v ;
v = sign * v;
return piby2 - v;
}
+8 -10
View File
@@ -5,8 +5,6 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Math
@@ -26,13 +24,13 @@ namespace StgSharp.Math
/// <param name="x">The sine value of the angle</param>
/// <returns></returns>
/// <exception cref="ArgumentException"></exception>
public static float ASin(float x )
public static float ASin(float x)
{
int sign = 1;
float y ;
if (x<0)
int sign = 1;
float y;
if (x < 0)
{
sign = -1;
y = -x;
@@ -42,14 +40,14 @@ namespace StgSharp.Math
y = x;
}
if ( x>1)
if (x > 1)
{
throw new ArgumentException();
}
float r, s, u, v = 0.0f;
bool transform = (y >= 0.5f);
if (transform)
{
r = 0.5f * (1.0f - y);
@@ -60,7 +58,7 @@ namespace StgSharp.Math
{
r = y * y;
}
u= r * (0.184161606965100694821398249421F +
u = r * (0.184161606965100694821398249421F +
(-0.0565298683201845211985026327361F +
(-0.0133819288943925804214011424456F -
0.00396137437848476485201154797087F * r) * r) * r) /
+5 -9
View File
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Math
namespace StgSharp.Math
{
public static unsafe partial class Calc
{
@@ -30,7 +26,7 @@ namespace StgSharp.Math
angle = 0.7853981634f;
}
float v = 0.7853981634f * x + x * (1 - x) * (0.2447f+0.0663f * x);
float v = 0.7853981634f * x + x * (1 - x) * (0.2447f + 0.0663f * x);
v += angle;
v *= sign;
@@ -46,10 +42,10 @@ namespace StgSharp.Math
float z = y / x;
float sign = 1, angle = 0,angle2 = 0;
if (x<0)
float sign = 1, angle = 0, angle2 = 0;
if (x < 0)
{
angle = -3.1415926535f ;
angle = -3.1415926535f;
}
if (z < 0)
{
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;
using System.Numerics;
using System.Globalization;
namespace StgSharp.Math
+1 -5
View File
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Math
namespace StgSharp.Math
{
public static partial class Calc
{
+1 -3
View File
@@ -1,13 +1,11 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
namespace StgSharp.Math
{
public unsafe delegate float ScalarCalcHandler(float* x);
public static unsafe partial class Calc
public static unsafe partial class Calc
{
[DllImport("Kernel32.dll", EntryPoint = "VirtualAlloc")]
private static extern IntPtr VirtualAlloc(IntPtr address, int size, uint allocType, uint protect);
+4 -8
View File
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Math
namespace StgSharp.Math
{
public static unsafe partial class Calc
{
@@ -25,14 +21,14 @@ namespace StgSharp.Math
}
bool sign = false;
if (x<0)
if (x < 0)
{
sign = true;
x = -x;
}
float z = x , t;
if (x<0.5f)
float z = x, t;
if (x < 0.5f)
{
t = 1.0f + x * (
1.0f + x * (
+2 -6
View File
@@ -1,12 +1,8 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Math
namespace StgSharp.Math
{
public class Function
{
}
}
+9 -13
View File
@@ -1,15 +1,11 @@
using System;
using System.Collections.Generic;
using System.Net.Sockets;
using System.Text;
using static System.Net.WebRequestMethods;
namespace StgSharp.Math
{
public static partial class Calc
{
static private readonly float[] logArray =
private static readonly float[] logArray =
{
0f, 0.00995033085316809f, 0.0198026272961797f, 0.0295588022415444f, 0.0392207131532813f, 0.048790164169432f, 0.0582689081239758f, 0.0676586484738149f, 0.0769610411361284f, 0.0861776962410524f,
0.0953101798043249f, 0.104360015324243f, 0.113328685307003f, 0.122217632724249f, 0.131028262406404f, 0.139761942375159f, 0.148420005118273f, 0.157003748809665f, 0.165514438477573f, 0.173953307123438f,
@@ -30,9 +26,9 @@ namespace StgSharp.Math
/// <returns>
/// Returns the value of ln(x).
/// </returns>
public unsafe static float Log(float x)
public static unsafe float Log(float x)
{
if (x<0)
if (x < 0)
{
throw new ArgumentOutOfRangeException();
}
@@ -45,24 +41,24 @@ namespace StgSharp.Math
input >>= 9;
input += 0b_0011_1111_1000_0000_0000_0000_0000_0000;
float result = *(float*)&input;
int order = (int)(result * 100)-100;
int order = (int)(result * 100) - 100;
float cache = (result) / (1f + 0.01f * order) -1 ;
float cache = (result) / (1f + 0.01f * order) - 1;
result = cache * -0.25f + 0.3333333333333f;
result = result * cache - 0.5f;
result = result * cache + 1.0f;
result *= cache;
return
f*0.6931471806f +
result +
return
f * 0.6931471806f +
result +
logArray[order];
}
public static float Log(float x, float y)
{
return Log(x)/Log(y);
return Log(x) / Log(y);
}
+5 -9
View File
@@ -1,9 +1,5 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Math
{
namespace StgSharp.Math
{
public static unsafe partial class Calc
{
/// <summary>
@@ -31,7 +27,7 @@ namespace StgSharp.Math
{
return 1;
}
if (x==1&&y==0)
if (x == 1 && y == 0)
{
return 1.0f / 0;
}
@@ -44,7 +40,7 @@ namespace StgSharp.Math
z = -z;
}
if (z<0.5f)
if (z < 0.5f)
{
t = 1.0f + z * (
1.0f + z * (
@@ -77,7 +73,7 @@ namespace StgSharp.Math
t = t * t;
}
}
if (sign)
{
+2 -6
View File
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Math
namespace StgSharp.Math
{
public static partial class Calc
{
@@ -45,7 +41,7 @@ namespace StgSharp.Math
float refer2 = refer * refer;
return sinData[a]*(1 - 0.0123370055f * refer2 + 2.536695709e-5f * refer2 * refer2 )
return sinData[a] * (1 - 0.0123370055f * refer2 + 2.536695709e-5f * refer2 * refer2)
+ cosData[a] * (0.1570796327f * refer - 6.459640975e-4f * refer * refer2);
}
}
-1
View File
@@ -1,5 +1,4 @@
using System;
using System.Runtime.InteropServices;
namespace StgSharp.Math
{
+3 -7
View File
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Math
namespace StgSharp.Math
{
public static partial class Calc
{
@@ -21,8 +17,8 @@ namespace StgSharp.Math
float sin = (0.1570796327f * refer - 6.459640975e-4f * refer * refer2);
float cos = (1 - 0.0123370055f * refer2 + 2.536695709e-5f * refer2 * refer2);
return ( sinData[a] * cos + cosData[a] * sin )
/ ( cosData[a] * cos - sinData[a] * sin );
return (sinData[a] * cos + cosData[a] * sin)
/ (cosData[a] * cos - sinData[a] * sin);
}
}
}