From fdc38fc800dd631b71892d2795c997a089c091bf Mon Sep 17 00:00:00 2001 From: Syntriax Date: Sun, 20 Oct 2024 15:12:20 +0300 Subject: [PATCH] feat: Engine.Core.MathExtensions --- Engine.Core/MathExtensions.cs | 70 +++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 Engine.Core/MathExtensions.cs diff --git a/Engine.Core/MathExtensions.cs b/Engine.Core/MathExtensions.cs new file mode 100644 index 0000000..9fba5b8 --- /dev/null +++ b/Engine.Core/MathExtensions.cs @@ -0,0 +1,70 @@ +using System; +using System.Numerics; + +namespace Syntriax.Engine.Core; + +public static class MathExtensions +{ + /// + public static T Abs(this T x) where T : INumber => Math.Abs(x); + + /// + public static float Acos(this float x) => Math.Acos(x); + + /// + public static float Asin(this float x) => Math.Asin(x); + + /// + public static float Atan2(this float y, float x) => Math.Atan2(y, x); + + /// + public static float Atanh(this float x) => Math.Atanh(x); + + /// + public static T Clamp(this T x, T min, T max) where T : INumber => Math.Clamp(x, min, max); + + /// + public static float Ceiling(this float x) => Math.Ceiling(x); + + /// + public static float CopySign(this float x, float y) => Math.CopySign(x, y); + + /// + public static float Floor(this float x) => Math.Floor(x); + + /// + public static float IEEERemainder(this float x, float y) => Math.IEEERemainder(x, y); + + /// + public static float Log(this float x, float y) => Math.Log(x, y); + + /// + public static T Max(this T x, T y) where T : INumber => Math.Max(x, y); + + /// + public static T AbsMax(this T x, T y) where T : INumber => Math.AbsMax(x, y); + + /// + public static T Min(this T x, T y) where T : INumber => Math.Min(x, y); + + /// + public static T AbsMin(this T x, T y) where T : INumber => Math.AbsMin(x, y); + + /// + public static float Pow(this float x, float y) => Math.Pow(x, y); + + /// + public static T Lerp(this T x, T y, T t) where T : IFloatingPoint => Math.Lerp(x, y, t); + + /// + public static float Round(this float x, int digits, MidpointRounding mode) => Math.Round(x, digits, mode); + + /// + public static T Sqr(this T x) where T : INumber => Math.Sqr(x); + + /// + public static float Sqrt(this float x) => Math.Sqrt(x); + + /// + public static float Truncate(this float x) => Math.Truncate(x); +}