daily update on 20240209 by nitload youmu
This commit is contained in:
@@ -4,12 +4,10 @@ using System.Runtime.InteropServices;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// A two dimension vector defined by two elements.
|
||||
/// Vec2Ds in StgSharp are defaultly usaed as colum vector.
|
||||
/// </summary>
|
||||
|
||||
[StructLayout(LayoutKind.Explicit, Size = 16, Pack = 16)]
|
||||
public struct Vec2d
|
||||
{
|
||||
@@ -21,10 +19,17 @@ namespace StgSharp.Math
|
||||
|
||||
[FieldOffset(0)]
|
||||
internal Vector4 vec;
|
||||
[FieldOffset(0)]
|
||||
internal Vector2 v;
|
||||
|
||||
public Vec2d(float x, float y)
|
||||
{
|
||||
X = x; Y = y;
|
||||
v = new Vector2(x, y);
|
||||
}
|
||||
|
||||
internal Vec2d(Vector2 vec)
|
||||
{
|
||||
v = vec;
|
||||
}
|
||||
|
||||
public static Vec2d Zero
|
||||
@@ -32,43 +37,36 @@ namespace StgSharp.Math
|
||||
get { return new Vec2d(0, 0); }
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Vec2d operator +(Vec2d vec1, Vec2d vec2)
|
||||
public static Vec2d Unit
|
||||
{
|
||||
return new Vec2d(
|
||||
vec1.X + vec2.X,
|
||||
vec1.Y + vec2.Y
|
||||
);
|
||||
get { return new Vec2d(1, 1); }
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Vec2d operator -(Vec2d vec1, Vec2d vec2)
|
||||
public static Vec2d operator +(Vec2d left, Vec2d right)
|
||||
{
|
||||
return new Vec2d(
|
||||
vec1.X - vec2.X,
|
||||
vec1.Y - vec2.Y
|
||||
);
|
||||
return new Vec2d(left.v + right.v);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Vec2d operator -(Vec2d left, Vec2d right)
|
||||
{
|
||||
return new Vec2d(left.v - right.v);
|
||||
}
|
||||
|
||||
public static Vec2d operator *(Vec2d vec, float value)
|
||||
{
|
||||
return new Vec2d(
|
||||
vec.X * value,
|
||||
vec.Y * value
|
||||
);
|
||||
return new Vec2d(vec.v * value);
|
||||
}
|
||||
|
||||
public static Vec2d operator /(Vec2d vec, float value)
|
||||
{
|
||||
return new Vec2d(
|
||||
vec.X / value,
|
||||
vec.Y / value
|
||||
);
|
||||
return new Vec2d(vec.v / value);
|
||||
}
|
||||
|
||||
public static bool operator ==(Vec2d left, Vec2d right)
|
||||
{
|
||||
return left.X == right.X && left.Y == right.Y;
|
||||
return left.v == right.v;
|
||||
}
|
||||
|
||||
public static bool operator !=(Vec2d left, Vec2d right)
|
||||
|
||||
@@ -3,6 +3,7 @@ using System;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security.AccessControl;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
@@ -11,6 +12,8 @@ namespace StgSharp.Math
|
||||
{
|
||||
[FieldOffset(0)]
|
||||
internal Vector4 vec;
|
||||
[FieldOffset(0)]
|
||||
internal Vector3 v;
|
||||
|
||||
[FieldOffset(0)] public float X;
|
||||
[FieldOffset(4)] public float Y;
|
||||
@@ -28,7 +31,7 @@ namespace StgSharp.Math
|
||||
#if NET5_0_OR_GREATER
|
||||
Unsafe.SkipInit(out vec);
|
||||
#endif
|
||||
X = x; Y = y; Z = z;
|
||||
v = new Vector3(x, y, z);
|
||||
}
|
||||
|
||||
internal vec3d(Vector4 vector)
|
||||
@@ -36,6 +39,11 @@ namespace StgSharp.Math
|
||||
vec = vector;
|
||||
}
|
||||
|
||||
internal vec3d(Vector3 vector)
|
||||
{
|
||||
v = vector;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public float Dot(vec3d right)
|
||||
{
|
||||
@@ -76,61 +84,42 @@ namespace StgSharp.Math
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static vec3d operator -(vec3d left, vec3d right)
|
||||
{
|
||||
return new vec3d(
|
||||
left.X - right.X,
|
||||
left.Y - right.Y,
|
||||
left.Z - right.Z
|
||||
);
|
||||
return new vec3d(left.v - right.v);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static vec3d operator *(vec3d vec, float value)
|
||||
{
|
||||
return new vec3d(
|
||||
vec.X * value,
|
||||
vec.Y * value,
|
||||
vec.Z * value
|
||||
);
|
||||
return new vec3d(vec.v * value);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static vec3d operator /(vec3d vec, float value)
|
||||
{
|
||||
return new vec3d(
|
||||
vec.X / value,
|
||||
vec.Y / value,
|
||||
vec.Z / value
|
||||
);
|
||||
return new vec3d(vec.v / value);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float operator *(vec3d left, vec3d right)
|
||||
{
|
||||
return
|
||||
left.X * right.X +
|
||||
left.Y * right.Y +
|
||||
left.Z * right.Z;
|
||||
return Vector3.Dot(left.v, right.v);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator ==(vec3d left, vec3d right)
|
||||
{
|
||||
return left.X == right.X
|
||||
&& left.Y == right.Y
|
||||
&& left.Z == right.Z;
|
||||
return left.v == right.v;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator !=(vec3d left, vec3d right)
|
||||
{
|
||||
return left.X != right.X
|
||||
&& left.Y != right.Y
|
||||
&& left.Z != right.Z;
|
||||
return left.v != right.v;
|
||||
}
|
||||
|
||||
public string ToString(string sample)
|
||||
{
|
||||
return $"{this.X}\t{this.Y}\t{this.Z}\t";
|
||||
return $"[{X.ToString(sample)},{Y.ToString(sample)},{Z.ToString(sample)}]";
|
||||
}
|
||||
|
||||
public bool Equals(vec3d other)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using StgSharp.Controlling;
|
||||
using StgSharp.Math;
|
||||
using System;
|
||||
using System.Data.Common;
|
||||
using System.Numerics;
|
||||
using System.Runtime.InteropServices;
|
||||
@@ -39,10 +40,10 @@ namespace StgSharp.Math
|
||||
[FieldOffset(8)] public float Z;
|
||||
[FieldOffset(12)] public float W;
|
||||
|
||||
public Vec4d(
|
||||
float x, float y, float z, float w)
|
||||
|
||||
public Vec4d(float x, float y, float z, float w)
|
||||
{
|
||||
X = x; Y = y; Z = z; W = w;
|
||||
vec = new Vector4(x, y, z, w);
|
||||
}
|
||||
|
||||
public static implicit operator M128(Vec4d vec)
|
||||
|
||||
Reference in New Issue
Block a user