aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/cc/polyfrost/oneconfig/utils/MathUtils.java
blob: 630390bdef1b3ecad03ed853ed92fcd895c574f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package cc.polyfrost.oneconfig.utils;

import cc.polyfrost.oneconfig.gui.OneConfigGui;

public final class MathUtils {
    public static float clamp(float number) {
        return clamp(number, 0, 1);
    }

    public static float clamp(float number, float min, float max) {
        return number < min ? min : Math.min(number, max);
    }

    @Deprecated
    public static float easeOut(float current, float goal, float speed) {
        float deltaTime = OneConfigGui.INSTANCE == null ? 16 : OneConfigGui.INSTANCE.getDeltaTime();
        if (Math.round(Math.abs(goal - current) * 100) > 0) {
            return current + (goal - current) / speed * deltaTime;
        } else {
            return goal;
        }
    }

    public static float map(float value, float start1, float stop1, float start2, float stop2) {
        return start2 + (stop2 - start2) * ((value - start1) / (stop1 - start1));
    }
}