diff --git a/Prowl.Runtime/GUI/Gui.Interaction.cs b/Prowl.Runtime/GUI/Gui.Interaction.cs
index 3f6746e6..6db3f21d 100644
--- a/Prowl.Runtime/GUI/Gui.Interaction.cs
+++ b/Prowl.Runtime/GUI/Gui.Interaction.cs
@@ -124,7 +124,7 @@ public Interactable GetInteractable(LayoutNode target, Rect? interactArea = null
///
public bool IsBlockedByInteractable(Vector2 pos, double zIndex = -1, ulong ignoreID = 0)
{
- if (Math.Abs(zIndex - (-1)) < Mathf.Epsilon)
+ if (MathD.ApproximatelyEquals(zIndex, -1))
{
if (!_zInteractableCounter.TryGetValue(CurrentZIndex, out int count))
count = 0;
diff --git a/Prowl.Runtime/Math/MathD.cs b/Prowl.Runtime/Math/MathD.cs
index f903af18..2112326e 100644
--- a/Prowl.Runtime/Math/MathD.cs
+++ b/Prowl.Runtime/Math/MathD.cs
@@ -10,7 +10,7 @@ namespace Prowl.Runtime;
public static class MathD
{
- private const MethodImplOptions IN = MethodImplOptions.AggressiveInlining;
+ public const MethodImplOptions IN = MethodImplOptions.AggressiveInlining;
#region Constants
@@ -38,9 +38,6 @@ public static class MathD
/// A small but not tiny value, Used in places like ApproximatelyEquals, where there is some tolerance (0.00001)
public static readonly double Small = 0.000001;
- ///
- public static readonly double Epsilon = double.MinValue;
-
///
public const double Infinity = double.PositiveInfinity;
@@ -194,7 +191,7 @@ public static double LerpAngle(double aRad, double bRad, double t)
[MethodImpl(IN)] public static int ComputeMipLevels(int width, int height) => (int)Math.Log2(Math.Max(width, height));
- [MethodImpl(IN)] public static bool ApproximatelyEquals(double a, double b) => Abs(a - b) < Epsilon;
+ [MethodImpl(IN)] public static bool ApproximatelyEquals(double a, double b) => Abs(a - b) < double.Epsilon;
[MethodImpl(IN)] public static bool ApproximatelyEquals(Vector2 a, Vector2 b) => ApproximatelyEquals(a.x, b.x) && ApproximatelyEquals(a.y, b.y);
[MethodImpl(IN)] public static bool ApproximatelyEquals(Vector3 a, Vector3 b) => ApproximatelyEquals(a.x, b.x) && ApproximatelyEquals(a.y, b.y) && ApproximatelyEquals(a.z, b.z);
[MethodImpl(IN)] public static bool ApproximatelyEquals(Vector4 a, Vector4 b) => ApproximatelyEquals(a.x, b.x) && ApproximatelyEquals(a.y, b.y) && ApproximatelyEquals(a.z, b.z) && ApproximatelyEquals(a.w, b.w);
diff --git a/Prowl.Runtime/Math/Mathf.cs b/Prowl.Runtime/Math/Mathf.cs
index 7d3fdaaf..40160500 100644
--- a/Prowl.Runtime/Math/Mathf.cs
+++ b/Prowl.Runtime/Math/Mathf.cs
@@ -2,12 +2,14 @@
// Licensed under the MIT License. See the LICENSE file in the project root for details.
using System;
+using System.Runtime.CompilerServices;
namespace Prowl.Runtime;
public static class Mathf
{
- public static readonly float Epsilon = float.MinValue;
-
- public static bool ApproximatelyEquals(float value1, float value2) => Math.Abs(value1 - value2) < Epsilon;
+ public static bool ApproximatelyEquals(float value1, float value2) => Math.Abs(value1 - value2) < float.Epsilon;
+ [MethodImpl(MathD.IN)] public static bool ApproximatelyEquals(System.Numerics.Vector2 a, System.Numerics.Vector2 b) => ApproximatelyEquals(a.X, b.X) && ApproximatelyEquals(a.Y, b.Y);
+ [MethodImpl(MathD.IN)] public static bool ApproximatelyEquals(System.Numerics.Vector3 a, System.Numerics.Vector3 b) => ApproximatelyEquals(a.X, b.X) && ApproximatelyEquals(a.Y, b.Y) && ApproximatelyEquals(a.Z, b.Z);
+ [MethodImpl(MathD.IN)] public static bool ApproximatelyEquals(System.Numerics.Vector4 a, System.Numerics.Vector4 b) => ApproximatelyEquals(a.X, b.X) && ApproximatelyEquals(a.Y, b.Y) && ApproximatelyEquals(a.Z, b.Z) && ApproximatelyEquals(a.W, b.W);
}
diff --git a/Prowl.Runtime/Math/Matrix4x4.cs b/Prowl.Runtime/Math/Matrix4x4.cs
index 35538475..9bb8658f 100644
--- a/Prowl.Runtime/Math/Matrix4x4.cs
+++ b/Prowl.Runtime/Math/Matrix4x4.cs
@@ -247,7 +247,7 @@ public static Matrix4x4 CreateBillboard(Vector3 objectPosition, Vector3 cameraPo
double norm = zaxis.sqrMagnitude;
- if (norm < MathD.Epsilon)
+ if (norm < double.Epsilon)
{
zaxis = -cameraForwardVector;
}
@@ -288,7 +288,7 @@ public static Matrix4x4 CreateConstrainedBillboard(Vector3 objectPosition, Vecto
double norm = faceDir.sqrMagnitude;
- if (norm < MathD.Epsilon)
+ if (norm < double.Epsilon)
{
faceDir = -cameraForwardVector;
}
@@ -1420,14 +1420,14 @@ public static bool Decompose(Matrix4x4 matrix, out Vector3 scale, out Quaternion
}
#endregion
- if (pfScales[a] < MathD.Epsilon)
+ if (pfScales[a] < double.Epsilon)
{
*(pVectorBasis[a]) = pCanonicalBasis[a];
}
*pVectorBasis[a] = Vector3.Normalize(*pVectorBasis[a]);
- if (pfScales[b] < MathD.Epsilon)
+ if (pfScales[b] < double.Epsilon)
{
uint cc;
double fAbsX, fAbsY, fAbsZ;
@@ -1480,7 +1480,7 @@ public static bool Decompose(Matrix4x4 matrix, out Vector3 scale, out Quaternion
*pVectorBasis[b] = Vector3.Normalize(*pVectorBasis[b]);
- if (pfScales[c] < MathD.Epsilon)
+ if (pfScales[c] < double.Epsilon)
{
*pVectorBasis[c] = Vector3.Cross(*pVectorBasis[a], *pVectorBasis[b]);
}
@@ -1502,7 +1502,7 @@ public static bool Decompose(Matrix4x4 matrix, out Vector3 scale, out Quaternion
det -= 1.0;
det *= det;
- if ((det > MathD.Epsilon))
+ if ((det > double.Epsilon))
{
// Non-SRT matrix encountered
rotation = Quaternion.identity;
diff --git a/Prowl.Runtime/Math/Quaternion.cs b/Prowl.Runtime/Math/Quaternion.cs
index c5ee411e..5a6c25f3 100644
--- a/Prowl.Runtime/Math/Quaternion.cs
+++ b/Prowl.Runtime/Math/Quaternion.cs
@@ -114,7 +114,7 @@ public double Magnitude()
public static Quaternion NormalizeSafe(Quaternion q)
{
double mag = q.Magnitude();
- if (mag < MathD.Epsilon)
+ if (mag < double.Epsilon)
return identity;
else
return q / mag;
@@ -334,7 +334,7 @@ public static Quaternion Slerp(Quaternion quaternion1, Quaternion quaternion2, d
double s1, s2;
- if (cosOmega > (1.0 - MathD.Epsilon))
+ if (cosOmega > (1.0 - double.Epsilon))
{
// Too close, do straight linear interpolation.
s1 = 1.0 - t;
diff --git a/Prowl.Runtime/Math/Ray.cs b/Prowl.Runtime/Math/Ray.cs
index 727d9509..8f665718 100644
--- a/Prowl.Runtime/Math/Ray.cs
+++ b/Prowl.Runtime/Math/Ray.cs
@@ -81,7 +81,7 @@ public override int GetHashCode()
{
double? tMin = null, tMax = null;
- if (Math.Abs(direction.x) < MathD.Epsilon)
+ if (Math.Abs(direction.x) < double.Epsilon)
{
if (origin.x < box.min.x || origin.x > box.max.x)
return null;
@@ -99,7 +99,7 @@ public override int GetHashCode()
}
}
- if (Math.Abs(direction.y) < MathD.Epsilon)
+ if (Math.Abs(direction.y) < double.Epsilon)
{
if (origin.y < box.min.y || origin.y > box.max.y)
return null;
@@ -123,7 +123,7 @@ public override int GetHashCode()
if (!tMax.HasValue || tMaxY < tMax) tMax = tMaxY;
}
- if (Math.Abs(direction.z) < MathD.Epsilon)
+ if (Math.Abs(direction.z) < double.Epsilon)
{
if (origin.z < box.min.z || origin.z > box.max.z)
return null;
diff --git a/Prowl.Runtime/Math/Transform.cs b/Prowl.Runtime/Math/Transform.cs
index 901d5479..f7df6528 100644
--- a/Prowl.Runtime/Math/Transform.cs
+++ b/Prowl.Runtime/Math/Transform.cs
@@ -276,7 +276,7 @@ public void RotateAround(Vector3 point, Vector3 axis, double angle)
internal void RotateAroundInternal(Vector3 worldAxis, double rad)
{
Vector3 localAxis = InverseTransformDirection(worldAxis);
- if (localAxis.sqrMagnitude > MathD.Epsilon)
+ if (localAxis.sqrMagnitude > double.Epsilon)
{
localAxis.Normalize();
Quaternion q = Quaternion.AngleAxis(rad, localAxis);
@@ -356,6 +356,6 @@ public Matrix4x4 GetWorldRotationAndScale()
return ret;
}
- static double InverseSafe(double f) => MathD.Abs(f) > MathD.Epsilon ? 1.0F / f : 0.0F;
+ static double InverseSafe(double f) => MathD.Abs(f) > double.Epsilon ? 1.0F / f : 0.0F;
static Vector3 InverseSafe(Vector3 v) => new Vector3(InverseSafe(v.x), InverseSafe(v.y), InverseSafe(v.z));
}