Wer weiß, was ich alles so gemacht hatte...

- Fixed crash caused by early ScriptEngine shutdown
This commit is contained in:
Simon Lübeß
2023-05-30 16:50:22 +02:00
parent ef5e4ba64f
commit 5855b13873
12 changed files with 310 additions and 80 deletions
+64
View File
@@ -1,4 +1,5 @@
using System;
using System.Runtime.CompilerServices;
namespace GlitchyEngine.Math;
@@ -50,4 +51,67 @@ public struct Vector2
}
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector2 operator +(in Vector2 a, in Vector2 b) => new(a.X + b.X, a.Y + b.Y);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector2 operator +(float a, in Vector2 b) => new(a + b.X, a + b.Y);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector2 operator +(in Vector2 a, float b) => new(a.X + b, a.Y + b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector2 operator +(in Vector2 a) => a;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector2 operator -(in Vector2 a, in Vector2 b) => new(a.X - b.X, a.Y - b.Y);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector2 operator -(float a, in Vector2 b) => new(a - b.X, a - b.Y);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector2 operator -(in Vector2 a, float b) => new(a.X - b, a.Y - b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector2 operator -(in Vector2 a) => new Vector2(-a.X, -a.Y);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector2 operator *(in Vector2 a, in Vector2 b) => new(a.X * b.X, a.Y * b.Y);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector2 operator *(float a, in Vector2 b) => new(a * b.X, a * b.Y);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector2 operator *(in Vector2 a, float b) => new(a.X * b, a.Y * b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector2 operator /(in Vector2 a, in Vector2 b) => new(a.X / b.X, a.Y / b.Y);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector2 operator /(float a, in Vector2 b) => new(a / b.X, a / b.Y);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector2 operator /(in Vector2 a, float b) => new(a.X / b, a.Y / b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(Vector2 a, Vector2 b)
{
float diffX = a.X - b.X;
float diffY = a.Y - b.Y;
return diffX * diffX + diffY * diffY < 0.00001f;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator !=(Vector2 a, Vector2 b)
{
return !(a == b);
}
public override int GetHashCode()
{
unchecked
{
var hashCode = X.GetHashCode();
hashCode = (hashCode * 397) ^ Y.GetHashCode();
return hashCode;
}
}
public override string ToString()
{
return $"X:{X}, Y:{Y}";
}
}