Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e85c5aa6 authored by Romain Guy's avatar Romain Guy
Browse files

Add norm() and map() to MathUtils.

parent b5a72b0e
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -144,6 +144,14 @@ public final class MathUtils {
        return start + (stop - start) * amount;
    }
    
    public static float norm(float start, float stop, float value) {
        return (value - start) / (stop - start);
    }
    
    public static float map(float minStart, float minStop, float maxStart, float maxStop, float value) {
        return maxStart + (maxStart - maxStop) * ((value - minStart) / (minStop - minStart));
    }

    public static int random(int howbig) {
        return (int) (sRandom.nextFloat() * howbig);
    }