diff --git a/Engine.Core/Math.cs b/Engine.Core/Math.cs index 7cec55b..eda310b 100644 --- a/Engine.Core/Math.cs +++ b/Engine.Core/Math.cs @@ -1,4 +1,5 @@ using System; +using System.Numerics; namespace Syntriax.Engine.Core; @@ -11,24 +12,24 @@ public static class Math public const float PI = 3.1415926535897932f; public const float Tau = 2f * PI; - public static float Abs(float x) => MathF.Abs(x); + public static T Abs(T x) where T : INumber => x > T.Zero ? x : -x; public static float Acos(float x) => MathF.Acos(x); public static float Asin(float x) => MathF.Asin(x); public static float Atan2(float y, float x) => MathF.Atan2(y, x); public static float Atanh(float x) => MathF.Atanh(x); - public static float Clamp(float x, float min, float max) => (x < min) ? min : (x > max) ? max : x; + public static T Clamp(this T x, T min, T max) where T : INumber => (x < min) ? min : (x > max) ? max : x; public static float Ceiling(float x) => MathF.Ceiling(x); public static float CopySign(float x, float y) => MathF.CopySign(x, y); public static float Floor(float x) => MathF.Floor(x); public static float IEEERemainder(float x, float y) => MathF.IEEERemainder(x, y); public static float Log(float x, float y) => MathF.Log(x, y); - public static float Max(float x, float y) => MathF.Max(x, y); + public static T Max(T x, T y) where T : INumber => (x > y) ? x : y; public static float MaxMagnitude(float x, float y) => MathF.MaxMagnitude(x, y); - public static float Min(float x, float y) => MathF.Min(x, y); + public static T Min(T x, T y) where T : INumber => (x < y) ? x : y; public static float MinMagnitude(float x, float y) => MathF.MinMagnitude(x, y); public static float Pow(float x, float y) => MathF.Pow(x, y); public static float Round(float x, int digits, MidpointRounding mode) => MathF.Round(x, digits, mode); - public static float Sqr(float x) => x * x; + public static T Sqr(T x) where T : INumber => x * x; public static float Sqrt(float x) => MathF.Sqrt(x); public static float Truncate(float x) => MathF.Truncate(x); }