2using System.Collections.Generic;
5using System.Threading.Tasks;
14 public const float PI = 3.14159274f;
19 public const float Infinity =
float.PositiveInfinity;
29 public const float Deg2Rad = 0.0174532924f;
54 public static float Sin(
float f)
56 return (
float)Math.Sin((
double)f);
66 public static float Cos(
float f)
68 return (
float)Math.Cos((
double)f);
75 public static float Tan(
float f)
77 return (
float)Math.Tan((
double)f);
84 public static float Asin(
float f)
86 return (
float)Math.Asin((
double)f);
93 public static float Acos(
float f)
95 return (
float)Math.Acos((
double)f);
102 public static float Atan(
float f)
104 return (
float)Math.Atan((
double)f);
112 public static float Atan2(
float y,
float x)
114 return (
float)Math.Atan2((
double)y, (
double)x);
121 public static float Sqrt(
float f)
123 return (
float)Math.Sqrt((
double)f);
130 public static float Abs(
float f)
139 public static int Abs(
int value)
141 return Math.Abs(value);
150 public static float Min(
float a,
float b)
152 return (!(a < b)) ? b : a;
161 public static float Min(params
float[] values)
163 int num = values.Length;
168 float num2 = values[0];
169 for (
int i = 1; i < num; i++)
171 if (values[i] < num2)
185 public static int Min(
int a,
int b)
187 return (a >= b) ? b : a;
196 public static int Min(params
int[] values)
198 int num = values.Length;
203 int num2 = values[0];
204 for (
int i = 1; i < num; i++)
206 if (values[i] < num2)
220 public static float Max(
float a,
float b)
222 return (!(a > b)) ? b : a;
231 public static float Max(params
float[] values)
233 int num = values.Length;
238 float num2 = values[0];
239 for (
int i = 1; i < num; i++)
241 if (values[i] > num2)
255 public static int Max(
int a,
int b)
257 return (a <= b) ? b : a;
266 public static int Max(params
int[] values)
268 int num = values.Length;
273 int num2 = values[0];
274 for (
int i = 1; i < num; i++)
276 if (values[i] > num2)
289 public static float Pow(
float f,
float p)
291 return (
float)Math.Pow((
double)f, (
double)p);
298 public static float Exp(
float power)
300 return (
float)Math.Exp((
double)power);
308 public static float Log(
float f,
float p)
310 return (
float)Math.Log((
double)f, (
double)p);
317 public static float Log(
float f)
319 return (
float)Math.Log((
double)f);
328 return (
float)Math.Log10((
double)f);
335 public static float Ceil(
float f)
337 return (
float)Math.Ceiling((
double)f);
346 return (
float)Math.Floor((
double)f);
355 return (
float)Math.Round((
double)f);
364 return (
int)Math.Ceiling((
double)f);
373 return (
int)Math.Floor((
double)f);
382 return (
int)Math.Round((
double)f);
389 public static float Sign(
float f)
391 return (!(f >= 0f)) ? (-1f) : 1f;
400 public static float Clamp(
float value,
float min,
float max)
406 else if (value > max)
419 public static int Clamp(
int value,
int min,
int max)
425 else if (value > max)
458 public static float Lerp(
float a,
float b,
float t)
460 return a + (b - a) *
Clamp01(t);
474 return a + (b - a) * t;
483 public static float LerpAngle(
float a,
float b,
float t)
485 float num =
Repeat(b - a, 360f);
499 public static float MoveTowards(
float current,
float target,
float maxDelta)
501 if (
Abs(target - current) <= maxDelta)
505 return current +
Sign(target - current) * maxDelta;
517 if (0f - maxDelta < num && num < maxDelta)
521 target = current + num;
531 public static float SmoothStep(
float from,
float to,
float t)
534 t = -2f * t * t * t + 3f * t * t;
535 return to * t + from * (1f - t);
538 public static float Gamma(
float value,
float absmax,
float gamma)
545 float num =
Abs(value);
548 return (!flag) ? num : (0f - num);
550 float num2 =
Pow(num / absmax, gamma) * absmax;
551 return (!flag) ? num2 : (0f - num2);
554 public static float SmoothDamp(
float current,
float target, ref
float currentVelocity,
float smoothTime,
float maxSpeed,
float deltaTime)
556 smoothTime =
Max(0.0001f, smoothTime);
557 float num = 2f / smoothTime;
558 float num2 = num * deltaTime;
559 float num3 = 1f / (1f + num2 + 0.48f * num2 * num2 + 0.235f * num2 * num2 * num2);
560 float value = current - target;
562 float num5 = maxSpeed * smoothTime;
563 value =
Clamp(value, 0f - num5, num5);
564 target = current - value;
565 float num6 = (currentVelocity + num * value) * deltaTime;
566 currentVelocity = (currentVelocity - num * num6) * num3;
567 float num7 = target + (value + num6) * num3;
568 if (num4 - current > 0f == num7 > num4)
571 currentVelocity = (num7 - num4) / deltaTime;
576 public static float SmoothDampAngle(
float current,
float target, ref
float currentVelocity,
float smoothTime,
float maxSpeed,
float deltaTime)
578 target = current +
DeltaAngle(current, target);
579 return SmoothDamp(current, target, ref currentVelocity, smoothTime, maxSpeed, deltaTime);
587 public static float Repeat(
float t,
float length)
589 return Clamp(t -
Floor(t / length) * length, 0f, length);
597 public static float PingPong(
float t,
float length)
599 t =
Repeat(t, length * 2f);
600 return length -
Abs(t - length);
613 return Clamp01((value - a) / (b - a));
625 float num =
Repeat(target - current, 360f);
635 float num = p2.
x - p1.
x;
636 float num2 = p2.
y - p1.
y;
637 float num3 = p4.
x - p3.
x;
638 float num4 = p4.
y - p3.
y;
639 float num5 = num * num4 - num2 * num3;
644 float num6 = p3.
x - p1.
x;
645 float num7 = p3.
y - p1.
y;
646 float num8 = (num6 * num4 - num7 * num3) / num5;
647 result =
new Vector2(p1.
x + num8 * num, p1.
y + num8 * num2);
651 internal static bool LineSegmentIntersection(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4, ref Vector2 result)
653 float num = p2.x - p1.x;
654 float num2 = p2.y - p1.y;
655 float num3 = p4.x - p3.x;
656 float num4 = p4.y - p3.y;
657 float num5 = num * num4 - num2 * num3;
662 float num6 = p3.x - p1.x;
663 float num7 = p3.y - p1.y;
664 float num8 = (num6 * num4 - num7 * num3) / num5;
665 if (num8 < 0f || num8 > 1f)
669 float num9 = (num6 * num2 - num7 * num) / num5;
670 if (num9 < 0f || num9 > 1f)
674 result =
new Vector2(p1.x + num8 * num, p1.y + num8 * num2);
678 internal static long RandomToLong(System.Random r)
680 byte[] array =
new byte[8];
682 return (
long)(BitConverter.ToUInt64(array, 0) & 0x7FFFFFFFFFFFFFFF);
static int Clamp(int value, int min, int max)
static float Acos(float f)
static float Tan(float f)
static float PingPong(float t, float length)
const float NegativeInfinity
static int Min(int a, int b)
static float Round(float f)
static float Min(float a, float b)
static int Max(int a, int b)
static float Max(params float[] values)
static float Min(params float[] values)
static float Ceil(float f)
static float Exp(float power)
static float Cos(float f)
static float Floor(float f)
static float MoveTowards(float current, float target, float maxDelta)
static float Clamp(float value, float min, float max)
static int Max(params int[] values)
static float Repeat(float t, float length)
static float Max(float a, float b)
static int FloorToInt(float f)
static float Abs(float f)
static float SmoothDamp(float current, float target, ref float currentVelocity, float smoothTime, float maxSpeed, float deltaTime)
static float Pow(float f, float p)
static float LerpAngle(float a, float b, float t)
static float Asin(float f)
static float MoveTowardsAngle(float current, float target, float maxDelta)
static int Abs(int value)
static float Lerp(float a, float b, float t)
static float Sqrt(float f)
static float SmoothStep(float from, float to, float t)
static float Sin(float f)
static volatile float FloatMinNormal
static int RoundToInt(float f)
static float Log10(float f)
static float DeltaAngle(float current, float target)
static float Gamma(float value, float absmax, float gamma)
static float Log(float f, float p)
static float Atan2(float y, float x)
static bool Approximately(float a, float b)
static float Log(float f)
static float Atan(float f)
static int Min(params int[] values)
static float Clamp01(float value)
static readonly float Epsilon
static int CeilToInt(float f)
static bool IsFlushToZeroEnabled
static float LerpUnclamped(float a, float b, float t)
static float SmoothDampAngle(float current, float target, ref float currentVelocity, float smoothTime, float maxSpeed, float deltaTime)
static float Sign(float f)
static float InverseLerp(float a, float b, float value)
static volatile float FloatMinDenormal