diff --git a/Hypercube.Client/Graphics/Viewports/Camera2D.cs b/Hypercube.Client/Graphics/Viewports/Camera2D.cs index 086d7a5..db678db 100644 --- a/Hypercube.Client/Graphics/Viewports/Camera2D.cs +++ b/Hypercube.Client/Graphics/Viewports/Camera2D.cs @@ -1,5 +1,6 @@ using Hypercube.Mathematics; using Hypercube.Mathematics.Matrices; +using Hypercube.Mathematics.Quaternions; using Hypercube.Mathematics.Transforms; using Hypercube.Mathematics.Vectors; diff --git a/Hypercube.Mathematics/Extensions/FloatingPointEqualsExtension.cs b/Hypercube.Mathematics/Extensions/FloatingPointEqualsExtension.cs index b8e83cb..c1824ea 100644 --- a/Hypercube.Mathematics/Extensions/FloatingPointEqualsExtension.cs +++ b/Hypercube.Mathematics/Extensions/FloatingPointEqualsExtension.cs @@ -1,16 +1,17 @@ -namespace Hypercube.Mathematics.Extensions; +using JetBrains.Annotations; +namespace Hypercube.Mathematics.Extensions; + +[PublicAPI] public static class FloatingPointEqualsExtension { - public static bool AboutEquals(this double a, double b, double tolerance = 1E-15d) + public static bool AboutEquals(this float a, float b, float tolerance = 1E-15f) { - var epsilon = System.Math.Max(System.Math.Abs(a), System.Math.Abs(b)) * 1E-15d; - return System.Math.Abs(a - b) <= epsilon; + return HyperMath.AboutEquals(a, b, tolerance); } - - public static bool AboutEquals(this float a, float b, float tolerance = 1E-15f) + + public static bool AboutEquals(this double a, double b, double tolerance = 1E-15d) { - var epsilon = System.Math.Max(System.Math.Abs(a), System.Math.Abs(b)) * tolerance ; - return System.Math.Abs(a - b) <= epsilon; + return HyperMath.AboutEquals(a, b, tolerance); } } \ No newline at end of file diff --git a/Hypercube.Mathematics/HyperMath.cs b/Hypercube.Mathematics/HyperMath.cs index aa6ab1c..8d2d72a 100644 --- a/Hypercube.Mathematics/HyperMath.cs +++ b/Hypercube.Mathematics/HyperMath.cs @@ -34,7 +34,19 @@ public static class HyperMath public const float RadiansToDegreesF = 180 / PIf; public const float DegreesToRadiansF = PIf / 180; - + + public static bool AboutEquals(float a, float b, float tolerance = 1E-15f) + { + var epsilon = Math.Max(Math.Abs(a), Math.Abs(b)) * tolerance ; + return Math.Abs(a - b) <= epsilon; + } + + public static bool AboutEquals(double a, double b, double tolerance = 1E-15d) + { + var epsilon = Math.Max(Math.Abs(a), Math.Abs(b)) * tolerance; + return Math.Abs(a - b) <= epsilon; + } + public static byte MoveTowards(byte current, byte target, byte distance) { return current < target ? diff --git a/Hypercube.Mathematics/Matrices/Matrix4X4.cs b/Hypercube.Mathematics/Matrices/Matrix4X4.cs index 06b1eae..e6529ac 100644 --- a/Hypercube.Mathematics/Matrices/Matrix4X4.cs +++ b/Hypercube.Mathematics/Matrices/Matrix4X4.cs @@ -1,5 +1,6 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +using Hypercube.Mathematics.Quaternions; using Hypercube.Mathematics.Shapes; using Hypercube.Mathematics.Transforms; using Hypercube.Mathematics.Vectors; diff --git a/Hypercube.Mathematics/Quaternion.cs b/Hypercube.Mathematics/Quaternions/Quaternion.cs similarity index 98% rename from Hypercube.Mathematics/Quaternion.cs rename to Hypercube.Mathematics/Quaternions/Quaternion.cs index 7c62ad3..559424e 100644 --- a/Hypercube.Mathematics/Quaternion.cs +++ b/Hypercube.Mathematics/Quaternions/Quaternion.cs @@ -1,10 +1,11 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using Hypercube.Mathematics.Vectors; +using JetBrains.Annotations; -namespace Hypercube.Mathematics; +namespace Hypercube.Mathematics.Quaternions; -[StructLayout(LayoutKind.Sequential)] +[PublicAPI, StructLayout(LayoutKind.Sequential)] public readonly struct Quaternion : IEquatable { private const float SingularityThreshold = 0.4999995f; diff --git a/Hypercube.Mathematics/Transforms/Transform2.Compatibility.cs b/Hypercube.Mathematics/Transforms/Transform2.Compatibility.cs index 723ae94..e856b2a 100644 --- a/Hypercube.Mathematics/Transforms/Transform2.Compatibility.cs +++ b/Hypercube.Mathematics/Transforms/Transform2.Compatibility.cs @@ -1,4 +1,5 @@ using System.Runtime.CompilerServices; +using Hypercube.Mathematics.Quaternions; using Hypercube.Mathematics.Vectors; namespace Hypercube.Mathematics.Transforms; diff --git a/Hypercube.Mathematics/Transforms/Transform3.cs b/Hypercube.Mathematics/Transforms/Transform3.cs index b53abed..3fc3793 100644 --- a/Hypercube.Mathematics/Transforms/Transform3.cs +++ b/Hypercube.Mathematics/Transforms/Transform3.cs @@ -1,4 +1,5 @@ using Hypercube.Mathematics.Matrices; +using Hypercube.Mathematics.Quaternions; using Hypercube.Mathematics.Vectors; namespace Hypercube.Mathematics.Transforms; diff --git a/Hypercube.UnitTests/Mathematics/Quaternions/QuaternionTest.cs b/Hypercube.UnitTests/Mathematics/Quaternions/QuaternionTest.cs index 59ba1fc..6715234 100644 --- a/Hypercube.UnitTests/Mathematics/Quaternions/QuaternionTest.cs +++ b/Hypercube.UnitTests/Mathematics/Quaternions/QuaternionTest.cs @@ -1,4 +1,5 @@ using Hypercube.Mathematics; +using Hypercube.Mathematics.Quaternions; using Hypercube.Mathematics.Vectors; namespace Hypercube.UnitTests.Mathematics.Quaternions;