2018-05-02 14:41:43 +02:00
|
|
|
package com.minelittlepony.util.math;
|
|
|
|
|
|
|
|
import net.minecraft.util.math.MathHelper;
|
|
|
|
|
|
|
|
public class MathUtil {
|
|
|
|
|
|
|
|
public static double clampLimit(double num, double limit) {
|
|
|
|
return MathHelper.clamp(num, -limit, limit);
|
|
|
|
}
|
2018-06-11 19:25:02 +02:00
|
|
|
|
2018-10-23 10:05:29 +02:00
|
|
|
public static int mod(int value, int mod) {
|
|
|
|
value %= mod;
|
|
|
|
|
|
|
|
while (value < 0) value += mod;
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2018-06-11 19:25:02 +02:00
|
|
|
public static float sensibleAngle(float angle) {
|
|
|
|
angle %= 360;
|
|
|
|
|
|
|
|
if (angle > 180) angle -= 360;
|
|
|
|
if (angle < -180) angle += 360;
|
|
|
|
|
|
|
|
return angle;
|
|
|
|
}
|
2018-09-19 19:43:23 +02:00
|
|
|
|
|
|
|
public static float interpolateDegress(float prev, float current, float partialTicks) {
|
|
|
|
float difference = current - prev;
|
|
|
|
|
|
|
|
while (difference < -180) difference += 360;
|
|
|
|
while (difference >= 180) difference -= 360;
|
|
|
|
|
|
|
|
return prev + partialTicks * difference;
|
|
|
|
}
|
2018-09-23 11:08:30 +02:00
|
|
|
|
|
|
|
public static float interpolateRadians(float prev, float current, float partialTicks) {
|
|
|
|
return (float)Math.toRadians(interpolateDegress(prev, current, partialTicks));
|
|
|
|
}
|
2018-12-09 23:05:33 +01:00
|
|
|
|
|
|
|
public static boolean compareFloats(float a, float b) {
|
|
|
|
return Math.abs(a - b) <= 0.001F;
|
|
|
|
}
|
2018-05-02 14:41:43 +02:00
|
|
|
}
|