daily update on 20230320 by nitload youmu
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
internal class Cordination
|
||||
{
|
||||
}
|
||||
|
||||
public enum CordinatePlain
|
||||
{
|
||||
XY,
|
||||
YZ,
|
||||
XZ,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
public static unsafe partial class Vector
|
||||
{
|
||||
|
||||
public static float Det(matrix2x2 array)
|
||||
{
|
||||
return Cross(array.row1,array.row2);
|
||||
}
|
||||
|
||||
public static unsafe float Det(matrix3x3 array)
|
||||
{
|
||||
float* p = &array.row1.X;
|
||||
|
||||
matrix2x2 matrix1 = new matrix2x2(
|
||||
*(p + 4), *(p + 5),
|
||||
*(p + 7), *(p + 8)
|
||||
);
|
||||
matrix2x2 matrix2 = new matrix2x2(
|
||||
*(p + 3), *(p + 5),
|
||||
*(p + 6), *(p + 8)
|
||||
);
|
||||
matrix2x2 matrix3 = new matrix2x2(
|
||||
*(p + 3), *(p + 4),
|
||||
*(p + 6), *(p + 7)
|
||||
);
|
||||
|
||||
return
|
||||
*p * Det(matrix1)
|
||||
- *(p + 1) * Det(matrix2)
|
||||
+ *(p + 2) * Det(matrix3)
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
public static unsafe partial class Vector
|
||||
{
|
||||
public static float GetAngle(vec2d vec1, vec2d vec2)
|
||||
{
|
||||
return Calc.ACos(
|
||||
vec1 .multiple(vec2)
|
||||
/ (vec1.GetLength() * vec2.GetLength())
|
||||
);
|
||||
}
|
||||
|
||||
public static float GetAngle(vec3d vec1, vec3d vec2)
|
||||
{
|
||||
return Calc.ACos(
|
||||
vec1 * vec2
|
||||
/ (vec1.GetLength() * vec2.GetLength())
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
public static unsafe partial class Vector
|
||||
{
|
||||
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
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
public static unsafe partial class Vector
|
||||
{
|
||||
/*
|
||||
public static vec2d GetVector( vec4d pointPair)
|
||||
{
|
||||
return pointPair.Point2-pointPair.Point1;
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
public static unsafe partial class Vector
|
||||
{
|
||||
public static vec3d To3D(this vec2d vec)
|
||||
{
|
||||
return new vec3d(vec.X, vec.Y, 0.0f);
|
||||
}
|
||||
|
||||
public static vec4d To4D(this vec2d Vec)
|
||||
{
|
||||
return new vec4d(Vec.X, Vec.Y, 0, 0);
|
||||
}
|
||||
|
||||
public static vec4d To4D(this vec3d vec)
|
||||
{
|
||||
return new vec4d(vec.X, vec.Y, vec.Z, 0);
|
||||
}
|
||||
|
||||
public static vec2d To2D(vec3d vec, CordinatePlain plain)
|
||||
{
|
||||
switch (plain)
|
||||
{
|
||||
case CordinatePlain.XY:
|
||||
return new vec2d(vec.X, vec.Y);
|
||||
break;
|
||||
case CordinatePlain.YZ:
|
||||
return new vec2d(vec.Y, vec.Z);
|
||||
break;
|
||||
case CordinatePlain.XZ:
|
||||
return new vec2d(vec.X, vec.Z);
|
||||
break;
|
||||
default:
|
||||
return default(vec2d);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
public static unsafe partial class Vector
|
||||
{
|
||||
|
||||
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
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
public struct colum2:IEquatable<colum2>
|
||||
{
|
||||
[FieldOffset(0)]
|
||||
public float X;
|
||||
[FieldOffset(4)]
|
||||
public float Y;
|
||||
|
||||
public colum2(float x,float y)
|
||||
{
|
||||
X= x;
|
||||
Y= y;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (obj.GetType() != typeof(colum2))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.Equals((colum2)obj);
|
||||
}
|
||||
}
|
||||
|
||||
bool IEquatable<colum2>.Equals(colum2 other)
|
||||
{
|
||||
if (this.GetHashCode() != other.GetHashCode())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return X == other.X && Y == other.Y;
|
||||
}
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(X,Y);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{X}\n{Y}";
|
||||
}
|
||||
|
||||
public static colum2 operator +(colum2 c1,colum2 c2)
|
||||
{
|
||||
return new colum2(
|
||||
c1.X + c2.X,
|
||||
c1.Y + c2.Y
|
||||
);
|
||||
}
|
||||
|
||||
public static colum2 operator -(colum2 c1, colum2 c2)
|
||||
{
|
||||
return new colum2(
|
||||
c1.X - c2.X,
|
||||
c1.Y - c2.Y
|
||||
);
|
||||
}
|
||||
|
||||
public static colum2 operator *(colum2 colum, float x)
|
||||
{
|
||||
return new colum2(colum.X * x,colum.Y * x);
|
||||
}
|
||||
|
||||
public static colum2 operator /(colum2 colum, float x)
|
||||
{
|
||||
return new colum2(colum.X / x, colum.Y / x);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
public struct colum3 : IEquatable<colum3>
|
||||
{
|
||||
[FieldOffset(0)]
|
||||
public float X;
|
||||
[FieldOffset(4)]
|
||||
public float Y;
|
||||
[FieldOffset(8)]
|
||||
public float Z;
|
||||
|
||||
public colum3(float x, float y, float z)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
Z = z;
|
||||
}
|
||||
|
||||
bool IEquatable<colum3>.Equals(colum3 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(colum3))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.Equals((colum3)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 ==(colum3 vec1, colum3 vec2)
|
||||
{
|
||||
return vec1.X == vec2.X
|
||||
&& vec1.Y == vec2.Y
|
||||
&& vec1.Z == vec2.Z;
|
||||
}
|
||||
|
||||
public static bool operator !=(colum3 vec1, colum3 vec2)
|
||||
{
|
||||
return !(vec1.X == vec2.X
|
||||
&& vec1.Y == vec2.Y
|
||||
&& vec1.Z == vec2.Z);
|
||||
}
|
||||
|
||||
public static colum3 operator +(colum3 vec1, colum3 vec2)
|
||||
{
|
||||
return new colum3(
|
||||
vec1.X + vec2.X,
|
||||
vec1.Y + vec2.Y,
|
||||
vec1.Z + vec2.Z
|
||||
);
|
||||
}
|
||||
|
||||
public static colum3 operator -(colum3 vec1, colum3 vec2)
|
||||
{
|
||||
return new colum3(
|
||||
vec1.X - vec2.X,
|
||||
vec1.Y - vec2.Y,
|
||||
vec1.Z - vec2.Z
|
||||
);
|
||||
}
|
||||
|
||||
public static float operator *(colum3 vec1, colum3 vec2)
|
||||
{
|
||||
return
|
||||
vec1.X * vec2.X
|
||||
+ vec1.Y + vec2.Y
|
||||
+ vec1.Z + vec2.Z;
|
||||
}
|
||||
|
||||
public static colum3 operator *(colum3 vec, float x)
|
||||
{
|
||||
return new colum3(
|
||||
vec.X * x,
|
||||
vec.Y * x,
|
||||
vec.Z * x
|
||||
);
|
||||
}
|
||||
|
||||
public static colum3 operator /(colum3 vec, float x)
|
||||
{
|
||||
return new colum3(
|
||||
vec.X / x,
|
||||
vec.Y / x,
|
||||
vec.Z / x
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
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>
|
||||
{
|
||||
[FieldOffset(0)]
|
||||
public float X;
|
||||
[FieldOffset(4)]
|
||||
public float Y;
|
||||
[FieldOffset(8)]
|
||||
public float Z;
|
||||
[FieldOffset(12)]
|
||||
public float W;
|
||||
|
||||
public colum4(float x, float y, float z, float w)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
Z = z;
|
||||
W = w;
|
||||
}
|
||||
|
||||
public bool Equals(colum4 other)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return base.Equals(obj);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return base.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
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>
|
||||
{
|
||||
[FieldOffset(0)]
|
||||
public vec2d row1;
|
||||
[FieldOffset(8)]
|
||||
public vec2d row2;
|
||||
|
||||
|
||||
public matrix2x2(vec2d c0, vec2d c1)
|
||||
{
|
||||
row1 = c0;
|
||||
row2 = c1;
|
||||
}
|
||||
|
||||
public matrix2x2(
|
||||
float a11,
|
||||
float a12,
|
||||
float a21,
|
||||
float a22
|
||||
)
|
||||
{
|
||||
row1 = new vec2d(a11, a12);
|
||||
row2 = new vec2d(a21, a22);
|
||||
}
|
||||
|
||||
bool IEquatable<matrix2x2>.Equals(matrix2x2 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(matrix2x2))
|
||||
{
|
||||
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}";
|
||||
}
|
||||
|
||||
public static matrix2x2 operator +(matrix2x2 matrix1 , matrix2x2 matrix2)
|
||||
{
|
||||
return new matrix2x2(
|
||||
matrix1.row1 + matrix2.row1,
|
||||
matrix1.row2 + matrix2.row2
|
||||
);
|
||||
}
|
||||
|
||||
public static matrix2x2 operator -(matrix2x2 matrix1, matrix2x2 matrix2)
|
||||
{
|
||||
return new matrix2x2(
|
||||
matrix1.row1 - matrix2.row1,
|
||||
matrix1.row2 - matrix2.row2
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
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>
|
||||
{
|
||||
[FieldOffset(0)]
|
||||
public vec3d row1;
|
||||
[FieldOffset(12)]
|
||||
public vec3d row2;
|
||||
|
||||
public matrix2x3(vec3d r1, vec3d r2)
|
||||
{
|
||||
row1 = r1;
|
||||
row2 = r2;
|
||||
}
|
||||
|
||||
public matrix2x3(
|
||||
float r11, float r12, float r13,
|
||||
float r21, float r22, float r23
|
||||
)
|
||||
{
|
||||
row1 = new vec3d(r11, r12, r13);
|
||||
row2 = new vec3d(r21, r22, r23);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (obj.GetType() != typeof(matrix2x3))
|
||||
{
|
||||
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<matrix2x3>.Equals(matrix2x3 other)
|
||||
{
|
||||
if (this.GetHashCode() != other.GetHashCode())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return
|
||||
this.row1 == other.row1
|
||||
&& this.row2 == other.row2;
|
||||
}
|
||||
}
|
||||
|
||||
public static matrix2x3 operator +(matrix2x3 matrix1, matrix2x3 matrix2)
|
||||
{
|
||||
return new matrix2x3(
|
||||
matrix1.row1 + matrix2.row1,
|
||||
matrix1.row2 + matrix2.row2
|
||||
);
|
||||
}
|
||||
|
||||
public static matrix2x3 operator -(matrix2x3 matrix1, matrix2x3 matrix2)
|
||||
{
|
||||
return new matrix2x3(
|
||||
matrix1.row1 - matrix2.row1,
|
||||
matrix1.row2 - matrix2.row2
|
||||
);
|
||||
}
|
||||
|
||||
public static matrix2x3 operator *(matrix2x3 array, float x)
|
||||
{
|
||||
return new matrix2x3(
|
||||
array.row1 * x,
|
||||
array.row2 * x
|
||||
) ;
|
||||
}
|
||||
|
||||
public static matrix2x3 operator /(matrix2x3 array, float x)
|
||||
{
|
||||
return new matrix2x3(
|
||||
array.row1 / x,
|
||||
array.row2 / x
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
public struct matrix2x4 : IEquatable<matrix2x4>
|
||||
{
|
||||
[FieldOffset(0)]
|
||||
public vec4d row1;
|
||||
[FieldOffset(16)]
|
||||
public vec4d row2;
|
||||
|
||||
public matrix2x4( vec4d r1, vec4d r2)
|
||||
{
|
||||
row1 = r1;
|
||||
row2 = r2;
|
||||
}
|
||||
|
||||
public matrix2x4(
|
||||
float a11, float a12, float a13, float a14,
|
||||
float a21, float a22, float a23, float a24
|
||||
)
|
||||
{
|
||||
row1 = new vec4d(a11,a12,a13,a14);
|
||||
row2 = new vec4d(a21,a22,a23,a24);
|
||||
}
|
||||
|
||||
public bool Equals(matrix2x4 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(matrix2x4))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.Equals((matrix2x4)obj);
|
||||
}
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(this.row1, this.row2);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{this.row1}\n{this.row2}";
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
return new matrix2x4(
|
||||
matrix1.row1 - matrix2.row1,
|
||||
matrix1.row2 - matrix2.row2
|
||||
);
|
||||
}
|
||||
|
||||
public static matrix2x4 operator *(matrix2x4 array, float x)
|
||||
{
|
||||
return new matrix2x4(
|
||||
array.row1 * x,
|
||||
array.row2 * x
|
||||
);
|
||||
}
|
||||
|
||||
public static matrix2x4 operator /(matrix2x4 array, float x)
|
||||
{
|
||||
return new matrix2x4(
|
||||
array.row1 / x,
|
||||
array.row2 / x
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
public struct matrix3x2:IEquatable<matrix3x2>
|
||||
{
|
||||
[FieldOffset(0)]
|
||||
public vec2d row1;
|
||||
[FieldOffset(8)]
|
||||
public vec2d row2;
|
||||
[FieldOffset(16)]
|
||||
public vec2d row3;
|
||||
|
||||
public matrix3x2(vec2d r1,vec2d r2,vec2d r3)
|
||||
{
|
||||
row1= r1;
|
||||
row2= r2;
|
||||
row3= r3;
|
||||
}
|
||||
|
||||
public matrix3x2(
|
||||
float a11, float a12,
|
||||
float a21, float a22,
|
||||
float a31, float a32
|
||||
)
|
||||
{
|
||||
row1 = new vec2d(a11, a12);
|
||||
row2 = new vec2d(a21, a22);
|
||||
row3 = new vec2d(a31, a32);
|
||||
}
|
||||
|
||||
bool IEquatable<matrix3x2>.Equals(matrix3x2 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(matrix3x2))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.Equals((matrix3x2)obj);
|
||||
}
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(row1, row2, row3);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{row1}\n{row2}\n{row3}";
|
||||
}
|
||||
|
||||
public static matrix3x2 operator +(matrix3x2 matrix1, matrix3x2 matrix2)
|
||||
{
|
||||
return new matrix3x2(
|
||||
matrix1.row1 + matrix2.row1,
|
||||
matrix1.row2 + matrix2.row2,
|
||||
matrix1.row3 + matrix2.row3
|
||||
);
|
||||
}
|
||||
|
||||
public static matrix3x2 operator -(matrix3x2 matrix1, matrix3x2 matrix2)
|
||||
{
|
||||
return new matrix3x2(
|
||||
matrix1.row1 - matrix2.row1,
|
||||
matrix1.row2 - matrix2.row2,
|
||||
matrix1.row3 - matrix2.row3
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
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>
|
||||
{
|
||||
[FieldOffset(0)]
|
||||
public vec3d row1;
|
||||
[FieldOffset(12)]
|
||||
public vec3d row2;
|
||||
[FieldOffset(24)]
|
||||
public vec3d row3;
|
||||
|
||||
public matrix3x3(vec3d r0,vec3d r1,vec3d r2)
|
||||
{
|
||||
row1 = r0;
|
||||
row2 = r1;
|
||||
row3 = r2;
|
||||
}
|
||||
|
||||
public matrix3x3(
|
||||
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<matrix3x3>.Equals(matrix3x3 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(matrix3x3))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.Equals((matrix3x3)obj);
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{row1}\n{row2}\n{row3}";
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static bool operator ==(matrix3x3 matrix1, matrix3x3 matrix2)
|
||||
{
|
||||
return matrix1.Equals(matrix2);
|
||||
}
|
||||
|
||||
public static bool operator !=(matrix3x3 matrix1, matrix3x3 matrix2)
|
||||
{
|
||||
return !matrix1.Equals(matrix2);
|
||||
}
|
||||
|
||||
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.Z + matrix2.row1.Z,
|
||||
|
||||
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.Z + matrix2.row3.Z
|
||||
);
|
||||
}
|
||||
|
||||
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.Z - matrix2.row1.Z,
|
||||
|
||||
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.Z - matrix2.row3.Z
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static matrix3x3 operator *(matrix3x3 array, float x)
|
||||
{
|
||||
return new matrix3x3(
|
||||
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
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
using StgSharp.Math;
|
||||
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 matrix3x4:IEquatable<matrix3x4>
|
||||
{
|
||||
[FieldOffset(0)]
|
||||
public vec4d row1;
|
||||
[FieldOffset(16)]
|
||||
public vec4d row2;
|
||||
[FieldOffset(32)]
|
||||
public vec4d row3;
|
||||
|
||||
public matrix3x4(
|
||||
vec4d r1,vec4d r2,vec4d r3
|
||||
)
|
||||
{
|
||||
this.row1 = r1;
|
||||
this.row2 = r2;
|
||||
this.row3 = r3;
|
||||
}
|
||||
|
||||
public matrix3x4(
|
||||
float a11, float a12, float a13, float a14,
|
||||
float a21, float a22, float a23, float a24,
|
||||
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);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (obj.GetType() != typeof(matrix3x4))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.Equals((matrix3x4)obj);
|
||||
}
|
||||
}
|
||||
|
||||
bool IEquatable<matrix3x4>.Equals(matrix3x4 other)
|
||||
{
|
||||
if (this.GetHashCode() != other.GetHashCode())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.row1 == other.row1
|
||||
&& this.row2 == other.row2
|
||||
&& this.row3 == other.row3;
|
||||
}
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(this.row1,this.row2,this.row3);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{this.row1}\n{this.row2}\n{this.row3}";
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
public struct matrix4x2:IEquatable<matrix4x2>
|
||||
{
|
||||
[FieldOffset(0)]
|
||||
public vec2d row1;
|
||||
[FieldOffset(8)]
|
||||
public vec2d row2;
|
||||
[FieldOffset(16)]
|
||||
public vec2d row3;
|
||||
[FieldOffset(24)]
|
||||
public vec2d row4;
|
||||
|
||||
public matrix4x2(vec2d r1, vec2d r2, vec2d r3, vec2d r4)
|
||||
{
|
||||
row1 = r1;
|
||||
row2 = r2;
|
||||
row3 = r3;
|
||||
row4 = r4;
|
||||
}
|
||||
|
||||
public matrix4x2(
|
||||
float a11, float a12,
|
||||
float a21, float a22,
|
||||
float a31, float a32,
|
||||
float a41, float a42
|
||||
)
|
||||
{
|
||||
row1 = new vec2d(a11, a12);
|
||||
row2 = new vec2d(a21, a22);
|
||||
row3 = new vec2d(a31, a32);
|
||||
row4 = new vec2d(a41, a42);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (obj.GetType() == typeof(matrix4x2))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.Equals((matrix4x2)obj);
|
||||
}
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(row1, row2, row3, row4);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{row1}\n{row2}\n{row3}\n{row4}";
|
||||
}
|
||||
|
||||
bool IEquatable<matrix4x2>.Equals(matrix4x2 other)
|
||||
{
|
||||
if (this.GetHashCode() != other.GetHashCode())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.row1 == other.row1
|
||||
&& this.row2 == other.row2
|
||||
&& this.row3 == other.row3
|
||||
&& this.row4 == other.row4;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
public struct matrix4x3:IEquatable<matrix4x3>
|
||||
{
|
||||
[FieldOffset(0)]
|
||||
public vec3d row1;
|
||||
[FieldOffset(12)]
|
||||
public vec3d row2;
|
||||
[FieldOffset(24)]
|
||||
public vec3d row3;
|
||||
[FieldOffset(36)]
|
||||
public vec3d row4;
|
||||
|
||||
public matrix4x3(
|
||||
float a11, float a12, float a13,
|
||||
float a21, float a22, float a23,
|
||||
float a31, float a32, float a33,
|
||||
float a41, float a42, float a43
|
||||
)
|
||||
{
|
||||
row1 = new vec3d(a11, a12, a13);
|
||||
row2 = new vec3d(a21, a22, a23);
|
||||
row3 = new vec3d(a31, a32, a33);
|
||||
row4 = new vec3d(a41, a42, a43);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (obj.GetType() != typeof(matrix4x3))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.Equals((matrix4x3)obj);
|
||||
}
|
||||
}
|
||||
|
||||
bool IEquatable<matrix4x3>.Equals(matrix4x3 other)
|
||||
{
|
||||
if (this.GetHashCode() != other.GetHashCode())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.row1 == other.row1
|
||||
&& this.row2 == other.row2
|
||||
&& this.row3 == other.row3
|
||||
&& this.row4 == other.row4;
|
||||
}
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return base.ToString();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
public struct matrix4x4:IEquatable<matrix4x4>
|
||||
{
|
||||
[FieldOffset(0)]
|
||||
public vec4d row1;
|
||||
[FieldOffset(16)]
|
||||
public vec4d row2;
|
||||
[FieldOffset(32)]
|
||||
public vec4d row3;
|
||||
[FieldOffset(48)]
|
||||
public vec4d row4;
|
||||
|
||||
public matrix4x4( vec4d r1,vec4d r2,vec4d r3,vec4d r4)
|
||||
{
|
||||
row1 = r1;
|
||||
row2 = r2;
|
||||
row3 = r3;
|
||||
row4 = r4;
|
||||
}
|
||||
|
||||
public matrix4x4(
|
||||
float a11, float a12, float a13, float a14,
|
||||
float a21, float a22, float a23, float a24,
|
||||
float a31, float a32, float a33, float a34,
|
||||
float a41, float a42, float a43, float a44
|
||||
)
|
||||
{
|
||||
row1 = new vec4d(a11, a12, a13, a14);
|
||||
row2 = new vec4d(a21, a22, a23, a24);
|
||||
row3 = new vec4d(a31, a32, a33, a34);
|
||||
row4 = new vec4d(a41, a42, a43, a44);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return base.Equals(obj);
|
||||
}
|
||||
|
||||
bool IEquatable<matrix4x4>.Equals(matrix4x4 other)
|
||||
{
|
||||
if (this.GetHashCode() != other.GetHashCode())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.row1 == other.row1
|
||||
&& this.row2 == other.row2
|
||||
&& this.row3 == other.row3
|
||||
&& this.row4 == other.row4;
|
||||
}
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(row1, row2, row3, row4);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{this.row1}\n{this.row2}\n{this.row3}\n{this.row4}";
|
||||
}
|
||||
|
||||
public static matrix4x4 operator +(matrix4x4 matrix1, matrix4x4 matrix2)
|
||||
{
|
||||
return new matrix4x4(
|
||||
matrix1.row1 + matrix2.row1,
|
||||
matrix1.row2 + matrix2.row2,
|
||||
matrix1.row3 + matrix2.row3,
|
||||
matrix1.row4 + matrix2.row4
|
||||
);
|
||||
}
|
||||
|
||||
public static matrix4x4 operator -(matrix4x4 matrix1, matrix4x4 matrix2)
|
||||
{
|
||||
return new matrix4x4(
|
||||
matrix1.row1 - matrix2.row1,
|
||||
matrix1.row2 - matrix2.row2,
|
||||
matrix1.row3 - matrix2.row3,
|
||||
matrix1.row4 - matrix2.row4
|
||||
);
|
||||
}
|
||||
|
||||
public static matrix4x4 operator *(matrix4x4 array, float x)
|
||||
{
|
||||
return new matrix4x4(
|
||||
array.row1 * x,
|
||||
array.row2 * x,
|
||||
array.row3 * x,
|
||||
array.row4 * x
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
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 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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
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 a1,float a2,float a3,float a4)
|
||||
{
|
||||
Point1= default(vec2d);
|
||||
Point2= default(vec2d);
|
||||
|
||||
X = a1;
|
||||
Y = a2;
|
||||
Z = a3;
|
||||
W = a4;
|
||||
}
|
||||
|
||||
public vec4d(vec2d p1,vec2d p2)
|
||||
{
|
||||
X= 0;
|
||||
Y= 0;
|
||||
Z = 0;
|
||||
W = 0;
|
||||
|
||||
Point1= p1;
|
||||
Point2 = p2;
|
||||
}
|
||||
|
||||
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.X == other.X
|
||||
&& this.Y == other.Y
|
||||
&& this.Z == other.Z
|
||||
&& this.W == other.Z;
|
||||
}
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(X, Y, Z, W);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{X}\t{Y}\t{Z}\t{W}";
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user