diff options
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig/utils/MathUtils.java')
-rw-r--r-- | src/main/java/cc/polyfrost/oneconfig/utils/MathUtils.java | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/MathUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/MathUtils.java index 7eb4944..e30c227 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/MathUtils.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/MathUtils.java @@ -2,18 +2,21 @@ package cc.polyfrost.oneconfig.utils; public class MathUtils { public static float clamp(float number) { - return number < (float) 0.0 ? (float) 0.0 : Math.min(number, (float) 1.0); + return number < 0f ? 0f : Math.min(number, 1f); + } + + public static float clamp(float number, float min, float max) { + return number < min ? min : Math.min(number, max); } public static float easeOut(float current, float goal, float speed) { - if (Math.floor(Math.abs(goal - current) * Math.abs(current - goal) * 3) > 0) { + if (Math.round(Math.abs(goal - current) * 25) > 0) { return current + (goal - current) / speed; } else { return goal; } } - public static float easeInQuad(float current) { return current * current; } @@ -26,5 +29,7 @@ public class MathUtils { return c / 2 * ((float) Math.sqrt(1 - (t -= 2) * t) + 1) + b; } - + public static float map(float value, float start1, float stop1, float start2, float stop2) { + return start2 + (stop2 - start2) * ((value - start1) / (stop1 - start1)); + } } |