summaryrefslogtreecommitdiff
path: root/Client/Assembly-CSharp/FloatRange.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Client/Assembly-CSharp/FloatRange.cs')
-rw-r--r--Client/Assembly-CSharp/FloatRange.cs159
1 files changed, 159 insertions, 0 deletions
diff --git a/Client/Assembly-CSharp/FloatRange.cs b/Client/Assembly-CSharp/FloatRange.cs
new file mode 100644
index 0000000..ca7cfbd
--- /dev/null
+++ b/Client/Assembly-CSharp/FloatRange.cs
@@ -0,0 +1,159 @@
+using System;
+using System.Collections.Generic;
+using UnityEngine;
+
+[Serializable]
+public class FloatRange
+{
+ public float Last { get; private set; }
+
+ public float Width
+ {
+ get
+ {
+ return this.max - this.min;
+ }
+ }
+
+ public float min;
+
+ public float max;
+
+ public FloatRange(float min, float max)
+ {
+ this.min = min;
+ this.max = max;
+ }
+
+ public float ChangeRange(float y, float min, float max)
+ {
+ return Mathf.Lerp(min, max, (y - this.min) / this.Width);
+ }
+
+ public float Clamp(float value)
+ {
+ return Mathf.Clamp(value, this.min, this.max);
+ }
+
+ public bool Contains(float t)
+ {
+ return this.min <= t && this.max >= t;
+ }
+
+ public float CubicLerp(float v)
+ {
+ if (this.min >= this.max)
+ {
+ return this.min;
+ }
+ v = Mathf.Clamp(0f, 1f, v);
+ return v * v * v * (this.max - this.min) + this.min;
+ }
+
+ public float EitherOr()
+ {
+ if (UnityEngine.Random.value <= 0.5f)
+ {
+ return this.max;
+ }
+ return this.min;
+ }
+
+ public float LerpUnclamped(float v)
+ {
+ return Mathf.LerpUnclamped(this.min, this.max, v);
+ }
+
+ public float Lerp(float v)
+ {
+ return Mathf.Lerp(this.min, this.max, v);
+ }
+
+ public float ExpOutLerp(float v)
+ {
+ return this.Lerp(1f - Mathf.Pow(2f, -10f * v));
+ }
+
+ public static float ExpOutLerp(float v, float min, float max)
+ {
+ return Mathf.Lerp(min, max, 1f - Mathf.Pow(2f, -10f * v));
+ }
+
+ public static float Next(float min, float max)
+ {
+ return UnityEngine.Random.Range(min, max);
+ }
+
+ public float Next()
+ {
+ return this.Last = UnityEngine.Random.Range(this.min, this.max);
+ }
+
+ public IEnumerable<float> Range(int numStops)
+ {
+ float num;
+ for (float i = 0f; i <= (float)numStops; i = num)
+ {
+ yield return Mathf.Lerp(this.min, this.max, i / (float)numStops);
+ num = i + 1f;
+ }
+ yield break;
+ }
+
+ public IEnumerable<float> RandomRange(int numStops)
+ {
+ float num;
+ for (float i = 0f; i <= (float)numStops; i = num)
+ {
+ yield return this.Next();
+ num = i + 1f;
+ }
+ yield break;
+ }
+
+ internal float ReverseLerp(float t)
+ {
+ return Mathf.Clamp((t - this.min) / this.Width, 0f, 1f);
+ }
+
+ public static float ReverseLerp(float t, float min, float max)
+ {
+ float num = max - min;
+ return Mathf.Clamp((t - min) / num, 0f, 1f);
+ }
+
+ public IEnumerable<float> SpreadToEdges(int stops)
+ {
+ return FloatRange.SpreadToEdges(this.min, this.max, stops);
+ }
+
+ public IEnumerable<float> SpreadEvenly(int stops)
+ {
+ return FloatRange.SpreadEvenly(this.min, this.max, stops);
+ }
+
+ public static IEnumerable<float> SpreadToEdges(float min, float max, int stops)
+ {
+ if (stops == 1)
+ {
+ yield break;
+ }
+ int num;
+ for (int i = 0; i < stops; i = num)
+ {
+ yield return Mathf.Lerp(min, max, (float)i / ((float)stops - 1f));
+ num = i + 1;
+ }
+ yield break;
+ }
+
+ public static IEnumerable<float> SpreadEvenly(float min, float max, int stops)
+ {
+ float step = 1f / ((float)stops + 1f);
+ for (float i = step; i < 1f; i += step)
+ {
+ yield return Mathf.Lerp(min, max, i);
+ }
+ yield break;
+ }
+}