Syntriax.Engine/Engine.Core/Math.cs

36 lines
1.8 KiB
C#
Raw Normal View History

2024-01-24 12:22:04 +03:00
using System;
using System.Numerics;
2024-01-24 12:22:04 +03:00
namespace Syntriax.Engine.Core;
public static class Math
{
public const float RadianToDegree = 180f / PI;
public const float DegreeToRadian = PI / 180f;
2024-01-24 12:22:04 +03:00
public const float E = 2.718281828459045f;
public const float PI = 3.1415926535897932f;
public const float Tau = 2f * PI;
2024-01-24 12:22:04 +03:00
public static T Abs<T>(T x) where T : INumber<T> => x > T.Zero ? x : -x;
2024-01-24 12:22:04 +03:00
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 T Clamp<T>(this T x, T min, T max) where T : INumber<T> => (x < min) ? min : (x > max) ? max : x;
2024-01-24 12:22:04 +03:00
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 T Max<T>(T x, T y) where T : INumber<T> => (x > y) ? x : y;
2024-01-24 12:22:04 +03:00
public static float MaxMagnitude(float x, float y) => MathF.MaxMagnitude(x, y);
public static T Min<T>(T x, T y) where T : INumber<T> => (x < y) ? x : y;
2024-01-24 12:22:04 +03:00
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 T Sqr<T>(T x) where T : INumber<T> => x * x;
2024-01-25 12:49:21 +03:00
public static float Sqrt(float x) => MathF.Sqrt(x);
2024-01-24 12:22:04 +03:00
public static float Truncate(float x) => MathF.Truncate(x);
}