109 lines
2.6 KiB
C#
109 lines
2.6 KiB
C#
using System;
|
|
|
|
namespace KitsuneCafe.Extension
|
|
{
|
|
public static class KMath
|
|
{
|
|
public static float SqrEpsilon = float.Epsilon * float.Epsilon;
|
|
|
|
public static bool IsZero(this float v, float epsilon = float.Epsilon) =>
|
|
v <= epsilon;
|
|
|
|
public static bool IsZero(this UnityEngine.Vector2 v) =>
|
|
v.sqrMagnitude <= SqrEpsilon;
|
|
|
|
public static bool IsZero(this UnityEngine.Vector3 v) =>
|
|
v.sqrMagnitude <= SqrEpsilon;
|
|
|
|
public static float SqrDistance(this UnityEngine.Vector3 a, UnityEngine.Vector3 b) =>
|
|
(b - a).sqrMagnitude;
|
|
|
|
public static bool IsApproxEqual(this float value, float other) =>
|
|
IsApproxEqual(value, other, 0.001f);
|
|
|
|
public static bool IsApproxEqual(this float value, float other, float epsilon) =>
|
|
Math.Abs(value - other) < epsilon;
|
|
|
|
public static bool And(bool a, bool b) => a && b;
|
|
|
|
public static bool Or(bool a, bool b) => a || b;
|
|
|
|
public static bool Not(bool value) => !value;
|
|
|
|
public static int Add(sbyte a, sbyte b) => a + b;
|
|
public static int Add(byte a, byte b) => a + b;
|
|
public static int Add(short a, short b) => a + b;
|
|
public static int Add(ushort a, ushort b) => a + b;
|
|
public static int Add(int a, int b) => a + b;
|
|
public static uint Add(uint a, uint b) => a + b;
|
|
public static long Add(long a, long b) => a + b;
|
|
public static ulong Add(ulong a, ulong b) => a + b;
|
|
public static nint Add(nint a, nint b) => a + b;
|
|
public static nuint Add(nuint a, nuint b) => a + b;
|
|
public static float Add(float a, float b) => a + b;
|
|
public static double Add(double a, double b) => a + b;
|
|
public static decimal Add(decimal a, decimal b) => a + b;
|
|
public static int Sub(sbyte a, sbyte b) => a - b;
|
|
|
|
public static int Sub(byte a, byte b)
|
|
{
|
|
return a - b;
|
|
}
|
|
|
|
public static int Sub(short a, short b)
|
|
{
|
|
return a - b;
|
|
}
|
|
|
|
public static int Sub(ushort a, ushort b)
|
|
{
|
|
return a - b;
|
|
}
|
|
|
|
public static int Sub(int a, int b)
|
|
{
|
|
return a - b;
|
|
}
|
|
|
|
public static uint Sub(uint a, uint b)
|
|
{
|
|
return a - b;
|
|
}
|
|
|
|
public static long Sub(long a, long b)
|
|
{
|
|
return a - b;
|
|
}
|
|
|
|
public static ulong Sub(ulong a, ulong b)
|
|
{
|
|
return a - b;
|
|
}
|
|
|
|
public static nint Sub(nint a, nint b)
|
|
{
|
|
return a - b;
|
|
}
|
|
|
|
public static nuint Sub(nuint a, nuint b)
|
|
{
|
|
return a - b;
|
|
}
|
|
|
|
public static float Sub(float a, float b)
|
|
{
|
|
return a - b;
|
|
}
|
|
|
|
public static double Sub(double a, double b)
|
|
{
|
|
return a - b;
|
|
}
|
|
|
|
public static decimal Sub(decimal a, decimal b)
|
|
{
|
|
return a - b;
|
|
}
|
|
|
|
}
|
|
}
|