Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
MathHelper.cs
Go to the documentation of this file.
1using System;
2
4
5public static class MathHelper
6{
7 public const float E = (float)Math.E;
8
9 public const float Log2E = 1.442695f;
10
11 public const float Log10E = 0.4342945f;
12
13 public const float Pi = (float)Math.PI;
14
15 public const float TwoPi = (float)Math.PI * 2f;
16
17 public const float PiOver2 = (float)Math.PI / 2f;
18
19 public const float PiOver4 = (float)Math.PI / 4f;
20
21 public static float ToRadians(float degrees)
22 {
23 return degrees * ((float)Math.PI / 180f);
24 }
25
26 public static float ToDegrees(float radians)
27 {
28 return radians * (180f / (float)Math.PI);
29 }
30
31 public static float Distance(float value1, float value2)
32 {
33 return Math.Abs(value1 - value2);
34 }
35
36 public static float Min(float value1, float value2)
37 {
38 return Math.Min(value1, value2);
39 }
40
41 public static float Max(float value1, float value2)
42 {
43 return Math.Max(value1, value2);
44 }
45
46 public static float Clamp(float value, float min, float max)
47 {
48 value = ((value > max) ? max : value);
49 value = ((value < min) ? min : value);
50 return value;
51 }
52
53 public static float Lerp(float value1, float value2, float amount)
54 {
55 return value1 + (value2 - value1) * amount;
56 }
57
58 public static float Barycentric(float value1, float value2, float value3, float amount1, float amount2)
59 {
60 return value1 + amount1 * (value2 - value1) + amount2 * (value3 - value1);
61 }
62
63 public static float SmoothStep(float value1, float value2, float amount)
64 {
65 float num = Clamp(amount, 0f, 1f);
66 return Lerp(value1, value2, num * num * (3f - 2f * num));
67 }
68
69 public static float CatmullRom(float value1, float value2, float value3, float value4, float amount)
70 {
71 float num = amount * amount;
72 float num2 = amount * num;
73 return 0.5f * (2f * value2 + (0f - value1 + value3) * amount + (2f * value1 - 5f * value2 + 4f * value3 - value4) * num + (0f - value1 + 3f * value2 - 3f * value3 + value4) * num2);
74 }
75
76 public static float Hermite(float value1, float tangent1, float value2, float tangent2, float amount)
77 {
78 float num = amount * amount;
79 float num2 = amount * num;
80 float num3 = 2f * num2 - 3f * num + 1f;
81 float num4 = -2f * num2 + 3f * num;
82 float num5 = num2 - 2f * num + amount;
83 float num6 = num2 - num;
84 return value1 * num3 + value2 * num4 + tangent1 * num5 + tangent2 * num6;
85 }
86
87 public static float WrapAngle(float angle)
88 {
89 angle = (float)Math.IEEERemainder(angle, 6.2831854820251465);
90 if (angle <= -(float)Math.PI)
91 {
92 angle += (float)Math.PI * 2f;
93 }
94 else if (angle > (float)Math.PI)
95 {
96 angle -= (float)Math.PI * 2f;
97 }
98 return angle;
99 }
100}
static float Lerp(float value1, float value2, float amount)
Definition MathHelper.cs:53
static float ToDegrees(float radians)
Definition MathHelper.cs:26
static float WrapAngle(float angle)
Definition MathHelper.cs:87
static float CatmullRom(float value1, float value2, float value3, float value4, float amount)
Definition MathHelper.cs:69
static float Distance(float value1, float value2)
Definition MathHelper.cs:31
static float Max(float value1, float value2)
Definition MathHelper.cs:41
static float Barycentric(float value1, float value2, float value3, float amount1, float amount2)
Definition MathHelper.cs:58
static float ToRadians(float degrees)
Definition MathHelper.cs:21
static float SmoothStep(float value1, float value2, float amount)
Definition MathHelper.cs:63
static float Clamp(float value, float min, float max)
Definition MathHelper.cs:46
static float Min(float value1, float value2)
Definition MathHelper.cs:36
static float Hermite(float value1, float tangent1, float value2, float tangent2, float amount)
Definition MathHelper.cs:76
static byte Min(byte val1, byte val2)
Definition Math.cs:912
const double E
Definition Math.cs:14
static double IEEERemainder(double x, double y)
Definition Math.cs:679
static double Abs(double value)
const double PI
Definition Math.cs:16
static byte Max(byte val1, byte val2)
Definition Math.cs:738